MIDL and juce_Initialisation.h interaction

Hi Jules,

It seems that when a VS2012 project uses the MIDL compiler, because there is an .idl file ( you know, to define COM classes and interfaces), the prototype of WinMain that the compiler expects is:

int __stdcall WinMain (HINSTANCE, HINSTANCE, const LPSTR, int)

instead of:

int __stdcall WinMain (void*, void*, const char*, int)

I got this conclusion because the VS2012 c++ compiler complains showing C2733 (second C linkage of overloaded function ‘function’ not allowed) and C2731 (The function WinMain cannot be overloaded.) errors.

I was diving into juce_Initialisation.h and I discovered that in the #IF DEFINE nest:

#if JUCE_WINDOWS #if defined (WINAPI) || defined (_WINDOWS_) #define JUCE_MAIN_FUNCTION int __stdcall WinMain (HINSTANCE, HINSTANCE, const LPSTR, int) #elif defined (_UNICODE) #define JUCE_MAIN_FUNCTION int __stdcall WinMain (void*, void*, const wchar_t*, int) #else #define JUCE_MAIN_FUNCTION int __stdcall WinMain (void*, void*, const char*, int) #endif #define JUCE_MAIN_FUNCTION_ARGS #else #define JUCE_MAIN_FUNCTION int main (int argc, char* argv[]) #define JUCE_MAIN_FUNCTION_ARGS argc, (const char**) argv #endif

reachs that WINAPI or WINDOWS is not defined. So JUCE_MAIN_FUNCTION is defined as int __stdcall WinMain (void*, void*, const char*, int) what the compiler not expect.

I’ve solved it temporally bypassing all the #if segment code and hardcoding the WinMain that the compiler expects: int __stdcall WinMain (HINSTANCE, HINSTANCE, const LPSTR, int)
But I think you can fix it to be compatible with the #IF DEFINE code

Gabriel

You could work around this without any hacks by just defining WINAPI in your AppConfig.h, right?

Otherwise, if your build doesn’t have either WINDOWS or WINAPI defined (which seems a bit odd…) then I’d need to know what it does have defined in order to extend that #if statement.

Jules,

I’ve solved it. In main.cpp, I swapped these lines generated by introjucer:

#include "MainComponent.h" #include "../JuceLibraryCode/JuceHeader.h"

Then, WINAPI is declared before juce_Initialisation.h uses it.

Does it make sense to you?

No, that’s not a very good idea. If you need to include windows.h, then you should do it before JuceHeader.h, but you should still include JuceHeader.h before your MainComponent.h.

All right! Definitely agree.
Thank you, Jules.