Solved

Export DLL functions- Link error

Posted on 2000-02-23
12
871 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

821 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