function CheckStr(str1:string;str2:string):Boolean;export; begin if str1=str2 then CheckStr:=true else CheckStr:=false; end; 在用静态的调用dll方式调用即可!
最好用 pchar 或 shortString 来传递字符串参数。 function FuncCheckString(str1,str2:pchar):integer;stdcall; begin ........... if 合法 then result := 1 else result := 0; end; export FuncCheckString index 1;
楼上说的对用pchar类型可以被其他编程语言调用该dll!就听他的吧!
那我的调用代码应该如何将参数传给DLL里面的函数啊?我是动态装载DLL的
以下是delphi的help里关于动态装载DLL,并调用其中函数的例子原文,请参考: uses Windows, ...; type TTimeRec = record Second: Integer; Minute: Integer; Hour: Integer; end; TGetTime = procedure(var Time: TTimeRec); THandle = Integer;var Time: TTimeRec; Handle: THandle; GetTime: TGetTime; ... begin Handle := LoadLibrary('DATETIME.DLL'); if Handle <> 0 then begin @GetTime := GetProcAddress(Handle, 'GetTime'); if @GetTime <> nil then begin GetTime(Time); with Time do WriteLn('The time is ', Hour, ':', Minute, ':', Second); end; FreeLibrary(Handle); end;end;
begin
if str1=str2 then CheckStr:=true
else CheckStr:=false;
end;
在用静态的调用dll方式调用即可!
function FuncCheckString(str1,str2:pchar):integer;stdcall;
begin
...........
if 合法 then
result := 1
else
result := 0;
end;
export
FuncCheckString index 1;
uses Windows, ...;
type TTimeRec = record
Second: Integer;
Minute: Integer;
Hour: Integer;
end; TGetTime = procedure(var Time: TTimeRec); THandle = Integer;var Time: TTimeRec;
Handle: THandle;
GetTime: TGetTime;
...
begin
Handle := LoadLibrary('DATETIME.DLL');
if Handle <> 0 then
begin
@GetTime := GetProcAddress(Handle, 'GetTime');
if @GetTime <> nil then
begin
GetTime(Time);
with Time do
WriteLn('The time is ', Hour, ':', Minute, ':', Second);
end;
FreeLibrary(Handle);
end;end;