我希望能够得到你的帮助。 我知道有很多地方可以获取这些信息。但是,无论如何,我在将Delphi DLL连接到我的C++ Builder项目时遇到了问题。
例如,我的Delphi DLL如下:
library f_dll;
uses
SysUtils,
Classes,
Forms,
Windows;
procedure HW(AForm : TForm);
begin
MessageBox(AForm.Handle, 'DLL message', 'you made it!',MB_OK);
end;
exports
HW;
{$R *.res}
begin
end.
以下是我连接 DLL 和其中一个函数的步骤:
//defining a function pointer type
typedef void (*dll_func)(TForm* AForm);
dll_func HLLWRLD = NULL;
HMODULE hDLL = LoadLibrary("f_dll.dll");
if (!hDLL) ShowMessage("Unable to load the library!");
//getting adress of the function
HLLWRD = (dll_func)GetProcAddress(hDLL, "_HW");
if (!pShowSum) ShowMessage("Unable to find the function");
HLLWRLD(Form1);
FreeLibrary(hDLL);
编译器没有给出错误信息,但是提示框显示未连接dll。我已将dll文件放置在项目文件夹和Debug文件夹中,但仍然没有连接。
请您帮助我,告诉我哪里出了问题?
编辑:我发布了有错误的C++代码,这是正确的代码(适用于遇到类似问题的人):
//defining a function pointer type
typedef void (*dll_func)(TForm* AForm);
dll_func HLLWRLD = NULL;
HMODULE hDLL = LoadLibrary("f_dll.dll");
if (!hDLL) ShowMessage("Unable to load the library!");
//getting adress of the function
HLLWRD = (dll_func)GetProcAddress(hDLL, "HW"); //HW instead _HW
if (!HLLWRLD) ShowMessage("Unable to find the function"); //HLLWRLD instead pShowSum
HLLWRLD(Form1);
FreeLibrary(hDLL);
TForm
。读取句柄属性这样简单的操作就可以了。实际上,很多东西可能会起作用,但也有很多会失败。 - David Heffernan