Solved

Export DLL functions- Link error

Posted on 2000-02-23
12
857 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 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