PInvoke question (caling conventions of C DLLs)

A

Anonymous

I want to call functions in a Win32 DLL from VB. The DLL in question, is
the Python DLL (python25.dll).

I have noticed something strange. When I declare the functions in VB6
(i.e. VB classic), I get an error : "Bad DLL calling convention" - yet
when I run the same code through VB.Net, the code works fine - my
assumption is that VB.Net can make calls to C functions using either the
__stdcall OR __cdecl, whereas VB6 requires the __stdcall calling convention.

This is just a hunch - does anyone know the technical reason for this
behaviour?
 
A

Armin Zingler

Anonymous said:
I want to call functions in a Win32 DLL from VB. The DLL in
question, is the Python DLL (python25.dll).

I have noticed something strange. When I declare the functions in
VB6 (i.e. VB classic), I get an error : "Bad DLL calling convention"
- yet when I run the same code through VB.Net, the code works fine -
my assumption is that VB.Net can make calls to C functions using
either the __stdcall OR __cdecl, whereas VB6 requires the __stdcall
calling convention.

This is just a hunch - does anyone know the technical reason for
this behaviour?

Probably you didn't change the declaration to fit the language. Integers:

16 bit: VB6=Integer; VB.Net=Short
32 bit: VB6=Long; VB.Net=Integer
64 bit: VB6=not available; VB.Net=Long


Armin
 
T

Tom Shelton

I want to call functions in a Win32 DLL from VB. The DLL in question, is
the Python DLL (python25.dll).

I have noticed something strange. When I declare the functions in VB6
(i.e. VB classic), I get an error : "Bad DLL calling convention" - yet
when I run the same code through VB.Net, the code works fine - my
assumption is that VB.Net can make calls to C functions using either the
__stdcall OR __cdecl, whereas VB6 requires the __stdcall calling convention.

This is just a hunch - does anyone know the technical reason for this
behaviour?

..NET can support __cdecl functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top