这是我的代码:
library PY;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Classes;
function GetPYIndexChar(Hzchar:string):String;stdcall;
begin
case (Word(hzchar[1]) shl 8 + word(hzchar[2])) of
$B0A1..$B0C4 : Result :='A';
$B0C5..$B2C0 : Result :='B';
$B2C1..$B4ED : Result :='C';
$B4EE..$B6E9 : Result :='D';
$B6EA..$B7A1 : Result :='E';
$B7A2..$B8C0 : Result :='F';
$B8C1..$B9FD : Result :='G';
$B9FE..$BBF6 : Result :='H';
$BBF7..$BFA5 : Result :='J';
$BFA6..$C0AB : Result :='K';
$C0AC..$C2E7 : Result :='L';
$C2E8..$C4C2 : Result :='M';
$C4C3..$C5B5 : Result :='N';
$C5B6..$C5BD : Result :='O';
$C5BE..$C6D9 : Result :='P';
$C6DA..$C8BA : Result :='Q';
$C8BB..$C8F5 : Result :='R';
$C8F6..$CBF9 : Result :='S';
$CBFA..$CDD9 : Result :='T';
$CDDA..$CEF3 : Result :='W';
$CEF4..$D1B8 : Result :='X';
$D1B9..$D4D0 : Result :='Y';
$D4D1..$D7F9 : Result :='Z';
else
Result := char(32);
end;
end;
function GetJM(s:string):string;stdcall;
var
sw:wideString;
c,JM:string;
i:integer;
begin
JM:='';
sw:=s;
for i :=1 to length(sw) do
begin
c:= sw;
if length(c)>1 then
JM:=JM+GetPyIndexChar(c)
else
JM:=JM+c;
end;
Result:=JM;
end;
exports
GetPYIndexChar,
GetJM;
{$R *.res}
begin
end.
下面是我的别的地方调用的这个dll的代码
procedure TForm1.Button1Click(Sender: TObject);
type
TGetJM=function(s:string):string;stdcall;
var
DLLHandle: THandle;
Func:TGetJM;
begin
try
DLLHandle := LoadLibrary('py.dll');
if dllhandle<>0 then
@Func := GetProcAddress(DLLHandle,'GetJM');
if Assigned(@Func) then
Edit3.Text:=Func(Edit2.Text);
finally
FreeLibrary(DLLHandle);
end;
end;
现在就在FreeLibrary(DLLHandle); 这句上出错,然后edit3.text 也没有值;