Solved

Export DLL functions- Link error

Posted on 2000-02-23
4
1,620 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
  • 3
4 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 2551592
Declare your C functions as:

extern "C" __declspec(dllexport) long __stdcall Connect(char *,char *,char *,char *);

In your VB program, declare it as:

Private Declare Function Connect Lib "MyDll.Dll" Alias _Connect@16 (ByVal p1 As String, ByVal p2 As String, ByVal p3 As String, ByVal p4 As String) As Long
0
 
LVL 32

Expert Comment

by:jhance
ID: 2551594
Also, forget the DEF file, you don't need it...
0
 

Author Comment

by:GregoryGr
ID: 2551639
That did it...thanks!
0
 
LVL 32

Expert Comment

by:jhance
ID: 2551684
BTW, the only really trick part is:

_Connect@16

The @16 varies depending on the number and type of arguments to the function.  The 16 in this case means 16 bytes are passed in, that's 4 bytes for each char *.  Most things in Windows are 32 bit values so this number is usually just 4 x number of args but there are 8, 16, and even 64 bit types possible.  If in doubt, check the actual exported name with:

DUMPBIN /EXPORTS mydll.dll

DUMPBIN is in the VC++ bin directory.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

786 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