Skip to content

Latest commit

 

History

History
110 lines (90 loc) · 6.15 KB

02152023.md

File metadata and controls

110 lines (90 loc) · 6.15 KB
  1. Win32 API acronyms demystification:
  • Handles and Data Types:

    • On 16-bit architectures (16-bit Windows) there are 2 types of pointers, P for pointer and LP stands for long pointer.

    • Long pointers (also called far pointers) were needed to address memory ranges outside of the current segment.

    • The LP prefix has been preserved to make it easier to port 16-bit code to 32-bit Windows.

    • Today there is no distinction, and these pointer types are all equivalent. Avoid using these prefixes; or if you must use one, then use P.

      RECT   *rect;  // Pointer to a RECT structure.
      LPRECT  rect;  // The same
      PRECT   rect;  // Also the same.
      • Pointer precision type: [DWORD_PTR, INT_PTR, LONG_PTR, ULONG_PTR, UINT_PTR].
    • Integer types: #include <stdint.h>

      typedef uint8_t BYTE;
      typedef uint16_t WORD;
      typedef uint32_t DWORD;
      typedef uint64_t QWORD;
      
      typedef long LONG;
      typedef unsigned long ULONG;
      typedef int INT;
      typedef unsigned int UINT;
      typedef short SHORT;
      typedef unsigned short USHORT;
      typedef char CHAR;
      typedef unsigned char UCHAR;
      Data type Size Signed?
      BYTE 8 bits Unsigned
      DWORD 32 bits Unsigned
      INT32 32 bits Signed
      INT64 64 bits Signed
      LONG 32 bits Signed
      LONGLONG 64 bits Signed
      UINT32 32 bits Unsigned
      UINT64 64 bits Unsigned
      ULONG 32 bits Unsigned
      ULONGLONG 64 bits Unsigned
      WORD 16 bits Unsigned
      Data Type Size (in bytes) Range
      char 1 -128 to 127 (signed) or 0 to 255 (unsigned)
      unsigned char 1 0 to 255
      short 2 -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned)
      unsigned short 2 0 to 65,535
      int 4 -2,147,483,648 to 2,147,483,647 (signed) or 0 to 4,294,967,295 (unsigned)
      unsigned int 4 0 to 4,294,967,295
      long 4 or 8 -2,147,483,648 to 2,147,483,647 (signed)
      0 to 4,294,967,295 (unsigned) (for 32-bit systems)
      -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed)
      0 to 18,446,744,073,709,551,615 (unsigned) (for 64-bit systems)
      unsigned long 4 or 8 0 to 4,294,967,295 (for 32-bit systems)
      0 to 18,446,744,073,709,551,615 (for 64-bit systems)
      long long 8 0 to 18,446,744,073,709,551,615
      -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed)
      unsigned long long 8 0 to 18,446,744,073,709,551,615 (unsigned)
      float 4 3.4e-38 to 3.4e+38
      double 8 1.7e-308 to 1.7e+308
      long double 10 or 16 3.4e-4932 to 1.1e+4932
  • Working with Strings:

    Typedef Definition
    CHAR char
    PSTR or LPSTR char *
    PCSTR or LPCSTR const char *
    PWSTR or LPWSTR wchar_t *
    PCWSTR or LPCWSTR const wchar_t *
    Macro Unicode ANSI
    TCHAR wchar_t char
    TEXT("x") or _T("x") L"x" "x"
    typedef wchar_t WCHAR;
    
    // To declare a wide-character literal or a wide-character string literal, put L before the literal.
    wchar_t a = L'a';
    wchar_t *str = L"hello";
    
    #ifdef UNICODE
    #define TCHAR WORD
    #define SetWindowText SetWindowTextW
    #else
    #define TCHAR BYTE
    #define SetWindowText SetWindowTextA
    #endif
  • In Win32 API functions, W, Ex, and A are suffixes that indicate the character set and other variations in the function names. Specifically:

    • W stands for Wide, which indicates that the function uses Unicode character encoding. For example, the function MessageBoxW displays a message box with Unicode text.

    • Ex stands for Extended, which indicates that the function has an extended version with additional parameters. For example, the function CreateWindowExW creates a window with extended style options and uses Unicode character encoding.

    • A stands for Ansi, which indicates that the function uses the legacy ANSI character encoding. For example, the function MessageBoxA displays a message box with ANSI text.

  • In general, it's recommended to use the W versions of the functions whenever possible, as they support a wider range of characters and are more compatible with internationalization and localization. However, the A versions may still be necessary for compatibility with older software or certain system configurations.