Solved

Export DLL functions- Link error

Posted on 2000-02-23
12
912 Views
Last Modified: 2008-03-06
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
Comment
Question by:GregoryGr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
12 Comments
 
LVL 5

Accepted Solution

by:
Wyn earned 200 total points
ID: 2550925
uncheck the setting in Projects menu.
 
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2550940
oops:
select not using MFC in setting option of Projects menu.
or using
__declspec(dllexport) before the connect function.
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2550969
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
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!

 

Author Comment

by:GregoryGr
ID: 2550981
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
 

Author Comment

by:GregoryGr
ID: 2551509
Adjusted points to 200
0
 

Author Comment

by:GregoryGr
ID: 2551553
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
 

Author Comment

by:GregoryGr
ID: 2551576
experts-exchange pilot error trying to close
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2553276
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
 
LVL 5

Expert Comment

by:Wyn
ID: 2553287
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
 
LVL 5

Expert Comment

by:Wyn
ID: 2553292
btw:Changing the name is useful to use .def to export it without declspe..(..)
0
 

Author Comment

by:GregoryGr
ID: 2554116
done...and thanks again.  I love you guys ;>)
0
 
LVL 5

Expert Comment

by:Wyn
ID: 2554725
Honored;)

W.Yinan
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question