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 SendBchar;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;
源码如下:
type
TOpenCom = function(const port:dword):boolean;
TCloseCom = function():boolean;
TSendByte = function(const SendBchar;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;