非常急,bcb怎么使用dll里带有参数的函数?

wingfootedtiger 2005-09-28 01:42:11
拿来一个dll,里面有个函数 ttt(LPCTSTR str1, LPCTSTR str2)

我的代码如下:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE dllHandle;
int _stdcall (*aaa)(void);
dllHandle=LoadLibrary("dlltest.dll");
aaa=GetProcAddress(dllHandle,"ttt");
aaa("999","111");
FreeLibrary(dllHandle);
}
编译不通过,错误信息 [C++ Error] Unit1.cpp(26): E2226 Extra parameter in call

如果将aaa("999","111");改为 aaa();就能正常编译,但运行的时候肯定出错了
请问怎么写?
...全文
191 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
wingfootedtiger 2005-09-28
  • 打赏
  • 举报
回复
结贴,开新贴问
wingfootedtiger 2005-09-28
  • 打赏
  • 举报
回复
这是测试过的代码么?我还是不能编译通过,信息如下
[C++ Error] Unit1.cpp(23): E2034 Cannot convert 'int (__stdcall *)()' to 'void (__stdcall *)(const char *,const char *)'
marchily 2005-09-28
  • 打赏
  • 举报
回复
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE dllHandle;
void_stdcall (*aaa)(LPCTSTR,LPCTSTR);
dllHandle=LoadLibrary("dlltest.dll");
aaa=GetProcAddress(dllHandle,"ttt");
aaa("999","111");
FreeLibrary(dllHandle);
}
Dll中应该没返回值,你把int 改为 void 在看看
rainfall19831109 2005-09-28
  • 打赏
  • 举报
回复
TO楼主:
首先你是要确定DLL里函数的返回值的类型到底是不是int
另外
定义函数指针的时候不用写明调用方式,即是:int (*aaa)(LPCTSTR,LPCTSTR)就可以了
wingfootedtiger 2005-09-28
  • 打赏
  • 举报
回复
楼上的,用了你的也不行
我现在改为
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE dllHandle;
int _stdcall (*aaa)(LPCTSTR,LPCTSTR);
dllHandle=LoadLibrary("dlltest.dll");
aaa=GetProcAddress(dllHandle,"ttt");
aaa("999","111");
FreeLibrary(dllHandle);
}
报错信息如下:
[C++ Error] Unit1.cpp(25): E2034 Cannot convert 'int (__stdcall *)()' to 'int (__stdcall *)(const char *,const char *)'

how to do ?
marchily 2005-09-28
  • 打赏
  • 举报
回复
HINSTANCE dllHandle;
FARPROC lpFarProc;
int _stdcall (*aaa)(LPCTSTR ,LPCTSTR );
dllHandle=LoadLibrary("dlltest.dll");
pFarProc=GetProcAddress(dllHandle,"ttt");
aaa=(int(_stdcall *)(AnsiString,AnsiString))lpFarProc;
aaa("999","111");
FreeLibrary(dllHandle)
你试下看看
constantine 2005-09-28
  • 打赏
  • 举报
回复
int _stdcall (*aaa)(void);--->后面的void要对要函数的参数类型,不过按照你用字符串
bcb里面如果要用AnsiString就比较麻烦,dll开头的说明自己看了

13,825

社区成员

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

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