For more information about dynamic DLL calling, see. Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061117201842206.html
DLL Code As follows:
Library dllsplitstring;
Uses
Sysutils,
Classes;
{$ R *. Res}
// The following functions separate characters according to the delimiter and write the separated characters into the 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.
Program In the call process:
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;
Why is the error 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;
The splitstring identifier is not defined.
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;