dll隐式连接问题,高分求助

phs520 2004-04-21 12:09:50
有一个genfunction.dll,genfunction.lib,genfunction.h
库中有
int gen_Read(char ctype,char *command=NULL,char *adr=NULL,char *recbuff=NULL,unsigned short nreclen=0);

我创建了一个usb工程
在usb.h 中
#pragma comment(lib,"genfunction.lib");
extern "C"_declspec(dllimport) int gen_Read(char ctype1,char *command1=NULL,char *adr1=NULL,char *recbuff1=NULL,unsigned short nreclen1=0);

usbdlg.cpp中调用

出错

c:\windows\desktop\usb\genfunction.h(11) : error C2572: 'gen_Read' : redefinition of default parameter : parameter 5
c:\windows\desktop\usb\usbdlg.h(12) : see declaration of 'gen_Read'
c:\windows\desktop\usb\genfunction.h(11) : error C2572: 'gen_Read' : redefinition of default parameter : parameter 4
c:\windows\desktop\usb\usbdlg.h(12) : see declaration of 'gen_Read'
c:\windows\desktop\usb\genfunction.h(11) : error C2572: 'gen_Read' : redefinition of default parameter : parameter 3
c:\windows\desktop\usb\usbdlg.h(12) : see declaration of 'gen_Read'
c:\windows\desktop\usb\genfunction.h(11) : error C2572: 'gen_Read' : redefinition of default parameter : parameter 2

小弟对dll 知道很少,寻求各位帮助
...全文
36 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ymbymb 2004-04-21
  • 打赏
  • 举报
回复
你照我说的试试,我试了,是可以的!
phs520 2004-04-21
  • 打赏
  • 举报
回复
纠正一下:
在usb.h 中
#pragma comment(lib,"genfunction.lib");
extern "C"_declspec(dllimport) int gen_Read(char ctype,char *command=NULL,char *adr=NULL,char *recbuff=NULL,unsigned short nreclen=0);

也就是说定义一应用一样啊,参数相同,不同,都好象不行

ymbymb 2004-04-21
  • 打赏
  • 举报
回复
在你的dll中应该如下定义:
extern "C" __declspec(dllexport) void int gen_Read(char ctype1,char *command1,char *adr1,char *recbuff1,unsigned short nreclen1);

extern "C" __declspec(dllexport) int gen_Read(char ctype1,char *command1=NULL,char *adr1=NULL,char *recbuff1=NULL,unsigned short nreclen1=0)
{
...
}
phs520 2004-04-21
  • 打赏
  • 举报
回复
哈哈
不好意思!!这就结贴
ymbymb 2004-04-21
  • 打赏
  • 举报
回复
楼主的信誉分有点低哦,解决了请赶快结贴!
ymbymb 2004-04-21
  • 打赏
  • 举报
回复
我知道你的问题了,你只要在usb.cpp中
#pragma comment(lib, "genfunction.lib")
#include "genfunction.h"
就可以了, 不用再另做申明.
extern "C"_declspec(dllimport) int gen_Read(char ctype1,char *command1=NULL,char *adr1=NULL,char *recbuff1=NULL,unsigned short nreclen1=0);
这句多余,删除之,搞定!
phs520 2004-04-21
  • 打赏
  • 举报
回复
哈哈谢谢了
三个文件
genfunction.h
genfunction.lib
genfunction.dll
ymbymb 2004-04-21
  • 打赏
  • 举报
回复
晕!把代码发过来,帮你搞定! ymbymb@yahoo.com
phs520 2004-04-21
  • 打赏
  • 举报
回复
不是很明白,
remove all the extern "C" or all add extern "C"

好象也不行
rivershan 2004-04-21
  • 打赏
  • 举报
回复
remove all the extern "C" or all add extern "C"
phs520 2004-04-21
  • 打赏
  • 举报
回复
我试了,还是不行啊
dll定义的:
int __stdcall gen_Read(char ctype,char *command=NULL,
char *addr=NULL,char *recbuff=NULL,unsigned short nreclen=0);

引用的:
#pragma comment(lib,"genfunction.lib");
extern "C"_declspec(dllimport) int gen_Read(char ctype,char *command=NULL,char *adr=NULL,char *recbuff=NULL,unsigned short nreclen=0);

应该以你的类似吧!!
dll是别人写的,所以没办法该:)
因为我的dll不熟,是不是引用不对啊!!!

15,471

社区成员

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

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