Win32 function prototype

zhaozj2021-02-16  83

The Win32 function prototype is divided into three kinds of ordinary, ANSI and Unicode. In fact, if it is strictly, it is not ordinary, which is only two kinds of ANSI and Unicode. Ordinary, generally given the form directly in the MSDN development document. For example, the following is a normal prototype of SetWindowText:

Bool SetwindowText (HWND HWND, LPCTSTSTER LPTEXT);

In fact, the header file containing the setWindowText function declaration is implemented by macro:

#ifdef unicode

#define setWindowText setWindowTextw

#ELSE

#define setWindowText setWindowTexta

#ndif //! Unicode

The preprocessor will replace the macro according to whether it defines the unicode, the replacement function is not the ANSI version is the Unicode version. Function

"A" represents "ANSI", and "W" represents "WIDE". There are also two different versions of function prototype declarations in header files:

ANSI prototype:

Bool WinAPI SetwindowTexta (HWND HWND, LPCSTR LPSTRING);

Unicode prototype:

Bool WinAPI SetWindowTextw (HWND HWND, LPCWSTR LPSTRING);

Below is a declaration and macro definition of the setWindowText function in WinUser.h header:

WinuseraPi

Bool

WinAPI

SetwindowTexta

HWND HWND,

LPCSTR LPSTRING);

WinuseraPi

Bool

WinAPI

SetwindowTextw

HWND HWND,

LPCWSTR LPSTRING);

#ifdef unicode

#define setWindowText setWindowTextw

#ELSE

#define setWindowText setWindowTexta

#ndif //! Unicode

Note that when using a string parameter, the ordinary prototype is LPCTSTR. The ANSI prototype is used by LPCSTR, and the Unicode prototype is used.

LPCWSTR.

We usually use ordinary prototypes in our own procedure, define Unicode when needed, and will use the Unicode version of the function. If Unicode is not defined, the ANSI version of the function is used by default. Of course, we can also use the ANSI version or Unicode version directly, the specific method is to add "A" or "W" in the ordinary prototype, but I don't advocate this because it is easy to confuse .

This method is usually applied in a function using a string parameter, in general, in a normal manner. What is normal way? Normal people are all normal ways, are you normal? Ha ha. Since the use of Unicode in VB, it must be noted when used in VB, and I want to be familiar with VB. This is clear. Both the string parameters in the function ended in "W" use Wide-Character, ie, one English character or a Chinese character you see with 2 bytes, while some functions are only Unicode versions.

There is a QuickInfo in the MSDN Development Document with a QuickInfo, and the function will indicate whether the function contains the ANSI version and Unicode version.

* ------------------------------------------- *

* Please inform the author and indicate the source, 9CBS welcomes you! *

* Author: Lu Peipei (goodname008) ** E-mail: goodname008@163.com *

* Column: http://blog.9cbs.net/goodname008 *

* ------------------------------------------- *

转载请注明原文地址:https://www.9cbs.com/read-16422.html

New Post(0)