我想寻求帮助。我知道,有很多地方,我可以得到这些信息。但是,无论如何,我在将 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);