静态调用DLL出错.........
DLL工程的代码:(dgull.dll)
(uses
ShareMem,
SysUtils,
Classes,
Windows;)
Function GetSystemDirectory: String;Stdcall; //得到系统目录
Var
pcSystemDirectory: PChar;
dwSDSize: DWORD;
Begin
dwSDSize:=MAX_PATH+1;
GetMem(pcSystemDirectory, dwSDSize);
Try
If Windows.GetSystemDirectory(pcSystemDirectory, dwSDSize)<>0 Then
Result:=pcSystemDirectory;
Finally
FreeMem(pcSystemDirectory);
End;
End;
调用的代码:
Function GetSystemDirectory: String;Stdcall; external 'dgull.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(GetSystemDirectory);
end;
*****
问题是,第一次点击Button一切正常,结果也对,可是第二次点击Button是出现错误:
存取地址***违例发生在模块"ntdll.dll"中**********
怎么解决?是不是GetSystemDirectory函数的事?