# MIDL and juce\_Initialisation.h interaction

**URL:** <https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961>\
**Category:** Windows\
**Created:** [August 9, 2013, 12:23pm UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961 "2013-08-09T12:23:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leirbag](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leirbag/32/6884_2.png) [@leirbag](https://forum.juce.com/u/leirbag)\
**Post date:** [August 9, 2013, 12:23pm UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961/1 "2013-08-09T12:23:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 9, 2013, 12:35pm UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961/2 "2013-08-09T12:35:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![leirbag](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leirbag/32/6884_2.png) [@leirbag](https://forum.juce.com/u/leirbag)\
**Post date:** [August 9, 2013, 9:40pm UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961/3 "2013-08-09T21:40:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 10, 2013, 8:27am UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961/4 "2013-08-10T08:27:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![leirbag](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/leirbag/32/6884_2.png) [@leirbag](https://forum.juce.com/u/leirbag)\
**Post date:** [August 10, 2013, 2:03pm UTC](https://forum.juce.com/t/midl-and-juce-initialisation-h-interaction/10961/5 "2013-08-10T14:03:38Z")

</div>

All right! Definitely agree.  
Thank you, Jules.
