有关动态调用DLL的问题,请教。
http://www.delphi2007.net/DelphiAPI/html/delphi_20061117201842206.html
DLL代码如下:
library DLLSplitString;
uses
SysUtils,
Classes;
{$R *.res}
// 以下函数实现根据分隔符分隔字符,并将分隔出来的字符写进StringList中。
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList: TStringList;
begin
StringList := TStringList.Create;
while Pos(Deli, Source)>0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;
exports
SplitString;
begin
end.
程序中的调用过程:
procedure TForm1.Button1Click(Sender: TObject);
var
OneHandle: THandle;
begin
OneHandle := LoadLibrary('DLLSplitString.dll');
try
if OneHandle <> 0 then
@SplitString := GetProcAddress(OneHandle, 'SplitString');
if not (@SplitString = nil) then
...
else
RaiseLastWin32Error;
finally
FreeLibrary(OneHandle);
end;
end;
为何一直报错 Undeclared identifier: 'SplitString' 如何处理呢?
procedure TForm1.Button1Click(Sender: TObject);
type
SplitString =function SplitString(Source, Deli: string ): TStringList;stdcall;
var
OneHandle: THandle;
begin
OneHandle := LoadLibrary('DLLSplitString.dll');
try
if OneHandle <> 0 then
@SplitString := GetProcAddress(OneHandle, 'SplitString');
if not (@SplitString = nil) then
...
else
RaiseLastWin32Error;
finally
FreeLibrary(OneHandle);
end;
end;
SplitString标识符未定义。
procedure TForm1.Button1Click(Sender: TObject);
var
OneHandle: THandle;
SplitString: function (Source, Deli: string): TStringList;
begin
OneHandle := LoadLibrary('DLLSplitString.dll');
try
if OneHandle <> 0 then
SplitString := GetProcAddress(OneHandle, 'SplitString');
if SplitString <> nil then
...
else
RaiseLastWin32Error;
finally
FreeLibrary(OneHandle);
end;
end;