dll调用时的问题,急呀。

congzhongxiao_57 2007-04-18 06:18:52
我的DLL代码
extern "C" void _declspec(dllexport)
__stdcall SplitWord(char *a,char*b)
{

}


调用代码
#include <iostream.h>
#include <Windows.h>
void main(){

//typedef int (*ADD)(int ,int);//函数指针类型
//加载我们刚才生成的dll
//ADD add = (ADD)GetProcAddress(Hint,"add");//取得dll导出的add方法
char *a,*b;
a="abcd";
b=NULL;
typedef void (__stdcall *SP)(char*,char*);
HINSTANCE Hint = ::LoadLibrary("Test002.dll");

SP swTest=GetProcAddress(Hint,"SplitWord");
swTest(a,b);
cout<<a<<endl;
cout<<b<<endl;
}

错误提示:
cannot convert from 'int (__stdcall *)(void)' to 'void (__stdcall *)(char *,char *)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast


为甚么我的DLL导出的时'int (__stdcall *)(void)'啊?
给各正确答案啊,谢谢了

...全文
224 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
congzhongxiao_57 2007-04-20
  • 打赏
  • 举报
回复
学了很多东西,不好意思分给少了。
HF_99 2007-04-19
  • 打赏
  • 举报
回复
不好意思写错了
extern "C"__declspec(dllexport) void SplitWord(char *a,char*b)
{

}
ATField 2007-04-18
  • 打赏
  • 举报
回复
进一步解释一下, GetProcAddress返回的是FARPROC,其定义为
typedef int (FAR WINAPI *FARPROC)();
也就是int (__stdcall *)(void);
这个结果应该被转换成正确的函数指针类型,也就是int (__stdcall *)(char *, char *)
只需要一个C-style cast或者reinterpret_cast即可。
正确写法是:
SP swTest = (SP)GetProcAddress(...)
or
SP swTest = reinterpret_cast<SP>(GetProcAddress(...));
neil_cn 2007-04-18
  • 打赏
  • 举报
回复
同意 llydd() 的
SP swTest=GetProcAddress(Hint,"SplitWord");
改成SP swTest=(SP)GetProcAddress(Hint,"SplitWord");
试试


HF_99() 写的那个是导入声明,不是导出声明
HF_99 2007-04-18
  • 打赏
  • 举报
回复
将DLL代码改成这样,看看行吗
extern "C"__declspec(dllimport) void SplitWord(char *a,char*b)
{

}
llydd 2007-04-18
  • 打赏
  • 举报
回复
SP swTest=GetProcAddress(Hint,"SplitWord");
改成SP swTest=(SP)GetProcAddress(Hint,"SplitWord");
试试

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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