-
June 3rd, 2005, 06:54 AM
#1
[Solved] GCC, dynamic linking and calling conventions
Hello
I am trying to develop Windows application using DevCpp and GCC compiler v.3.2.4. Application uses mylib.dll library compiled with MSVC 7 and this causes the incompatibility problems. Some functions (almost all) at mylib.dll use __stdcall calling convention, while GCC compiler uses __cdecl by default. This behaviour can be changed globally using -mrtd switch.
Because of problems with linking MSVC dlls to GCC apps, I decided to link mylib.dll dynamically. Using LoadLibrary and GetProc Address I assign address of proc to function pointer, and call it in my program:
Code:
typedef void (*myfunc)(void); //function pointer declaration
....
//this one works
LoadLibrary("mylib.dll");
//this one too
myfunc func1 = (myfunc)GetProcAddress("_func1@0");//strange name, since itd __stdcall one and is not aliased
.......
//some lines later.....
just_a_func(); // <-- function defined in program or other GCC library, __cdecl call by default
func1(); //<--__stdcall imported func
Now whats the question: Is there any way to force GCC compiler to call some functions pointed by pointers using __stdcall, and some others pointed by pointers and defined in program using __cdecl?
I was trying following things:
1. use -mrtd switch: works OK but only as long as my app calls ONLY __stdcall procs. When this option is used, app cannot correctly call functions from other GCC libs, as they use __cdecl.
2. do not use -mrtd switch, and declare function pointer as using __stdcall
Code:
typedef void (*__stdcall myfunc)(void); //doesnt work, function is still called as __cdecl
typedef void (*myfunc)(void) __attribute__((stdcall)); //same as above
Either its not possible to specify calling convention of function pointer, or I am doing something wrong, or GCC ignores calling specifiers in C++ modules.
I found a lot of examples 'How to link GCC app with MSVC dll', and I tried them. Indeed, linker does not complain, but this does not prevent GPFs and stack troubles at runtime.
Thanks for help
Hob
Last edited by Hobson; June 7th, 2005 at 04:48 AM.
B+!
'There is no cat' - A. Einstein
Use [code] [/code] tags!
Did YOU share your photo with us at CG Members photo gallery ?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|