c++builder如何调用vc++MFC DLL 中带有参数的函数(急!!! 在线等)

syy64 2004-05-14 10:47:15
程序如下:
h文件:

//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TOpenDialog *ttt;
TMainMenu *MainMenu1;
TEdit *Edit1;
TLabel *Label1;
TPopupMenu *PopupMenu1;
TButton *Button1;
void __fastcall Edit1Change(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern "C" __declspec(dllimport) double __stdcall Ex21cSquareRoot(double d);
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

*.cpp 文件:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
int jj;
double d, d1;
// extern "C" __declspec(dllimport) double __stdcall Ex21cSquareRoot(double d);

HINSTANCE h;
FARPROC pp;
// int _stdcall (*t)(void);
// double _stdcall (*t(double))(void);
h=LoadLibrary("ex21c.dll"); //导入库
pp = GetProcAddress(h,"Ex21cSquareRoot"); //指出库中函数的位置
d = 9.0;
// d1 = Ex21cSquareRoot(d);
d1 = pp(d); 这一行编译出错:[C++ Error] Unit1.cpp(42): E2226 Extra parameter in call
// ShowMessage(IntToStr(t()));
FreeLibrary(h);

jj = 2;
}
//---------------------------------------------------------------------------

高手帮帮忙!!!
...全文
213 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
seajoke 2004-06-18
  • 打赏
  • 举报
回复
两种调用方法被你搞混了!
1。extern "C" __declspec(dllimport) double __stdcall Ex21cSquareRoot(double d);
然后直接调用函数 Ex21cSquareRoot(double d);
2。typedef double (_stdcall *pEx21cSquareRoot)(double d);
*.cpp:
pEx21cSquareRoot FEx21cSquareRoot;
FEx21cSquareRoot = (pEx21cSquareRoot)::GetProcAddress( h, "Ex21cSquareRoot");
然后直接调用函数 FEx21cSquareRoot(double d);
syy64 2004-06-08
  • 打赏
  • 举报
回复
问题已仅仅,谢谢各位。
childman 2004-06-08
  • 打赏
  • 举报
回复
可能是因为Borland的dll跟Microsoft的dll格式不一样的缘故,很有可能是
GetProcAddress(h,"Ex21cSquareRoot"); //没找到Ex21cSquareRoot这个函数,有可能是_Ex21cSquareRoot也说不定,可以用VC自带的那个Dependy.exe看看
bocwg 2004-06-08
  • 打赏
  • 举报
回复
extern "C" __declspec(dllexport) double __stdcall Ex21cSquareRoot(double d);
dllimport改为dllexport
syy64 2004-05-14
  • 打赏
  • 举报
回复
有高手知道吗?
syy64 2004-05-14
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int jj;
double d, d1;
// extern "C" __declspec(dllimport) double __stdcall Ex21cSquareRoot(double d);

HINSTANCE h;
FARPROC pp;
// int _stdcall (*t)(void);
typedef double _stdcall (*t)(double);
h=LoadLibrary("ex21c.dll"); //导入库
t t1 = (t)GetProcAddress(h,"Ex21cSquareRoot"); //指出库中函数的位置
d = 9.0;
d1 = t1(d);
FreeLibrary(h);

jj = 2;
}
//---------------------------------------------------------------------------
我又将程序改成上面这样,编译到通过了,但运行时,t1为NULL
有谁能帮帮我!,看来周末没法休息啦!
syy64 2004-05-14
  • 打赏
  • 举报
回复
你能教教我方法吗?
fxly 2004-05-14
  • 打赏
  • 举报
回复
楼主的调用步骤太烦杂了,根本不需要那么麻烦!
syy64 2004-05-14
  • 打赏
  • 举报
回复
动态调用也需要吗?
ccddff 2004-05-14
  • 打赏
  • 举报
回复
在项目里有没有包含文件 ex21c.lib ?

13,870

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧