Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 992
  • Last Modified:

Export DLL functions- Link error

I cant get the C++ V6 syntax correct to get a clean link of this DLL.  The intent is to create a function library to be used in VB6.

My confusion stems from a lack of understanding of decorated and undecorated symbnols.

I documented below the 1) the link error, 2) C++ code and 3) .def file
/////////////////////////////////
Link error:
Linking...
.\notes2clarifydll.def : warning LNK4022: cannot find unique match for symbol "Connect"
.\notes2clarifydll.def : warning LNK4002: "long __stdcall Connect(char *,char *,char *,char *)" (?Connect@@YGJPAD000@Z) defined in .\Debug\notes2clarifydll.obj
.\notes2clarifydll.def : warning LNK4002: "public: int __thiscall CAsyncSocket::Connect(char const *,unsigned int)" (?Connect@CAsyncSocket@@QAEHPBDI@Z) defined in D:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\nafxcwd.lib
.\notes2clarifydll.def : warning LNK4002: "public: int __thiscall CAsyncSocket::Connect(struct sockaddr const *,int)" (?Connect@CAsyncSocket@@QAEHPBUsockaddr@@H@Z) defined in D:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\nafxcwd.lib
.\notes2clarifydll.def : warning LNK4002: "protected: int __thiscall CDatabase::Connect(unsigned long)" (?Connect@CDatabase@@IAEHK@Z) defined in D:\Program Files\Microsoft Visual Studio\VC98\MFC\LIB\nafxcwd.lib
LINK : fatal error LNK1152: cannot resolve one or more undecorated symbols
LINK : fatal error LNK1141: failure during build of exports file
Error executing link.exe.
Creating browse info file...

notes2clarifydll.dll - 2 error(s), 5 warning(s)

//////////////////////////////////
Extracted code of the C function:

//Prototype functions called externally
long __stdcall Connect(char *,char *,char *,char *);
...

//Establish a connection to the database
long  __stdcall Connect(char *strServer,char *strDatabase,char *strUsername,char *strPassword)
{
      char *MOD = "ServerLogin";
      long iConnect_rc;

      //Login to the database.
      thedb.dbo_status = cpi_sess_login(strServer,  /* server name */
            strDatabase,  /* database name */
            strUsername,  /* login name */
            strPassword,  /* password */
            CPI_OPTIONS_DEFAULT,
            &dbid);
    iConnect_rc = check_status(thedb.dbo_status, MOD, "Error logging into the database. \n",1L);
      return iConnect_rc;
}


///////////////////////////////////
; notes2clarifydll.def : Declares the module parameters for the DLL.

LIBRARY      "notes2clarifydll"
DESCRIPTION  'notes2clarifydll Windows Dynamic Link Library'

EXPORTS
    ; Explicit exports can go here
      Connect
0
GregoryGr
Asked:
GregoryGr
  • 7
  • 5
1 Solution
 
WynCommented:
uncheck the setting in Projects menu.
 
0
 
WynCommented:
oops:
select not using MFC in setting option of Projects menu.
or using
__declspec(dllexport) before the connect function.
0
 
WynCommented:
The reason is the export function connect in your .def is not unique as the warning said:

notes2clarifydll.def : warning LNK4022: cannot find unique match for symbol "Connect"

You'd better change your function name to another or using methods above.
Regards
W.Yinan
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GregoryGrAuthor Commented:
I added "__declspec(dllexport)" and got a clean link BUT I cant reference the "Connect" function from my VB code

Example of your suggested change...
__declspec(dllexport) long __stdcall Connect(char *,char *,char *,char *);

Error from Vb when I call Connect...
can't find DLL entry point Connect in notes2clarifydll
0
 
GregoryGrAuthor Commented:
Adjusted points to 200
0
 
GregoryGrAuthor Commented:
I'll close this question because I now have a clean link (thanks).

I'll open a new question to resolve my problem of referencing the DLL funcion from VB6
0
 
GregoryGrAuthor Commented:
experts-exchange pilot error trying to close
0
 
WynCommented:
You'd better change the function name and add extern "C" before the function and define in .def as well.This will elliminate the name decoration.
Regards
W.Yinan

ps:
experts-exchange pilot error trying to close

----------
What's this?
0
 
WynCommented:
You'd better change the function name OR(!!!here is OR,I type as AND above) add extern "C" before the function and define in .def as well.This will elliminate the name decoration.
0
 
WynCommented:
btw:Changing the name is useful to use .def to export it without declspe..(..)
0
 
GregoryGrAuthor Commented:
done...and thanks again.  I love you guys ;>)
0
 
WynCommented:
Honored;)

W.Yinan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now