VB 声明如下:
Public Declare Function CheckData& Lib "chk100.dll" Alias "chk100" _
(ByVal ProgressbarFunctionAddress As Long, ByRef MyDepth As Single, ByRef rtA1 As Single, ByRef rtA7 As Single, ByRef rtA8 As Single)
VB 调用如下:
CheckData AddressOf ProgressBar1, Depth1(1), rtA2(1), rtA7(1), rtA8(1)
其中:
Progressbar1为一个函数 其它都是数组
请问Delphi中如何调用DLL中的函数,各项类型该怎么声明呢?
怎么传递数组地址?是不是@depth?
Public Declare Function CheckData& Lib "chk100.dll" Alias "chk100" _
(ByVal ProgressbarFunctionAddress As Long, ByRef MyDepth As Single, ByRef rtA1 As Single, ByRef rtA7 As Single, ByRef rtA8 As Single)
VB 调用如下:
CheckData AddressOf ProgressBar1, Depth1(1), rtA2(1), rtA7(1), rtA8(1)
其中:
Progressbar1为一个函数 其它都是数组
请问Delphi中如何调用DLL中的函数,各项类型该怎么声明呢?
怎么传递数组地址?是不是@depth?
procedure CallReport(SourceGrid:TDBGrid; TitleCap,Indent,ShowField:ShortString);
var
LibHandle : THandle;
GeneralRpt : TGeneralRpt;
TempCap : String;
begin
LibHandle := LoadLibrary('ReportDll.dll');
try
if LibHandle = 0 then
raise EDLLLoadError.Create('Unable to Load DLL');
@GeneralRpt := GetProcAddress(LibHandle, 'GeneralRpt'); TempCap :=GetOldCap(ShowField); if not (@GeneralRpt = nil) then
GeneralRpt(Application.Handle, '通用报表生成器',SourceGrid,TitleCap,Indent,TempCap)
else
RaiseLastWin32Error;
finally
FreeLibrary(LibHandle); // Unload the DLL.
end;
end;
--------------------------------------------procedure TForm1.Button1Click(Sender: TObject);
type
TNewCheckData = function (ProgressbarFunctionAddress:Longint;MyDepth,rtA1,rtA7,rtA8:PSingle): 返回类型; StdCall;
var
mNewCheckData:TNewCheckData;
myhandle:Thandle;
begin
myhandle:= LoadLibrary('chk100.dll');
try
if myhandle<=0 then
raise exception.Create('DLL调用失败,错误代码为:'+inttostr(getlasterror))
else
begin
@mNewCheckData:=GetProcAddress(myhandle, 'CheckData');
if not assigned(mNewCheckData)then
raise exception.Create('getproceaddress调用失败,错误代码:'+inttostr(getlasterror))
else
begin
//自己调用函数处理部分
end;
end;
finally
freelibrary(myhandle);
end;
end;