procedure Secret16Encrypt(lpInBuffer:PChar; lpKey:PChar);
var
Secret16Encrypt: function(lpInBuffer:PChar; lpKey:PChar; lpOutBuffer:PChar): Boolean; stdcall;
OutputStr: array [0..16] of Char;
begin
FillChar(OutputStr, Sizeof(OutputStr), #0);
Initialize;
if hlib <> 0 then begin
@Secret16Encrypt := GetProcAddress(hlib, 'Secret16Encrypt');
if @Secret16Encrypt <> nil then begin
if Secret16Encrypt(lpInBuffer, lpKey, OutputStr) then
Return := OutputStr
else
Return := '函数调用错误!'
end
else
ShowMessage('加载功能模块出错!'); FreeLibrary(hlib);
end
else
ShowMessage('无法加载DLL!');
end;上面这段代码是我从人家的一个DEMO里面拷贝出来的,它功能是就是输入一个字符串和一个Key然后得到加密结果,但是它没有通过函数返回加果,而是通过函数参数返回结果,lpOutBuffer就是返回结果,这样的效果应该在DLL怎么定义呢?
不用VAR应该怎么实现?
var
Secret16Encrypt: function(lpInBuffer:PChar; lpKey:PChar; lpOutBuffer:PChar): Boolean; stdcall;
OutputStr: array [0..16] of Char;
begin
FillChar(OutputStr, Sizeof(OutputStr), #0);
Initialize;
if hlib <> 0 then begin
@Secret16Encrypt := GetProcAddress(hlib, 'Secret16Encrypt');
if @Secret16Encrypt <> nil then begin
if Secret16Encrypt(lpInBuffer, lpKey, OutputStr) then
Return := OutputStr
else
Return := '函数调用错误!'
end
else
ShowMessage('加载功能模块出错!'); FreeLibrary(hlib);
end
else
ShowMessage('无法加载DLL!');
end;上面这段代码是我从人家的一个DEMO里面拷贝出来的,它功能是就是输入一个字符串和一个Key然后得到加密结果,但是它没有通过函数返回加果,而是通过函数参数返回结果,lpOutBuffer就是返回结果,这样的效果应该在DLL怎么定义呢?
不用VAR应该怎么实现?
function Secret16Encrypt(lpInBuffer:PChar; lpKey:PChar; lpOutBuffer:PChar): Boolean;
可能大伙还没有看明白我的意思吧,我的意思是最后函数返回加密后的值是返回给lpOutBuffer,这样是怎么样做到的?
library AppDll;uses
SysUtils,Windows,Classes,Dialogs;{$R *.res}function AddStr(lpInputStr:PChar;lpOutputStr:PChar):Boolean;stdcall;
begin
try
lpOutputStr:=PChar(StrPas(lpInputStr)+'abcdef');
Result:=True;
except
Result:=False;
end;
end;exports
AddStr;
begin
end.主程序代码:
var
hlib: HMODULE;implementation{$R *.dfm}procedure Initialize;
begin
hlib:= LoadLibrary('AppDLL.dll');
end;Procedure Str(lpInputStr:PChar);
var
AddStr: function(lpInputStr:PChar;lpOutputStr:PChar): Boolean; stdcall;
DllStr:array[0..30] of Char;
begin
FillChar(DllStr, SizeOf(DllStr), #0);
Initialize;
if hlib <> 0 then begin
@AddStr := GetProcAddress(hLib, 'AddStr');
if @AddStr <> nil then begin
if AddStr(lpInputStr, DllStr) then
Form1.Edit1.Text:= DLLStr
else
Form1.Edit1.Text:= '函数调用错误!'
end
else
ShowMessage('加载功能模块出错!'); FreeLibrary(hLib);
end
else
ShowMessage('无法加载DLL!');
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Str(PChar('123456'));
end;