尽管项目为多字节,但在VS2010中定义了UNICODE的问题 [英] Issue with UNICODE being defined in VS2010 despite a project being multibyte
问题描述
我最近在编译以32位模式工作的项目时,VS2010遇到了一个奇怪的问题.我收到许多相同形式的错误:
I've recently run into a strange issue with VS2010 while compiling the project I work on in 32-bit mode. I get many errors of the same general form:
6>c:\opticks\future\opticks-1288\future\code\application\pluginutilities\systemservicesimp.cpp(101): error C2440: 'initializing' : cannot convert from 'const char *' to 'PCTSTR'
6> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
此特定错误对应于以下代码块:
This particular error corresponds to this block of code:
PCTSTR aInsertions[] = {message.c_str()};
其中消息只是一个std :: string
Where message is just a std::string
调查进一步指出,这与项目中的Unicode/多字节设置有关.从 这个主题,我发现在项目中使用Unicode时,PCTSTR必须是wchar_t *而不是char *.但是,我正在构建的项目在其项目设置中设置为使用多字节字符.但同时,当我翻阅 似乎仍在定义UNICODE的源,导致WinNT.h将def PCTSTR键入wchar_t.我还没有找到一种明确的方法来告诉项目未定义UNICODE的方法.我只能通过在WinNT.h中将鼠标悬停在上面来定义它 并看到出现#define UNICODE 1,但在任何实际代码,项目设置等中都找不到该符号.
Investigating further pointed to this being some problem with the Unicode/multi-byte settings in the project. From this topic, I found that, when using Unicode in a project, a PCTSTR has to be a wchar_t* and not a char*. However, the project I am building is set to use multibyte characters in its project setting. At the same time, though, when I looked through the source it appears that UNICODE is still being defined, causing WinNT.h to typedef PCTSTR to wchar_t. I haven't seen a way to explicitly tell the project to not define UNICODE. I can only tell it's being defined by hovering over it in WinNT.h and seeing #define UNICODE 1 appear, but I can't find the symbol in any actual code, project settings, etc.
只有在以32位模式进行编译时才会发生这种情况,而我们团队中的其他人都没有遇到过此问题.我不太确定关于VS2010可能安装或更改的内容.或可能导致此问题出现的Windows,但是我 完全重新安装了VS2010,但我仍然遇到此问题.谁能指出我正确的方向?
This only occurs when compiling in 32-bit mode, and no one else on my team has encountered this problem. I'm not really sure what I may have installed or changed with regard to VS2010 or Windows that may have caused this issue to arise, but I had VS2010 completely reinstalled and I am still running into this problem. Can anyone point me in the right direction?
推荐答案
PCTSTR aInsertions [] = {message.c_str()};
其中消息只是一个std :: string
PCTSTR aInsertions[] = {message.c_str()};
Where message is just a std::string
在那种情况下,您确实应该写出以下任何一个文件:
In that case you really ought to have written either:
PCSTR而不是PCTSTR
PCSTR rather than PCTSTR
或使用类似的类型定义的basic_string< TCHAR>而不是字符串.
or used a similar typedefed basic_string<TCHAR> rather than string.
但是,...
但是,我正在构建的项目在其项目设置中设置为使用多字节字符.
However, the project I am building is set to use multibyte characters in its project setting.
也可以按源文件进行设置.你检查过了吗
仅选择一个源文件时的预处理器符号
在解决方案资源管理器中?
Settings can also be made per-source file. Have you checked the
preprocessor symbols when you have just that one source file selected
in the Solution Explorer?
有2个符号UNICODE和_UNICODE起作用.是
最好只通过项目的字符集"进行设置在
上设置
常规页面-未在预处理器符号中明确显示.
There's are 2 symbols UNICODE and _UNICODE that come into play. It's
best to just set it via the project's "Character Set" setting on the
General page - and not explicitly in the preprocessor symbols.
戴夫
这篇关于尽管项目为多字节,但在VS2010中定义了UNICODE的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!