S
shamohu
Unregistered / Unconfirmed
GUEST, unregistred user!
用Borland C++ 5.5免费编译器,源程序如下,存为testdll.cpp,用命令行:
bcc32 -O2 -WDE “testdll.cpp”
可以生成testdll.dll动态库。
#include <windows.h>
void __declspec(dllexport) dllf(double a, double b){
b = a + 1;
}
在Delphi中:
procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc=procedure(a: double; b:double);cdecl;
var
Th:Thandle;
MyFunc:TintFunc;
Tp:TFarProc;
temb: double;
begin
Th:=LoadLibrary('D:/Borland/BCC55/Bin/testdll.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('dllf'));
if Tp<>nil then begin
MyFunc:=TIntFunc(Tp);
MyFunc(2,temb); // {调用dll函数} //这行出错
end
else
ShowMessage('dllf函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('testdll.dll没有找到');
end;
end.
运行时总出错,说”dllf函数没有找到“没找到,望高手指点,谢谢。
bcc32 -O2 -WDE “testdll.cpp”
可以生成testdll.dll动态库。
#include <windows.h>
void __declspec(dllexport) dllf(double a, double b){
b = a + 1;
}
在Delphi中:
procedure TForm1.Button1Click(Sender: TObject);
type
TIntFunc=procedure(a: double; b:double);cdecl;
var
Th:Thandle;
MyFunc:TintFunc;
Tp:TFarProc;
temb: double;
begin
Th:=LoadLibrary('D:/Borland/BCC55/Bin/testdll.dll'); {装载DLL}
if Th>0 then
try
Tp:=GetProcAddress(Th,PChar('dllf'));
if Tp<>nil then begin
MyFunc:=TIntFunc(Tp);
MyFunc(2,temb); // {调用dll函数} //这行出错
end
else
ShowMessage('dllf函数没有找到');
finally
FreeLibrary(Th); {释放DLL}
end
else
ShowMessage('testdll.dll没有找到');
end;
end.
运行时总出错,说”dllf函数没有找到“没找到,望高手指点,谢谢。