调用dll有三种方法,楼上的只说了一种,其他的相对比较麻烦 1:function MyFunction(s:string;i:integer;...):boolean stdcall; external 'DLLName.dll' index x;2:function MyFunction(s:string;i:integer;...):Integer stdcall; external 'DLLName.dll' name 'FunctionName';
静态:function MyFunction(..): type stdcall; external 'DLLName.dll'; 动态: type TOleRegisterFunction = function : HResult; ... hLibraryHandle := LoadLibrary(PCHAR(strOleFileName)); if (hLibraryHandle > 0) then try if (OleAction = RegisterOle) then hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer')) else hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllUnregisterServer')); if (hFunctionAddress <> NIL) then begin RegFunction := TOleRegisterFunction(hFunctionAddress); if RegFunction >= 0 then result := true; end; finally FreeLibrary(hLibraryHandle); end;
function MyFunction(S: string): string; external 'MYDLL.dll';
ActiveX:
菜单 Component\Import ActiveX Control...
然后与使用VCL差不多!
1:function MyFunction(s:string;i:integer;...):boolean stdcall; external 'DLLName.dll' index x;2:function MyFunction(s:string;i:integer;...):Integer stdcall; external 'DLLName.dll' name 'FunctionName';
动态:
type
TOleRegisterFunction = function : HResult;
...
hLibraryHandle := LoadLibrary(PCHAR(strOleFileName));
if (hLibraryHandle > 0) then try
if (OleAction = RegisterOle) then hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllRegisterServer'))
else hFunctionAddress := GetProcAddress(hLibraryHandle, pchar('DllUnregisterServer'));
if (hFunctionAddress <> NIL) then begin
RegFunction := TOleRegisterFunction(hFunctionAddress); if RegFunction >= 0 then result := true;
end;
finally
FreeLibrary(hLibraryHandle);
end;