有一个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 知道很少,寻求各位帮助

解决方案 »

  1.   

    在你的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)
    {
    ...
    }
      

  2.   

    纠正一下:
    在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);也就是说定义一应用一样啊,参数相同,不同,都好象不行
      

  3.   

    我试了,还是不行啊
    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不熟,是不是引用不对啊!!!
      

  4.   

    remove all the extern "C" or all add extern "C"
      

  5.   

    不是很明白,
    remove all the extern "C" or all add extern "C"
     
    好象也不行
      

  6.   

    晕!把代码发过来,帮你搞定! [email protected]
      

  7.   

    哈哈谢谢了
     三个文件
    genfunction.h
    genfunction.lib
    genfunction.dll
      

  8.   

    我知道你的问题了,你只要在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);
    这句多余,删除之,搞定!