Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't find dll entry point

Status
Not open for further replies.

sahr

Programmer
Sep 21, 2000
3
US
I have a dll written with c++ which was written by another programmer. So I know very little about the dll other than the functions that I want to call. I can bring it up in visual c++ but since I'm not real familiar with c++ I don't understand it all. In any case I am trying to call the dll functions from a vb app and am getting errors.

In the dll's (Test.dll) .h file I have

#define EXPORT extern __declspec(dllexport) __stdcall
BOOL EXPORT Init(int Port1, int Port2);

In the dll's .cpp file I have something like

BOOL EXPORT Init(int Port1, int Port2)
{ <<code here>>
}

In Visual Basic I have the declaration
Public Declare Function Init Lib &quot;Test&quot; _
(ByVal port1 As Integer, port2 As Integer) As String

And I call the function with
blnRetVal = Init(1, 2)

Everything compiles fine but when I run it I get the following error.

&quot;Can't find DLL entry point Init in Test&quot;

I would appreciate any ideas anyone might have. Thanks
 
One starting point might be to use Dependency Walker (Start-Programs-Microsoft Visual C++ 6.0-Microsoft Visual C++ 6.0 Tools-Depends). It will let you know (in the middle pane on the right hand side) what functions have been exported from your DLL.

It could be that your &quot;Init&quot; function has been exported, but that the compiler has played name-mangling games with it (that is, added lots of characters to the name). If that is the case, you might want to try enclosing your declaration inside an extern &quot;C&quot; block, as follows:

extern &quot;C&quot;
{
BOOL EXPORT Init(int Port1, int Port2);
}

If that doesn't work, I'd try the following:
1. In the h file, remove the extern keyword from the EXPORT definition:
#define EXPORT __declspec(dllexport) __stdcall
BOOL EXPORT Init(int Port1, int Port2);

2. In the CPP file, remove EXPORT:
BOOL Init(int Port1, int Port2)
{
<<code here>>
}
 
Looked at the dll using the dependancy walker and sure enough it had tons of weird characters with the function names. Tried both of your suggestions but was unable to get rid of the weird stuff. I ended up changing my #define to

#define EXPORT extern &quot;C&quot; __declspec(dllexport)

Now the functions look right in the dependancy walker, but when I call them from VB I get:

&quot;Bad DLL Calling Convention&quot;
 
Once again I am guessing, but I think that if you don't specify a calling convention, cdecl will be used by default. That appears to be bad news for VB; please see the following Microsoft article:


So you might need to put __stdcall back in.

You might need to copy and paste that link into your browser; when I preview this post it seems to think that the stuff after the semicolon is not part of the link, when it really is.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top