Solved

Export DLL functions- Link error

Posted on 2000-02-23
12
833 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
  • 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
 

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now