What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Need help: __cdecl and __stdcall

Need help: __cdecl and __stdcall
Author: Message:
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
O.P. Huh?  Need help: __cdecl and __stdcall
Ok... I have a DLL written in VC++ that exports a function that uses the __cdecl calling convention and I want to call the function from a VB program. However VB uses the __stdcall calling convention so I can't use the DLL (actually I haven't tested that, but I'm sure I won't be albe to use the DLL).

So the question is: Is there anything I can do to force VB use the __cdecl calling convention? What can I do? Ideas?

I'd prefer not to modify the DLL code, because the DLL will be used by another program too, and it needs to stay as __cdecl. I've thought about making another DLL (in VC++) that exports a __stdcall function that calls the __cdecl one in the original DLL, however I'm not very good in VC++ and don't know how to call an exported function of a DLL :$.

Thanks for your help! :)
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
05-26-2004 08:59 PM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Need help: __cdecl and __stdcall
I believe all the functions in the Win32 API use __cdecl, but VB can still use them.

Typical VB API access declaration:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

'Template':
Private Declare Function <functionname> Lib "<filename>.dll" Alias "<funcnamefromdll>" (<arglist>) As <returntype>

EDIT: Tell you what, you post the function header from your DLL, and I'll see if I can come up with a VB declaration statement to allow you to use it.

This post was edited on 05-28-2004 at 12:02 PM by RaceProUK.
[Image: spartaafk.png]
05-28-2004 12:01 PM
Profile PM Web Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
O.P. RE: Need help: __cdecl and __stdcall
quote:
Originally posted by raceprouk
I believe all the functions in the Win32 API use __cdecl, but VB can still use them
No, the Windows API use __stdcall, that's why VB can use them.
quote:
Originally posted by raceprouk
Typical VB API access declaration:
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long

'Template':
Private Declare Function <functionname> Lib "<filename>.dll" Alias "<funcnamefromdll>" (<arglist>) As <returntype>
yes, I know :P  I have several years of experience in calling APIs from VB ;)
quote:
Originally posted by raceprouk
EDIT: Tell you what, you post the function header from your DLL, and I'll see if I can come up with a VB declaration statement to allow you to use it.
the problem is not that i don't know who to declare it in VB... anyway, if you're happier with this :P :

the VC++ DLL (traductor.dll) exports this function:
code:
int __cdecl TRADUCIR(const char *p_fichero_iso,const char *p_fichero_mac,const char *p_fichero_mec)

in VB i have this declaration:
code:
Public Declare Function TRADUCIR Lib "traductor.dll" (ByVal iso As Long, ByVal mac As Long, ByVal mec As Long) As Long

and when I try to call it from VB it says wrong call convention :refuck: (logic)

well, I've solved that doing this (however I'm still interested if vb can call __cdelc functions or how would be done if I couldn't modify the dll code) :
in VC++, add and export this function
code:
int __stdcall TRADUCIR__stdcall(const char *p_fichero_iso,const char *p_fichero_mac,const char *p_fichero_mec) {
    return TRADUCIR(p_fichero_iso,p_fichero_mac,p_fichero_mec);
}

and in VB change the declaration by this one:
code:
Public Declare Function TRADUCIR Lib "traductor.dll" Alias "TRADUCIR__stdcall" (ByVal iso As Long, ByVal mac As Long, ByVal mec As Long) As Long
:)
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
05-28-2004 02:15 PM
Profile PM Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Need help: __cdecl and __stdcall
I've really got to start reading up on stuff before answering questions...
[Image: spartaafk.png]
05-28-2004 03:10 PM
Profile PM Web Find Quote Report
Mnjul
forum super mod
******

Avatar
plz wub me

Posts: 5396
Reputation: 58
– / Other / Flag
Joined: Nov 2002
Status: Away
RE: Need help: __cdecl and __stdcall
Well Choli, it seems that you haven't searched whole MSDN and Microsoft KB...:P (OK, I'm joking :P)

Would this work? :)
code:
Public Declare Function TRADUCIR CDecl Lib "traductor.dll" (ByVal iso As Long, ByVal mac As Long, ByVal mec As Long) As Long

05-28-2004 05:09 PM
Profile PM Web Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
43 / Male / Flag
Joined: Jan 2003
O.P. RE: Need help: __cdecl and __stdcall
quote:
Originally posted by Mnjul
Well Choli, it seems that you haven't searched whole MSDN and Microsoft KB...
lol, :p can you give me the link where you found that, please?
quote:
Originally posted by Mnjul
Would this work?
yes and no, dodgy things are happening here... err... I mean:

When in VB (btw, VB 6, not .net) I put the CDecl keywork, VB recognices it (yay! :banana:) but I've found this things: I call the function in the DLL and when I put the CDelc, VB says wrong calling convention and if i remove CDecl it works. That was a quick test, so I said, I'll repeat later. Now, I've exported 2 functions, one with __cdecl and the other with __stdcall. If un VB I use the CDecl I can't call the function with __stdcall but I can call it if don't use CDecl ((Y)), but I can't call the __cdecl using nor not using CDecl :'(

Also, if in VC++ I export a function without saying __cdecl nor __stdcall, I can't call it from VB either (the default setting at the VC++ proyect is __cdecl).

So I'm starting to be paranoid :P Once the DLL is built, how can I know the calling convention of an exported function (with the dependency walker I can see the exported functions, but not their calling convention).

I'm using VC++ .NET 2002, if that helps :-/

I'm sure I'm doing something wrong but it seems I missed it :rolleyes:

Well, thanks a lot for your help... After seeing how VB compiles the code with the CDecl keyword I'm sure that doing that is possible... Definetely I have to do more tests :P
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
05-28-2004 11:58 PM
Profile PM Find Quote Report
Jnrz7
Full Member
***

Demon Lover

Posts: 115
– / Male / –
Joined: Dec 2002
RE: Need help: __cdecl and __stdcall
Choli,

VB6 hasta donde se, solo puede usar una DLL que usen la convension STDCALL.
La unica forma que encuentro es que cambies la funcion de CDECL a STDCALL para que pueda ser usada por un programa de VB6.
Cuando lo quieras llamar a la DLL desde otro programa tienes que asigname STDCALL tambien porque si no leera pura basura la DLL.
te escribo en castellano porque mi ingles es malo :p
chao
+The cuts were beautiful until they began to heal.
05-29-2004 01:02 AM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: Need help: __cdecl and __stdcall
And in English?
[Image: spartaafk.png]
05-29-2004 10:01 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On