VC做的DLL函数如下:
WORD _stdcall OpenComm(BYTE byPort, DWORD dwCommBaudRate);
WORD _stdcall ReadNum(int* iCard,BYTE* byCardNum);在delphi下怎么声明啊?
Function OpenComm(byPort:byte; dwCommBaudRate:dword):word;stdcall;far;
external 'DLL.dll'
Function ReadNum(iCard:Pinteger;byCardNum:Pbyte):word;stdcall;far;
external 'DLL.dll'
怎样做竟然不行?
WORD _stdcall OpenComm(BYTE byPort, DWORD dwCommBaudRate);
WORD _stdcall ReadNum(int* iCard,BYTE* byCardNum);在delphi下怎么声明啊?
Function OpenComm(byPort:byte; dwCommBaudRate:dword):word;stdcall;far;
external 'DLL.dll'
Function ReadNum(iCard:Pinteger;byCardNum:Pbyte):word;stdcall;far;
external 'DLL.dll'
怎样做竟然不行?
解决方案 »
- 还是托盘小问题.为什么我获得到的tip和路径只是如"dows\systems\TTplayer.exe"这样不全的.
- 程序到笔记本的问题
- 如何获得当前用户在richEdit中选中的文字起始和终止位置?
- 请问一个 Socket Server 可做多个服务器吗?
- 数据库连接问题
- 请熟悉批处理增加数据的看看怎么解决这个问题-------
- 程序界面问题?
- 新手问一个关于事务操作的问题,还望高手指教
- 请教高手:如何关闭一个窗口或隐藏一个窗口,另外谁能给我一个关于数据库开发的小程序,不胜感激!
- 急啊,关于richedit
- 有没有delphi+sql编程 青岛的高手
- not valid interger value
看不出有什么问题,在不用delphi的情况下有问题么?
function OpenComm( byPort:byte; dwCommBaudRate:dword ): word;
stdcall;external 'DLL.dll' name 'OpenComm';Function ReadNum( iCard:Pinteger;byCardNum:Pbyte):word;
stdcall;external 'DLL.dll' name 'ReadNum';
.......;function APGetVolume(var vol : DWORD) : HRESULT; stdcall;implementationconst
DLLNAME = 'X.dll';function APGetVolume; external DLLNAME name 'APGetVolume';end.
external 'DLL.dll ' ;第二个接口函数如果使用下面的声明的话,传入前,要分配内存空间,才能正常使用。
使用完后,要释放内存空间;(入参为指针类,可实现回调作用)
Function ReadNum(iCard:Pinteger;byCardNum:Pbyte):word;stdcall;far;
external 'DLL.dll ';第二个函数可以用这样的方式声明:(入参为引用类型,有回调作用)
Function ReadNum(var iCard:integer;var byCardNum:byte):word;stdcall;far;
external 'DLL.dll ';示例代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DoSth(icard:pinteger);
procedure Do_Sth(var icard:integer);
end;var
Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.DoSth(icard: pinteger);
begin
icard^:=icard^+1;
end;procedure TForm1.Button1Click(Sender: TObject);
var
pi:pinteger;
i:integer;begin
new(pi);
try
pi^:=100;
DoSth(pi);
showmessage(inttostr(pi^));
finally
dispose(pi);
end; i:=100;
do_sth(i);
showmessage(inttostr(i));
end;procedure TForm1.Do_Sth(var icard: integer);
begin
icard:=icard+1;
end;end.
-----------------------------
运行结果跟你的机器环境相关,对串口操作,如果串口被占用或者不存在,打开串口就会失败,OpenComm 返回值就不是设备句柄,另外,如果打开串口失败,ReadNum操作返回值也是错误的。