简 述: Windows
编程中常见的一些类型意义、区别和讲解定义
- PVOID 和 LPVOID
- LPSTR / LPCSTR / LPTSTR / LPCTSTR / LPWSTR / LPCWSTR
- HWND / HANDLE / HMODULE / HINSTANCE
辨别区分标志
- L --> long;WIN32 下 long 和 int 长度一样。 故 L 和 LP 无区别。
- C --> const
- T --> 通用版本,依据 UNICODE 时候被定义,确定使用 A 还是 W 版本的函数、或字符集。
- STR --> string 字符串
- PTR --> ptr 指针
本文初发于 “偕臧的小站”,同步转载于此。
Windows Data Types
typedef void *PVOID; // PVOID - void *
typedef void *LPVOID; // LPVOID - void *
typedef CHAR *LPSTR; // LPSTR - ANSI, 每个字符占 1 字节(8 bit)
typedef __nullterminated CONST CHAR *LPCSTR; // LPCSTR - ANSI, 每个字符占 1 字节
typedef WCHAR *LPWSTR; // LPWSTR - UNICODE, 每个字符占 2 字节(16 bit)
typedef CONST WCHAR *LPCWSTR; // LPCWSTR - UNICODE, 每个字符占 2 字节
typedef LPWSTR LPTSTR; [OR] typedef LPSTR LPTSTR; // LPTSTR - ANSI/UNICODE, 每个字符占 1 字节或 2 字节
typedef LPCWSTR LPCTSTR; [OR] typedef LPCSTR LPCTSTR; // LPCTSTR - ANSI/UNICODE, 每个字符占 1 字节或 2 字节
typedef PVOID HANDLE; // HANDLE - void *
typedef HANDLE HWND; // HWND - void *
typedef HINSTANCE HMODULE; // HMODULE - void * 此两个互相等价, 于 <wtypes.h>
typedef HANDLE HINSTANCE; // HINSTANCE - void *
Data type | Description | declared |
---|---|---|
PVOID | A pointer to any type. | WinNT.h |
LPVOID | A pointer to any type. | WinDef.h |
LPSTR | A pointer to a null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts | WinNT.h |
LPCSTR | A pointer to a constant null-terminated string of 8-bit Windows (ANSI) characters. For more information, see Character Sets Used By Fonts | WinNT.h |
LPWSTR | A pointer to a null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts | WinNT.h |
LPCWSTR | A pointer to a constant null-terminated string of 16-bit Unicode characters. For more information, see Character Sets Used By Fonts | WinNT.h |
LPTSTR | An LPWSTR if UNICODE is defined, an LPSTR otherwise. For more information, see Windows Data Types for Strings | WinNT.h |
LPCTSTR | An LPCWSTR if UNICODE is defined, an LPCSTR otherwise. For more information, see Windows Data Types for Strings | WinNT.h |
HWND | A handle to a window. | WinDef.h |
HANDLE | A handle to an object. | WinNT.h |
HMODULE | A handle to a module. The is the base address of the module in memory. HMODULE and HINSTANCE are the same in current versions of Windows, but represented different things in 16-bit Windows. | WinDef.h |
HINSTANCE | A handle to an instance. This is the base address of the module in memory. | WinDef.h |
含义
-
PVOID 和 LPVOID
- 都是
void *
, 可指向一切,不解释。
- 都是
-
LPSTR / LPCSTR / LPTSTR / LPCTSTR / LPWSTR / LPCWSTR
- LPSTR: 32bit 指针,指向一个字符串,每个字符占 1 字节。 相当于 char *
- LPCSTR: 32-bit 指针,指向一个常字符串,每个字符占 1 字节。 相当于 const char *
- LPWSTR: 32-bit 指针,指向一个 unicode 字符串的指针,每个字符占 2 字节。
- LPCWSTR: 32-bit 指针,指向一个 unicode 字符串常量的指针,每个字符占 2 字节。
- LPTSTR: 32-bit 指针,指向一个字符串, 每字符可能占 1 字节或 2 字节,取决于 Unicode 是否定义
- LPCTSTR: 32-bit 指针,指向一个常字符串,每字符可能占 1 字节或 2 字节,取决于 Unicode 是否定义
-
HWND / HANDLE / HMODULE / HINSTANCE
都是
void *
类型,没有区别,只是其使用时候代表的含义用作区分- HWND:窗口句柄,如线程相关的
- HANDLE :系统内核对象,如文件句柄,线程句柄,进程句柄
- HMODULE :模块基地址,如 exe、dll 被载入内存时刻的地址
- HINSTANCE:同 HMODULE(仅在 16 位 Windows 上有所不同)