找回密码
 加入
搜索
查看: 3670|回复: 1

[转贴] 搬运英文论坛上某大大的帖子!关于au3写dll的!

[复制链接]
发表于 2010-9-13 16:03:30 | 显示全部楼层 |阅读模式
刚刚在研究用au3写dll的问题,在官网上看到一牛人的帖子,想法很新颖,给大家转下帖子,开阔下思路。。。。不过实际上他的这个所谓的dll功能极其有限,速度慢,限制极多,下面回帖的人也说毫无意义。。。。。但总算是有个不错的想法。

原帖地址:
http://www.autoitscript.com/forum/index.php?showtopic=116700&st=0&p=814117&hl=dll&fromsearch=1&#entry814117

他的思路就是把要调用的函数编译成可执行文件mydll.exe,然后函数名和参数作为程序的参数传给那个程序。。。。。。

第一个是dll.au3头文件,必须被mydll.au3和要调用函数的文件引用。
#include-once
#include <Process.au3>
#include <Array.au3>
#include <File.au3>

Func _DLL_StartUp()
        Opt("TrayIconHide",1)
        If Not(@Compiled) Then
                $vGetDLL = "1234.tmp;_ToolTip;www.team-sl4.com;wow a tooltip :O"
        Else
                $vGetDLL = $CmdLine[1]
        EndIf
        If Not($vGetDLL  = "") Then
                $vStringSplit = StringSplit($vGetDLL,";")
                Global $DLL_ID = $vStringSplit[1]
                ;_ArrayDisplay($vStringSplit) ; could be very helpful :P
                If $vStringSplit[0] = 2 Then
                        Call($vStringSplit[2])
                ElseIf $vStringSplit[0] = 3 Then
                        Call($vStringSplit[2],$vStringSplit[3])
                ElseIf $vStringSplit[0] = 4 Then
                        Call($vStringSplit[2],$vStringSplit[3],$vStringSplit[4])
                ElseIf $vStringSplit[0] = 5 Then
                        Call($vStringSplit[2],$vStringSplit[3],$vStringSplit[4],$vStringSplit[5])
                EndIf
        Else
                Exit
        EndIf
EndFunc

Func _DLL_Return($vReturn)
        Dim $DLL_ID
        $vFileOpen = FileOpen(@TempDir & "" & $DLL_ID,2)
        FileWrite($vFileOpen,$vReturn)
        FileClose($vFileOpen)
        Exit
EndFunc

Func _DLL_Call($vFile,$vFunction)
        $vTempFile = Random(1000,9999,1) & ".tmp"
        _RunDOS($vFile & " " & $vTempFile & ";" & $vFunction)
        $vFileOpen = FileOpen(@TempDir & "" & $vTempFile,0)
        $vFileRead = FileRead($vFileOpen)
        FileClose($vFileOpen)
        FileDelete(@TempDir & "" & $vTempFile)
        Return $vFileRead
EndFunc


第二个是mydll.au3,编译成mydll.exe,其中包含需要被其他程序调用的函数.....
#include <DLL.au3>
;you can not run this file
;this is a fake dll!

_DLL_StartUp()


Func _MsgBox($vID,$vTitle,$vText)
        Dim $iMsgBox
        $iMsgBox = MsgBox($vID,$vTitle,$vText)
        _DLL_Return($iMsgBox)
EndFunc

Func _ToolTip($vTitle,$vText)
        Dim $iToolTip
        ToolTip($vText,1,1,$vTitle)
        Sleep(1000*5)
        _DLL_Return($iToolTip)
EndFunc

Func _Calculate($Var1,$Var2)
        _DLL_Return($Var1+$Var2)
EndFunc


然后是他给的一个例子,调用了mydll.au3之中的函数:
#include <DLL.au3>

$MsgBox1 = _DLL_Call("mydll.exe","_MsgBox;64;www.team-sl4.com;text goes here...")
MsgBox(1,"Return",$MsgBox1)

$MsgBox2 = _DLL_Call("mydll.exe","_MsgBox;1;www.team-sl4.com;another msgbox :P")
MsgBox(1,"Return",$MsgBox2)

_DLL_Call("mydll.exe","_ToolTip;www.team-sl4.com;wow a tooltip :O")

MsgBox(1,"","As you see... everything works fine... now lets calculate with a fake dll call ;)" & @CRLF & "5+3=?")

MsgBox(1,"","5+3=" & @CRLF & _DLL_Call("mydll.exe","_Calculate;5;3"))


说真的,这东西都是骗人的。。。。。连他自己也说这个是fake dll。。。。。


几个人的回帖就不那么客气了,

第一个人说,真他妈的慢(因为要用文件和命令行),而且毫无意义。。。。。

第二个人问,这是干嘛的。。。。。

直到12楼才有人说,想法不错。。。。。
发表于 2010-9-16 10:34:21 | 显示全部楼层
真能写个dll就好了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-3 00:37 , Processed in 0.071928 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表