的WinMain() [英] WinMain()

查看:90
本文介绍了的WinMain()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们。我正在尝试学习一些Windows编程,但是我在代码中遇到了一些错误:


展开 | 选择 | Wrap | 行号

解决方案

在代码中的字符串之前使用L literal时,编译器会理解您是否愿意创建Unicode字符串(wchar_t *)而不是ANSI字符串(char *) )。
函数MessageBox,在这种情况下,在windows头文件中秘密定义为MessageBoxA,必须接收ANSI字符串作为参数,而不是Unicode st戒指。这就是编译器抱怨的原因。

如果你想要你的代码编译要么删除L文字以使用ANSI字符串或告诉编译器你正在使用
创建一个Unicode Win32应用程序

#define UNICODE 1

包括windows.h标题之前。


定义这样的预处理变量时,windows标题将秘密地将MessageBox函数定义为MessageBoxW,这样的函数接收Unicode字符串作为参数。



#define UNICODE 1

包括windows.h标头之前。



你不应该这样做。要取消定义它,您必须更改代码。相反,您的项目有一个字符集属性设置。将该属性设置为正确的值。


定义此类预处理变量时,windows标头将秘密定义函数MessageBox为MessageBoxW,此类函数接收Unicode字符串作为参数。



没有秘密定义。 MessageBox是一个宏。根据字符集,宏解析为MessageBoxA或MessageBoxW。使用文字前面的L的代码不能与MessageBoxA一起使用。此外,L指定了一个字符串wchar_t,这些字符不是 Unicode字符,除非它们包含Unicode值。


Microsoft提供了一系列名为TCHAR的映射你应该使用的映射。这些宏在ASCII和Unicode之间正确切换而无需更改代码。


您#include< tchar.h>


消息bis代码应该是:

展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号


我知道它不是一个秘密定义,只是想保持解释清楚而不去进入宏声明细节。


Hey guys. I''m trying to learn some windows programming, but i''m getting some errors with the code:


Expand|Select|Wrap|Line Numbers

解决方案

When you use the L literal before a string in your code, the compiler understands you are willing to create an Unicode string (wchar_t *) rather than an ANSI string (char *).

The function MessageBox, which is secretly defined as MessageBoxA inside the windows headers in this case, must receive ANSI strings as parameters, not Unicode strings. Thats why the compiler complains.

If you want your code to compile either remove the L literals to use ANSI strings or tell the compiler you are creating an Unicode Win32 application using

#define UNICODE 1
before including the windows.h header.

When defining such preprocessing variable, the windows header will secretly define the function MessageBox as MessageBoxW, such function receive Unicode strings as parameters.


#define UNICODE 1
before including the windows.h header.

You should not do this. To undefine it, you have to change your code. Instead there is a character set property setting for your project. Set that propertry to the correct value.

When defining such preprocessing variable, the windows header will secretly define the function MessageBox as MessageBoxW, such function receive Unicode strings as parameters.

There is no secret definition. MessageBox is a macro. Based on the character set, the macro resolves to MessageBoxA or MessageBoxW. Your code with the L in front of the literal will not work with MessageBoxA. Further, the L specifes a string of wchar_t and these characters are not Unicode characters unless they contain Unicode values.

Microsoft provides a series of mappings called the TCHAR mappings that you should be using. These macros correctly switch between ASCII and Unicode without your having to change your code.

You #include <tchar.h>

The message bis code should be:

Expand|Select|Wrap|Line Numbers


I know its not a secret definition, just wanted to keep the explanation clear without going into the macro declaration details.


这篇关于的WinMain()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆