delphi 动态连接库调用exe中的函数,时出现access violation at 0x0047a214 :read of address 0x0047
exe中的代码
unit Compile;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, Menus, ActnList;
type
TForm1 = class(TForm)
.....
end;
function XMLSaveInfo:string;
function XMLLoadInfo(LoadStr :String):Boolean ;
exports
XMLSaveInfo index 0 name 'XMLSaveInfo',
XMLLoadInfo index 1 name 'XMLLoadInfo';
测试调用该EXE代码
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TXMLSaveInfo = function :string; //定义
TForm1 = class(TForm)
。。。。
end;
procedure TForm1.Button1Click(Sender: TObject);
var
lib : THandle;
XMLSaveInfo :TXMLSaveInfo;
begin
try
FilName :=APath;
lib :=LoadLibrary('Compli.exe');
if lib = 0 then
ShowMessage('Cannot load the module')
else
begin
@XMLSaveInfo := GetProcAddress(lib,'XMLSaveInfo');
if @XMLSaveInfo =nil then
ShowMessage('Cannot GetProcAddress')
else
begin
memo1.lines.add(TXMLSaveInfo(@XMLSaveInfo));
end;
FreeLibrary(lib);
end;
except
on e:Exception do
showmessage(e.Message);
end;
end;
问题是调用到
memo1.lines.add(TXMLSaveInfo(@XMLSaveInfo));
出现 access violation at 0x0047a214 :read of address 0x0047a214 .. 这个问题该如何解决
等待高手。。。。希望讲的详细点(谢谢)