//得到DLL内函数指针的函数
function GetDllFunc(const strDllName, strFuncName: string): pointer;
var hdlDll: THandle;
begin
Result := nil;
hdlDll := LoadLibrary(PChar(strDllName));
if hdlDll = 0 then Exit;
Result := GetProcAddress(hdlDll, PChar(strFuncName));
end;
注:
1)知道DLL中的函数名,注意大小写问题;
2)知道DLL中的函数结构,定义此结构:如:
type
TFucGetName = function(None: string): PChar;
也可以用一个定义单元!
3)使用DLL内的函数
procedure UseDLLFunc(const strDllName, strFuncName: string);
var pFunc: pointer;
pchrReturn: PChar;
begin
pFunc := GetDllFunc(strDllName, strFuncName);
if pFunc = nil then Exit;
pchrReturn := TFucGetName(pFunc)(EmptyStr);//使用函数
ShowMessage(string(pchrReturn));
end;