Latest Tip; WinMain Error


#1

Hi Jules,

Just got the latest tip, and now my project throws a compile error saying ‘WinMain’ : function cannot be overloaded

In case you’re wondering, I’m of course including Windows.h before the JuceHeader.h since I’ve not run into this issue until today.


#2

For what it’s worth, the last time I pulled the latest tip was last Friday, and I didn’t have issues then.


#3

This sounds to me like a mismatch between the Unicode declaration of WinMain using wide strings versus the ANSI declaration.


#4

The issue was created/started at this commit:


#5

https://github.com/julianstorer/JUCE/commit/18cfadf898aa1678dc6b092d4dd314ed082d567f

I think the issue lies within changes (aka Removals) to this file specifically: modules/juce_gui_basics/application/juce_Initialisation.h


#6

New

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

Old

int WINAPI WinMain (HINSTANCE, HINSTANCE, LPSTR, int)

#7

Ah, I couldn’t remember why I had two different versions of that code hanging around, so cleaned it up. I guess the reason the old code was there is because otherwise it breaks if you’ve already included windows.h. Thanks, I’ll sort that out…


#8

As it is written, it would seem the declaration of WinMain might break, since it is hard-coded to use a non-unicode string. To declare WinMain correctly for all values of the UNICODE project setting I think you want to use LPTSTR instead of LPSTR.


#9

Thanks Jules.

I must say that I’m confused about the differences between what you have there, and LPSTR and HINSTANCE… I totally thought those were char* and void* respectively…? Or is there some hidden unicode bs flag that affects this stuff?


#10

…And you’ve just answered my question as I submitted my post, TheVinn. :smiley:


#11

I’m using currently the commit tagged with 2.0.27.
This version does not work with unicode and Windows.h included. When I change the WinMain definition from

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

to

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

it works again.


#12

Ah, right… yes, it does look like it should just be an LPSTR, thanks!


#13

Hi all,

I am running also into this issue, with the latest version of Juce (pulled today). Made a simple GUI app with the Introducer.

Is there something that I should explicitly set in the Introducer or in my VC++ 2010 project?

TIA.

Peter


#14

Are you including Windows.h? If so, are you doing so before including JuceHeader.h?


#15

Yep, thanks - I went through the other topics on this and got it fixed. Great framework, but steep learning curve :-)