#定义_UNICODE无法与MinGW + CodeBlocks配合使用 [英] #define _UNICODE not working with MinGW + CodeBlocks
问题描述
通常我使用Visual Studio,但是我改用mingw,我想使我的应用程序易于从unicode和多字节更改,在mingw项目中,我有自己的定义,包括:
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);
但是当我去编译时,出现错误,它无法在WNDCLASSEX lpszClassName上将wchar_t转换为CHAR *
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.
如果我右键单击并转到createwindowex和WNDCLASSEX的声明,它来自winuser.h:
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
如果我注释掉它编译的定义_UNICODE并且可以正常工作
if i comment out the define _UNICODE it compiles and works with no problems
推荐答案
编译Unicode应用程序时,您可能应该同时定义 UNICODE
和 _UNICODE
。 Windows标头使用 UNICODE 和MS C运行时使用 _UNICODE
When compiling unicode apps you should probably define both UNICODE
and _UNICODE
. The windows headers use UNICODE and the MS C runtime uses _UNICODE
这篇关于#定义_UNICODE无法与MinGW + CodeBlocks配合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!