4

usually i use visual studio, but i switched to mingw, i like to make my apps easily changeable from unicode and multi byte, in my mingw project i have my defines and includes like this:

#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0700
#define _UNICODE

#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>

#define WND_MAIN_CLASS  _T("MainWindowFrame")

then i register and create my window e.g.

 WNDCLASSEX wc;
...
wc.lpszClassName = WND_MAIN_CLASS;

RegisterClassEx(&wc);

    hwnd = CreateWindowEx(0, WND_MAIN_CLASS, _T("Main Window"),
  WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInst, NULL);

but when i go to compile i get errors that it cannot convert wchar_t to CHAR* on the WNDCLASSEX lpszClassName and the CreateWindowEx on the Class name and window title.

if i right click and go to declaration of createwindowex and WNDCLASSEX, it comes up with these from winuser.h:

    typedef WNDCLASSEXW WNDCLASSEX,*LPWNDCLASSEX,*PWNDCLASSEX;

#define CreateWindowEx CreateWindowExW

if i comment out the define _UNICODE it compiles and works with no problems

Kaije
  • 2,631
  • 6
  • 38
  • 40
  • 3
    what's with that WINVER? I didn't know there was a Windows version 7. – David Heffernan Jan 11 '11 at 19:02
  • lol, i thought that meant windows 7, oh well.. atleast everything should be included now its that high... what is the WINVER for windows 7? i thoguht vista was 0x0600 and xp 0x0500 – Kaije Jan 11 '11 at 20:26
  • 3
    @user394242: 2000 was 5.0, XP=5.1, 2003=5.2, Vista=6.0 and 7=6.1 (2008 is the same as VistaSP1: 6.0.6001 while VistaRTM's build number is 6000, this was the first time a service pack changed the OS version AFAIK) – Anders Jan 11 '11 at 21:16
  • 1
    If you want to use Unicode with MinGW, you will either need a wrapper or the `-municode` option. For details, see: http://stackoverflow.com/questions/3571250/wwinmain-unicode-and-mingw/11706847#11706847. – XP1 Jul 29 '12 at 08:33

1 Answers1

9

When compiling unicode apps you should probably define both UNICODE and _UNICODE. The windows headers use UNICODE and the MS C runtime uses _UNICODE

Anders
  • 97,548
  • 12
  • 110
  • 164
  • 6
    And if you want to easily change between ANSI and Unicode, specify them in build options instead of defining them in the source. – Cat Plus Plus Jan 11 '11 at 19:03