Delphi 动态调用Dll,释放时为什么总报错
procedureTForm1.Button2Click(Sender:TObject);typetfun=function(instr:PansiChar;outstr...
procedure TForm1.Button2Click(Sender: TObject);
type
tfun = function(instr: PansiChar; outstr: PansiChar; len: Integer)
: Integer; stdcall;
var
dll: THandle;
DeviceQuaryCommand: tfun;
pinstr, poutstr: PansiChar;
begin
dll := LoadLibrary('RelayControlCtl.DLL');
try
if dll <> 0 then
begin
@DeviceQuaryCommand := GetProcAddress(dll, 'DeviceQuaryCommand');
if @DeviceQuaryCommand <> nil then
begin
pinstr := ('R1:ON');
poutstr := GetMemory(10);
ZeroMemory(poutstr, 10);
DeviceQuaryCommand(pinstr, poutstr, 10);
MemoOutput.Text := (poutstr);
freememory(poutstr);
end;
end;
finally
FreeLibrary(dll);//这里报错,不知道为什么
end;
end; 展开
type
tfun = function(instr: PansiChar; outstr: PansiChar; len: Integer)
: Integer; stdcall;
var
dll: THandle;
DeviceQuaryCommand: tfun;
pinstr, poutstr: PansiChar;
begin
dll := LoadLibrary('RelayControlCtl.DLL');
try
if dll <> 0 then
begin
@DeviceQuaryCommand := GetProcAddress(dll, 'DeviceQuaryCommand');
if @DeviceQuaryCommand <> nil then
begin
pinstr := ('R1:ON');
poutstr := GetMemory(10);
ZeroMemory(poutstr, 10);
DeviceQuaryCommand(pinstr, poutstr, 10);
MemoOutput.Text := (poutstr);
freememory(poutstr);
end;
end;
finally
FreeLibrary(dll);//这里报错,不知道为什么
end;
end; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询