這段代碼有什么錯誤?
TestDll:
TestDll.c :
==================================
int Test(int a)
{
return 10;
}
==================================
TestDll.def:
===================================
LIBRARY "TestDll.Dll"
EXPORTS
Test @1;
============================================================
Delphi調用代碼:
TTest = function(a:integer): integer; stdcall;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
Var
ChgFunc:TTest;
DllHandle:THandle;
DllName:string;
Ack:Byte;
begin
DllName:='TestDll.dll';
DllHandle:=LoadLibrary(PChar(DllName));
Ack:=0;
If DllHandle>0 then
Begin
@ChgFunc:=GetProcAddress(DllHandle,'Test');
If Assigned(@ChgFunc) then
Begin
Ack:=ChgFunc(0);
End;
End;
ShowMessage(inttostr(Ack));
FreeLibrary(DllHandle);
end;
==================================
Delphi中調用時,ShowMessage顯示為10,但是調用完成后,出現"應用程序錯誤,即將關閉“這樣的錯誤提示,然后應用程序非法關閉了。這是怎么回事?是否這個Dll有什么問題?