Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C++ Libraries / November 2003

Tip: Looking for answers? Try searching our database.

Calling VC++.NET DLLEXPORT Function in VB6 (Error 453: Can't find DLL entry point xx in yy.dll)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe Hoggood - 17 Nov 2003 21:24 GMT
I am trying to call a VC++.NET exported function (Win32 DLL) in VB6. When I
try to call this exported function from VB6 I get the following error: Error
453: Can't find DLL entry point xx in yy.dll

VC++.NET cpp/h source:

// Win32DLL.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

#include "Win32DLL.h"

BOOL APIENTRY DllMain(

HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)

{

switch (ul_reason_for_call)

{

case DLL_PROCESS_ATTACH:

case DLL_THREAD_ATTACH:

case DLL_THREAD_DETACH:

case DLL_PROCESS_DETACH:

break;

}

return TRUE;

}

// This is an example of an exported variable

WIN32DLL_API public int nWin32DLL = 0;

// This is an example of an exported function.

WIN32DLL_API public int fnWin32DLL(int varIn)

{

int varOut;

varOut = varIn;

return varOut;

}

// This is the constructor of a class that has been exported. See Win32DLL.h
for the class definition

CWin32DLL::CWin32DLL()

{

return;

}

#ifdef WIN32DLL_EXPORTS

#define WIN32DLL_API __declspec(dllexport)

#else

#define WIN32DLL_API __declspec(dllimport)

#endif

// This class is exported from the Win32DLL.dll

class WIN32DLL_API CWin32DLL

{

public:

CWin32DLL(void);

// TODO: add your methods here.

};

extern WIN32DLL_API int nWin32DLL;

WIN32DLL_API int fnWin32DLL(int varIn);

Here's my VB6 tester code:

'Set up global declarations and declare functions.
Declare Function fnWin32DLL Lib
"C:\jhoggood\Applications\CommonC\BuildFiles\Win32DLL\Debug\Win32DLL.dll"
(ByVal varIn As Integer) As Integer

Public Function DoExternFunc(myInputVarA As Integer) As Integer
   ' Call external function
   DoExternFunc = fnWin32DLL(myInputVarA)
   Debug.Print myResult
End Function

Private Sub cmdCompute_Click()
   Dim x As Integer
   x = DoExternFunc(4)
   txtInputVarA.Text = x
End Sub
Ronald Laeremans [MSFT] - 17 Nov 2003 21:37 GMT
Make sure this is in an extern "C" block.

Have you looked at the DLL exports using dumpbin or depends or some other
tool?

Ronald Laeremans
Visual C++ team

> I am trying to call a VC++.NET exported function (Win32 DLL) in VB6. When I
> try to call this exported function from VB6 I get the following error: Error
[quoted text clipped - 114 lines]
>     txtInputVarA.Text = x
> End Sub
Joe Hoggood - 17 Nov 2003 21:48 GMT
Yes, I have looked using Dependency Walker V2.1 and the exported function
"fnWin32DLL" is there. What should my extern declarations look like in the
h/cpp files?

Thanks!

> Make sure this is in an extern "C" block.
>
[quoted text clipped - 111 lines]
> > 'Set up global declarations and declare functions.
> > Declare Function fnWin32DLL Lib

"C:\jhoggood\Applications\CommonC\BuildFiles\Win32DLL\Debug\Win32DLL.dll"
> > (ByVal varIn As Integer) As Integer
> >
[quoted text clipped - 9 lines]
> >     txtInputVarA.Text = x
> > End Sub
Joe Hoggood - 18 Nov 2003 19:10 GMT
Turns out this is a VB6 bug where you must run the application from an EXE
(File/Make EXE) otherwise you will get the following error:

Run-time error: '49' Bad DLL calling convention

> Yes, I have looked using Dependency Walker V2.1 and the exported function
> "fnWin32DLL" is there. What should my extern declarations look like in the
[quoted text clipped - 133 lines]
> > >     txtInputVarA.Text = x
> > > End Sub
Ronald Laeremans [MSFT] - 18 Nov 2003 19:44 GMT
Thanks for the follow-up.

Ronald

> Turns out this is a VB6 bug where you must run the application from an EXE
> (File/Make EXE) otherwise you will get the following error:
[quoted text clipped - 124 lines]
> > > > 'Set up global declarations and declare functions.
> > > > Declare Function fnWin32DLL Lib

"C:\jhoggood\Applications\CommonC\BuildFiles\Win32DLL\Debug\Win32DLL.dll"
> > > > (ByVal varIn As Integer) As Integer
> > > >
[quoted text clipped - 9 lines]
> > > >     txtInputVarA.Text = x
> > > > End Sub
Mattias Sj?gren - 18 Nov 2003 21:40 GMT
Joe,

>Turns out this is a VB6 bug where you must run the application from an EXE
>(File/Make EXE) otherwise you will get the following error:
>
>Run-time error: '49' Bad DLL calling convention

This is not a bug, it's just a limitation in VB6. It only supports the
stdcall calling convention, so you must use that for your exported
functions if you want to call them from VB.

The reason you only see the runtime error in the IDE is that the
checks that have to be done to dicover the calling convention mismatch
are not performed in a compiled executable for performance reasons. It
does not mean that you can ignore the error you get.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.