关于dll动态调用的问题,求救各位大虾 ( 积分: 100 )

  • 主题发起人 主题发起人 zstjungle
  • 开始时间 开始时间
Z

zstjungle

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟在调用xdll.DLL(exports OpenCom,SendByte,CloseCom三个函数)时老是提示错误,不只是什么原因,求教各位大虾,急!!!

源码如下:
type
TOpenCom = function(const port:dword):boolean;
TCloseCom = function():boolean;
TSendByte = function(const SendB:pchar;const SLen:dword):boolean;

procedure TForm1.Button1Click(Sender: TObject);
Var
LibHandle: Thandle;
OpenCom: TOpenCom;
CloseCom: TCloseCom;
SendByte: TSendByte;
Begin
LibHandle := LoadLibrary('xdll.dll');
try
if LibHandle = 0 then
raise exception.create('找不到动态库xdll.dll');

@OpenCom := GetProcAddress(LibHandle,'OpenCom');
@CloseCom := GetProcAddress(LibHandle,'CloseCom');
@SendByte := GetProcAddress(LibHandle,'SendByte')


if @SendByte=nil then exit;
begin
OpenCom(ComboBox1.itemindex+1);
SendByte(pchar('abcd'),4)
{运行到此会出错Project xxx.exe faulted with message:'access violation at 0x024acefc:read of address 0x00464000'.}
CloseCom();
end;
finally
FreeLibrary(LibHandle);
end;
end;
 
小弟在调用xdll.DLL(exports OpenCom,SendByte,CloseCom三个函数)时老是提示错误,不只是什么原因,求教各位大虾,急!!!

源码如下:
type
TOpenCom = function(const port:dword):boolean;
TCloseCom = function():boolean;
TSendByte = function(const SendB:pchar;const SLen:dword):boolean;

procedure TForm1.Button1Click(Sender: TObject);
Var
LibHandle: Thandle;
OpenCom: TOpenCom;
CloseCom: TCloseCom;
SendByte: TSendByte;
Begin
LibHandle := LoadLibrary('xdll.dll');
try
if LibHandle = 0 then
raise exception.create('找不到动态库xdll.dll');

@OpenCom := GetProcAddress(LibHandle,'OpenCom');
@CloseCom := GetProcAddress(LibHandle,'CloseCom');
@SendByte := GetProcAddress(LibHandle,'SendByte')


if @SendByte=nil then exit;
begin
OpenCom(ComboBox1.itemindex+1);
SendByte(pchar('abcd'),4)
{运行到此会出错Project xxx.exe faulted with message:'access violation at 0x024acefc:read of address 0x00464000'.}
CloseCom();
end;
finally
FreeLibrary(LibHandle);
end;
end;
 
没人回答么
 
c := 'abcd';
SendByte(c, 4);
 
改了也不行啊,应该不是这个问题。
谢谢xianguo
 
TSendByte = function(const SendB:pchar;const SLen:dword):boolean

-->
TSendByte = function(SendB:pchar;const SLen:dword):boolean;
 
var
buf:array[0..255] of char;
....
buf:='abcd';
SendByte(buf,4);
 
TOpenCom = function(const port:dword):boolean;stdcall;
TCloseCom = function():boolean;stdcall;
TSendByte = function(const SendB:pchar;const SLen:dword):boolean;stdcall;
 
谢谢wqyzsh
 
问题如wqyzsh所言,已解决
 
后退
顶部