Re: dll won't work with VB6

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Igor Tandetnik wrote:
Dave Cullen <none@xxxxxxxx> wrote:
I have created a DLL using VS8 C++. It works fine when the functions
are called from a C++ application but not from a VB6 app.

Functions in the dll are declared like this:
extern "C" __declspec(dllexport) int DLL_Init(int port1,int port2 =
NULL)
The VB declaration is like this:
Declare Function DLL_Init Lib "MfDfDLL.dll" (ByVal port1 As Long,
ByVal port2 As Long) As Long

The error I get under VB is Runtime error 49, "Bad DLL calling
convention".

VB can only call exported functions that use __stdcall calling
convention.

I thought there was a CDecl keyword you could tag on the Declare Function
line, but __stdcall is definitely the default, and also the convention used
by the entire Win32 API. In fact, typically you'd use the WINAPI macro on
the C prototype.


.



Relevant Pages

  • Re: Unsigned 32 bit
    ... This helper dll has the base adress 0x02400000. ... Its equivalent VB declare is ... Dim MyVar As Long, AdressOfMyVar1 As Long, AdressOfMyVar2 As Long ... Both project internal adresses are inside the jump table VB has build. ...
    (microsoft.public.vb.general.discussion)
  • Re: Unsigned 32 bit
    ... > For this helper dll I wrote a typelib in IDL called ukVBHLB.tlb. ... Its equivalent VB declare is ... > Both project internal adresses are inside the jump table VB has build. ...
    (microsoft.public.vb.general.discussion)
  • Re: Converting VB6 Structures to .NET
    ... This dll was written by a third party ... I will try ByRef. ... I am using a number of "Declare Function" statments to access the functions ... Public Structure zFuheader ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Why doesnt VB6 find yDecLib.dll on second and subsequent runs in IDE?
    ... The first time the app is run in the IDE, ... The dll is in the application folder. ... a full path for the Declare Statement. ...
    (microsoft.public.vb.general.discussion)
  • Re: Exported function mangaled name
    ... that header file; it must be declared as __declspec ... You have to declare the function the same way in your .cpp file as in ... #define LIBSPEC __declspec ... See my essay on The Ultimate DLL Header File on my MVP Tips site. ...
    (microsoft.public.vc.mfc)