Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

#define _UNICODE not working with MinGW + CodeBlocks

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

like image 571
Kaije Avatar asked Jan 21 '23 18:01

Kaije


1 Answers

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

like image 73
Anders Avatar answered Jan 31 '23 00:01

Anders