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
Solved

Export DLL functions- Link error

Posted on 2000-02-23
4
1,626 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

839 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