博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Building Unicode applications in MFC(转载)
阅读量:6112 次
发布时间:2019-06-21

本文共 2918 字,大约阅读时间需要 9 分钟。

What's The Point?

Windows NT4 and 2K run on . A great many of the net API functions provided by Microsoft® require Unicode and translating strings in and out of Unicode just to push them through these functions is a real pain. Building an application in Unicode not only allows easier access to these functions, but also creates code that runs optimally on NT operating systems.

NOTE - western releases of W9x don't support unicode. All releases of W9x only support a limited set of administrative net API calls which, as well as being ASCII, are often structured differently to their NT equivalents. The help files are fairly useless on leading you through the differences. The best way is to examine the respective header files for the function structures.

Project Settings

The first thing to ensure is that you have included the necessary Unicode libraries when installing your copy of Microsoft Visual Studio®. If you didn't do this when you first installed the tool, it's time to go back and remedy the omission.

Now you can go ahead and get the App Wizard to build you a project. Don't worry about Unicode for the moment, just work your way through the wizard as normal.

Once you've got a basic project up and running, all you need to do to make it build in Unicode is to tweak a couple of project settings. For debug builds, change the preprocessor directive to that shown below:

projsett2.gif

For release builds, change the preprocessor directives to that shown below:

projsett1.gif

If what you see in the preprocessor definitions box is substantially different from what you see above, don't panic. All you are trying to do is replace "_MBCS" with "_UNICODE" at the end of the string.

Finally you need to change the entry point symbol in the linker options:

projsett3.gif

Now the application will build using the Unicode libraries.

But this is only the first step. Now that the application builds in Unicode, you can't go on using the same old ASCII-type functions you always did. A little more refinement is required and here are a few hints on how to do it.

Unicode Programming

First of all, use MFC classes, particularly CStrings, wherever possible. They are overloaded to deal with both ASCII and Unicode.

When using string literals, you need to use the _T( ) macro to get the necessary conversion e.g.

AfxMessageBox(_T("This is a converted Unicode string literal"));

When using printf or the CString.Format() member function, the whole quoted section must be encapsulated by the _T( ) macro:

CString sExample;

sExample.Format(_T("Function failed, error code is %d"), GetLastError());

Don't use char[] types, use TCHAR[] instead (if you can't use a CString).

Below is a brief summary of some standard C++ function calls and their Unicode equivalents.

ASCII Unicode
strlen wcslen
strcpy wcscpy
itoa itow
atoi _wtoi
printf wprintf

And that, as they say, is all there is to it!

转载于:https://www.cnblogs.com/userinterface/archive/2005/05/13/154517.html

你可能感兴趣的文章
【ASP.NET Web API教程】5.4 ASP.NET Web API批处理器
查看>>
带下划线的LABEL控件
查看>>
CentOS上安装软件错误提示:configure: error: no acceptable C compiler found in $PATH
查看>>
【SAS NOTE】MEANS
查看>>
幸福框架:研发团队
查看>>
NSThread 的创建和使用
查看>>
对未登陆的用户进行处理的页面
查看>>
Ext Js简单Data Store创建及使用
查看>>
uva11130
查看>>
warning: name lookup of `i' changed
查看>>
[Hadoop源码详解]之一MapReduce篇之InputFormat
查看>>
js字符串处理
查看>>
如何在真机上调试Android应用程序(图文详解)
查看>>
链表中删除结点的两种方法
查看>>
PX qref latch等待事件
查看>>
ASP.NET 学习笔记_08 控件和母版
查看>>
监测ASP.NET应用程序性能最简单的方法
查看>>
每日英语:Rescuers Struggle to Reach Quake Victims
查看>>
VC++实现非窗口类中使用定时器的方法
查看>>
Activity在屏幕显示的方向切换
查看>>