编译出支持UNICODE的程序

环境: Visual Studio 2010

 

有三种方法:
1. 在命令行模式下加入编译参数:
/D  Defines constants and macros.
参考: http://msdn.microsoft.com/en-us/library/hhzbb5c8.aspx?appId=Dev10IDEF1&l=EN-US&k=k(MSDNSTART)&rd=true

 

cl /D_UNICODE /DUNICODE /LD DemoCryptQueryObjectCPP.cpp

 

2. 在 VS 的 Project 菜单中的 ...Property 中进行设置:
Configuration Properties -> General -> Project Defaults -> Character Set 设置为 Use Unicode Character Set.
然后在 VS 中编译。
查看方法:
Configuration Properties -> C/C++ -> Command Line 中可以查看编译参数:
例如:
/ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /GS

/fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\digital_signature.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze-

/errorReport:queue

3. 在 CPP 源代码中定义宏:
一定要在导入所有头文件之前定义UNICODE, _UNICODE 这两个宏。

 

#define UNICODE
#define _UNICODE

#include <windows.h>
#include <wincrypt.h>
#include <wintrust.h>
#include <stdio.h>
#include <tchar.h>
 

 

你可能感兴趣的:(C++,c,windows,Microsoft,FP)