找回密码
 加入
搜索
查看: 4718|回复: 15

Delphi中调用的dll如何在AU3中使用

[复制链接]
发表于 2009-1-23 01:08:24 | 显示全部楼层 |阅读模式
再次提问,真的是有点急切知道怎么做的
Delphi中这样的
function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';

function InitializeWinIo():Boolean;stdcall;External'WinIO.dll';    //初始化winio.dll,有返回值
procedure ShutdownWinIo();stdcall;External'WinIO.dll';          //关闭winio.dll
function GetPortVal(wPortAddr:word;pdwPortVal:pdword;bSize:byte):Boolean;stdcall;External'WinIO.dll';    //向指定端口写数据
function SetPortVal(wPortAddr:word;dwPortVal:dword;bSize:byte):Boolean;stdcall;External'WinIO.dll';
.................
..................
................
comhandle:=cominit(3);
  i:=0;
  while i<5 do
  begin
    p_card:=txrxrw(comhandle);
    s:=p_card;
    if s<>'' then
    begin
      i:=0;
      break;
    end
    else
    begin
      i:=i+1;
      sleep(500);
    end;
在AU3中怎么调用,DLLCALL如何写,急切知道
希望三恨及各位潜水的大侠能给点指点,
另外还有上次的同样的一贴能给答复,好给各位和我一样的菜菜参考,这样好结贴
http://www.autoitx.com/forum.php?mod=viewthread&tid=4734
http://www.autoitx.com/forum.php?mod=viewthread&tid=4266
谢谢

------------------------------------------------------
function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';

以上列出引用格式。

具体说明:


串口初始化函数
function ComInit(comid:integer):Thandle;
参数说明:
comid: 数据类型: 数值型
取值:1-8,代表Com1-Com8;
返回值:
数据类型:句柄;
值: -1:初始化失败
<> -1 初始化成功

串口关闭
function ComExit(_handle:Thandle):integer;
参数说明:
_handle: 数据类型: 句柄
输入值:<>-1;
返回值:
数据类型:数值;
值: 1:成功
-1: 失败


//读MF卡的卡号
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';
参数说明:
_handle: 数据类型: 句柄
输入值:<>-1;
返回值:
数据类型:pchar;(带#0结束的字符串)
值: nil:失败
<>nil : 成功(卡号为八位的十六进制字符串)

[ 本帖最后由 ken0137 于 2009-2-5 22:16 编辑 ]
 楼主| 发表于 2009-1-23 02:27:27 | 显示全部楼层

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 115)
$Input1 = GUICtrlCreateInput("", 192, 144, 121, 21)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
While 1        
        $dll = DllOpen("___MFCOM.DLL")
        $x=DllCall ("___MFCOM.DLL","ptr","ComInit","int","3")
        DllClose($dll)
        $dll = DllOpen("___MFCOM.DLL")
        $y=DllCall ("___MFCOM.DLL","str","txrxrw","ptr",$x)
        If $y<>'' Then
        GUICtrlSetData($Input1,$y)
        ExitLoop
        Else
        Sleep(500)
        EndIf
WEnd

Func CLOSEClicked()
        DllClose($dll)
        Exit
EndFunc

这样写不行啊,郁闷死了
发表于 2009-1-23 06:26:09 | 显示全部楼层
汗 我再看了下那个贴 上次没仔细看
http://www.autoitx.com/forum.php?mod=viewthread&tid=4734
你说放到1.txt里是可以打印的 那你那段改成这样试试
$Data = "^XA" & @LF
$Data &= "^LH0,0" & @LF
$Data &= "^BY3^FO70,137^BCN,40,N,N,N^FD>;{SnBar}^FS" & @LF
$Data &= "^AFN,26,14^FO100,180^CI0^FDSN:{Sn}^FS" & @LF
$Data &= "^PQ{Sheet}" & @LF
$Data &= "^XZ"


[ 本帖最后由 sxd 于 2009-1-23 06:27 编辑 ]
 楼主| 发表于 2009-1-23 08:06:19 | 显示全部楼层
原帖由 sxd 于 2009-1-23 06:26 发表
汗 我再看了下那个贴 上次没仔细看
http://www.autoitx.com/forum.php?mod=viewthread&tid=4734
你说放到1.txt里是可以打印的 那你那段改成这样试试
[au3]$Data = "^XA" & @LF
$Data &= "^LH0,0" & @LF
$Data &= "^BY3^ ...



换行符是不要紧的因为斑马打印机的语言是都是“^”起头的,1.txt里这样写是为了条理清楚,
其实连在一起也是可以的,例如
1.txt的内容
^XA^LH0,0^BY3^FO70,137^BCN,40,N,N,N^FD>;{SnBar}^FS^AFN,26,14^FO100,180^CI0^FDSN:{Sn}^FS^PQ{Sheet}^XZ
我想大概还是dllcall这里的问题吧
发表于 2009-1-23 09:26:24 | 显示全部楼层
尝试以下代码,对DELPHI的DLL调用不大了解。


$dll=DllOpen("___MFCOM.DLL")
DllCall($dll,"hwnd","ComInit","int",$Comid)
DllCall($dll,"int","ComExit","hwnd",$hwnd)
DllCall($dll,"ptr","TxRxRW","hwnd",$_handle)

发表于 2009-1-23 10:44:35 | 显示全部楼层
stdcall调用约定,和调用API一样
 楼主| 发表于 2009-1-23 12:56:38 | 显示全部楼层
谢谢各位,不过具体测试要过年后才行,因为这个dll是非接触式IC卡的读取,
公司里才有设备。。
 楼主| 发表于 2009-1-23 13:05:23 | 显示全部楼层
一起问了,这个怎么转化
function SerialPrint(uart:integer;Data:string):boolean;stdcall external 'ZebraPrint.dll'
function ParallelPrint(Data:string):boolean;stdcall external 'ZebraPrint.dll'
发表于 2009-1-23 17:16:19 | 显示全部楼层

$dll=DllOpen("ZebraPrint.dll")
DllCall($dll,"int","SerialPrint","int",$uart,"str",$Data)
DllCall($dll,"int","ParallelPrint","str",$Data)

发表于 2009-1-23 18:17:43 | 显示全部楼层
function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL'
$x=DllCall ("___MFCOM.DLL","ptr","ComInit","int","3")
不能成功调用就在于,类型问题。
Thandle是一个句柄,你不能 把它改为PTR(指针),可以是INT或LONG或HWND。
看你的参数"3"既然是INT,那么就不要+“”了,+了就变成string了。
char 对应byte
dllcall里面有详细说明的。
发表于 2009-1-24 07:53:43 | 显示全部楼层
是啊 像我们这种直接从au3开始的人 对数据类型的概念很差啊
 楼主| 发表于 2009-1-24 16:44:32 | 显示全部楼层
谢谢,akmm88,sanhen ,sxd的帮助,真的
就像sxd说的“我们这种直接从au3开始的人,对数据类型的概念很差啊”
我想akmm88和sanhen已经给了正确的答案,但是一定要试过我才结贴哦,
谢谢,祝大家新年快乐
 楼主| 发表于 2009-2-2 11:35:00 | 显示全部楼层
还是不行啊,在线等,赐教啊
我是这样的

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 193, 115)
$Input1 = GUICtrlCreateInput("", 176, 120, 121, 21)
$Button1 = GUICtrlCreateButton("Button1", 200, 224, 75, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUICtrlSetOnEvent($Button1, "_Exit");


While 1
        $dll = DllOpen("___MFCOM.DLL")
        $x = DllCall($dll, "hwnd", "ComInit", "int", 3)        
        $y = DllCall($dll, "ptr", "TxRxRW", "hwnd", $x)
        If $y <> "" Then                
                GUICtrlSetData($Input1, $y)
        EndIf
        DllCall($dll,"int","ComExit","hwnd",$x)
        Sleep(1000)
WEnd
Func _Exit()
        Exit
EndFunc   ;==>_Exit
 楼主| 发表于 2009-2-2 20:12:04 | 显示全部楼层
找到了说明
function ComInit(comid:integer):Thandle; StdCall external '___MFCOM.DLL' name 'ComInit';
function ComExit(_handle:Thandle):integer;stdcall external '___MFCOM.DLL' name 'ComExit';
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';

以上列出引用格式。

具体说明:


串口初始化函数
function ComInit(comid:integer):Thandle;
参数说明:
     comid: 数据类型: 数值型
            取值:1-8,代表Com1-Com8;
返回值:
    数据类型:句柄;
    值: -1:初始化失败
         <> -1 初始化成功

串口关闭
function ComExit(_handle:Thandle):integer;
参数说明:
     _handle: 数据类型: 句柄
              输入值:<>-1;
返回值:
    数据类型:数值;
    值: 1:成功
        -1: 失败


//读MF卡的卡号
function TxRxRW(_handle:THandle):pchar; stdcall external '___MFCOM.DLL' name 'TxRxRW';
参数说明:
     _handle: 数据类型: 句柄
              输入值:<>-1;
返回值:
    数据类型:pchar;(带#0结束的字符串)
    值: nil:失败
        <>nil : 成功(卡号为八位的十六进制字符串)
 楼主| 发表于 2009-2-4 19:25:50 | 显示全部楼层
再顶一下好了~~~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 17:53 , Processed in 0.083344 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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