Original link: https://ifmet.cn/posts/5020c5e7/
Brief description: Some common types of meanings, differences and explanation definitions in Windows
programming
- PVOID and LPVOID
- LPSTR / LPCSTR / LPTSTR / LPCTSTR / LPWSTR / LPCWSTR
- HWND / HANDLE / HMODULE / HINSTANCE
distinguishing mark
- L –> long; long and int have the same length under WIN32. So there is no difference between L and LP .
- C –> const
- T –> Generic version, defined according to UNICODE time, determines whether to use the A or W version of the function, or character set.
- STR –> string string
- PTR –> ptr pointer
[TOC]
This article was originally published on ” Xie Zang’s Small Station “, and is reproduced here simultaneously.
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 | AnLPCWSTR 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 |
meaning
-
PVOID and LPVOID
- All are
void *
, can point to everything, do not explain.
- All are
-
LPSTR / LPCSTR / LPTSTR / LPCTSTR / LPWSTR / LPCWSTR
- LPSTR: 32bit pointer, pointing to a string, each character occupies 1 byte. Equivalent to char*
- LPCSTR: 32-bit pointer, pointing to a constant string, each character occupies 1 byte. Equivalent to const char *
- LPWSTR: 32-bit pointer, a pointer to a unicode string, each character occupies 2 bytes.
- LPCWSTR: 32-bit pointer, pointer to a unicode string constant, each character occupies 2 bytes.
- LPTSTR: 32-bit pointer to a string, each character may occupy 1 byte or 2 bytes, depending on whether Unicode is defined or not
- LPCTSTR: 32-bit pointer to a constant string, each character may occupy 1 byte or 2 bytes, depending on whether Unicode is defined or not
-
HWND / HANDLE / HMODULE / HINSTANCE
They are all
void *
types, there is no difference, but the meaning they represent when they are used is used to distinguish- HWND: window handle, such as thread related
- HANDLE: System kernel objects, such as file handles, thread handles, process handles
- HMODULE: module base address, such as the address when exe and dll are loaded into memory
- HINSTANCE: same as HMODULE (only differs on 16-bit Windows)
Reference
- docs.microsoft.com: windows-data-types
- Windows client development – must know the difference between HWND, HANDLE, HMODULE, HINSTANCE
- The meaning and difference of LPSTR, LPCSTR, LPTSTR and LPCTSTR
- The meaning and difference of citing LPSTR, LPCSTR, LPTSTR, LPCTSTR, LPWSTR and LPCWSTR
This article is reprinted from: https://ifmet.cn/posts/5020c5e7/
This site is for inclusion only, and the copyright belongs to the original author.