Link to home
Start Free TrialLog in
Avatar of GregoryGr
GregoryGr

asked on

Cant find DLL reference point

I used C++ V6 to compile and link a DLL that includes function calls.  When I try to access functions from this DLL, I get the run-time error "Can't find DLL entry point ClfyConnect in notes2clarifydll".

I am thinking the problem is with the C++ DLL.

//////////////////////////
Sample calling code (VB6)...
Private Declare Function ClfyConnect Lib "notes2clarifydll" _
    (ByVal sServer As String, ByVal sDatabase As String, _
     ByVal sUsername As String, ByVal sPassword As String) As Long

////////////////////////////////
Sample C++ code generating the DLL...

__declspec(dllexport) long __stdcall ClfyConnect(char *,char *,char *,char *);
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

C++ "decorates" or "mangles" function names by appending a "code" to the end of the name that expresses the parameters passed to the function.  This is used to impliment function overloading, where 2 or more distinct functions have the same name and different parameters.  (Apparently they have the same name--C++ mangles the names so they don't actually have the same name).  

The function is exported with the mangeled name, so you aren't actually specifying the right name in VB.  You can use dumpbin to verify this, you should see the function exported with a mangeled name and that is the name that you woudl have to specify to VB

To fix this problem, you can specify the mangeled name to VB, or--better--declared the function as "extern "C" ".  This dissables name mangeling on the function.

Let me know if you have questions.
One more thing.  This may not be quite sufficient.  There is one other type of name decoration and this doesn't dissable that.  If after using extern "C" you find that the exported name (check with dumpbin) ends with a "@" followed by a number, they this is the standard call decoration.  

To remove this decoration you need to place an entry in the DLL's module defintion file (.def).  The entry should appear in the EXPORTS section and should just contain the name of the function.  for example

// in your .cpp file

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

// in your .def file.
EXPORTS
   ClfyConnect

let me know if you have any questions