Jump to content
  • Advertisement
Sign in to follow this  
Greg K

MingW/Microsoft

This topic is 5475 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am using Dev-C for my project but I want to write the editor using MFC. I have a DLL that gets compiled in Dev-C and I want to link it with my MFC app. It links fine but I am having some trouble when I am calling one of my functions. The function gets called but the parameter (in this case a window handle) changes from a valid handle to a 1. Does anyone know why this happens? -Greg

Share this post


Link to post
Share on other sites
Advertisement
It seems that all my variables are garbled when they come out on the other side of the dll call (inside the function). Any insight as to the cause of this would be great.
-Greg

Share this post


Link to post
Share on other sites
This is in Visual

MyClass->SetUp(
GetSafeHwnd(),1,rect.right-rect.left,rect.bottom-rect.top,0,
1,0,false,true,false,NULL
);


This is in Dev-C

void CMyClass::SetUp(
HWND hwnd,bool Windowed,dword Width,dword Height,dword MusicBufferSize,
bool EnableTriggerScript,
bool EnableBackgroundMusic,
bool EnableUnitAI,
bool DrawHiddenUnits,
bool DrawInterface,
const char *LoadScreenPath
){
Log.Record("This outputs a 1 %i\r\n", hwnd);

Share this post


Link to post
Share on other sites
Interesting... It seems to be assigning all the parameters "one to the right". So hwnd is lost, Windowed is in hwnd, Width is in Windowed etc... I am stumped.
-Greg

Share this post


Link to post
Share on other sites
The problem is C++ name mangling, you cannot call functions in a dll compiled on MinGW from a VC++ or the other way around if you used C++ unless you defined the functions as extern "C".

In this case you are calling a member function, so not even extern "C" would solve the problem, the shortest solution would be to compile both exe and dll with the same compiler.

Share this post


Link to post
Share on other sites
Quote:
Original post by Greg K
If only that were the shortest solution :(
Okay, thanks for your help.


I feel you there, I am still unable to code MilkShape plugins with MinGW [sad]

Share this post


Link to post
Share on other sites
Quote:
Original post by Greg KIf only that were the shortest solution :(
Or just make it static and pass the class instance as a parameter.
You still need to be carful with calling conventions though. Be sure to specify them at both ends.

In general you'll eighter have to export a C API or fake it with lots of heavy macro abuse (i.e. COM).

Share this post


Link to post
Share on other sites
Quote:
Original post by Greg K
Interesting... It seems to be assigning all the parameters "one to the right". So hwnd is lost, Windowed is in hwnd, Width is in Windowed etc... I am stumped.
-Greg


Hello,

Since everything compiled and linked fine, it cannot be a name manngling problem (name mangling prevent you from linking).

It seems that gcc pushes "this" on the stack (can't verify it, I don't have gcc installed :/) while msvc uses ecx to store the "this" pointer. If this is true then when you exec the CMyClass code you'll get this == hwnd (too bad). It may be easy to check.

Kwizatz's solution is not the shortest: I believe it is the only one. C++ is very compiler dependant :)

HTH,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!