The MASM Forum

General => The Workshop => Topic started by: sinsi on January 03, 2025, 02:29:55 PM

Title: Defining Windows API functions
Post by: sinsi on January 03, 2025, 02:29:55 PM
Can I assume that the 32-bit declaration _imp__CreateWindowExW@48 is the equivalent of a (made up) 64-bit _imp__CreateWindowExW@96?
i.e 48/sizeof(dword) --- 96/sizeof(qword).
Title: Re: Defining Windows API functions
Post by: zedd151 on January 03, 2025, 02:47:58 PM
Says Google (AI bot)

QuoteWhen using CreateWindowExW in 64-bit code, the parameters remain the same as in 32-bit code. However, there are a few things you need to be aware of:
1. Pointer Sizes:
In 64-bit code, pointers are 64 bits wide. This means that any parameters that are pointers (e.g., lpClassName, lpWindowName, hInstance) will be 64-bit values.
2. Data Alignment:
64-bit Windows uses 8-byte alignment for structures. This means that the members of structures passed to CreateWindowExW (e.g., WNDCLASSEX) must be properly aligned.
3. Callback Functions:
If you're using a callback function (e.g., WNDPROC), you need to make sure it's compiled as 64-bit code and that the function pointer is declared correctly.
Here's a breakdown of the parameters:
C++

HWND CreateWindowExW(
  DWORD    dwExStyle,      // Extended window styles
  LPCWSTR  lpClassName,    // Pointer to registered class name
  LPCWSTR  lpWindowName,  // Pointer to window name
  DWORD    dwStyle,        // Window styles
  int      x,              // Horizontal position of the window
  int      y,              // Vertical position of the window
  int      nWidth,          // Width of the window
  int      nHeight,        // Height of the window
  HWND      hWndParent,    // Handle to the parent window
  HMENU    hMenu,          // Handle to the window menu
  HINSTANCE hInstance,      // Handle to the instance of the module
  LPVOID    lpParam        // Pointer to window creation data
);
Key Points:
No changes to parameter types: The types of the parameters remain the same in 64-bit code.
Pointer size changes: Pointers are 8 bytes in 64-bit, which affects parameters like lpClassName, lpWindowName, and hInstance.
Alignment matters: Structures passed to the function must be 8-byte aligned.

dwExStyle and dwStyle are dwords from the look of it. The "int's" ought to be qwords in 64 bit, afaics.
Hope this helps.

Sucks not having a prototype, like masm32 does.
Title: Re: Defining Windows API functions
Post by: TimoVJL on January 03, 2025, 03:08:44 PM
Quote from: sinsi on January 03, 2025, 02:29:55 PMCan I assume that the 32-bit declaration _imp__CreateWindowExW@48 is the equivalent of a (made up) 64-bit _imp__CreateWindowExW@96?
i.e 48/sizeof(dword) --- 96/sizeof(qword).
64-bit Windows don't have decoration, as it have only one calling convention.
Title: Re: Defining Windows API functions
Post by: sinsi on January 03, 2025, 03:28:14 PM
Quote from: zedd151 on January 03, 2025, 02:47:58 PMThis means that the members of structures passed to CreateWindowExW (e.g., WNDCLASSEX)
That is enough for me to blacklist ChatGPT.

Quote from: TimoVJL on January 03, 2025, 03:08:44 PM64-bit Windows don't have decoration, as it have only one calling convention.
That's why I said (made up).

The question remains, CreateWindowEx (and any API call) has the same number of parameters for 32- and 64-bit.

Title: Re: Defining Windows API functions
Post by: zedd151 on January 03, 2025, 03:43:59 PM
Quote from: sinsi on January 03, 2025, 03:28:14 PMThat is enough for me to blacklist ChatGPT.
No, that was Google.  :tongue:
Title: Re: Defining Windows API functions
Post by: TimoVJL on January 03, 2025, 03:59:56 PM
Quote from: sinsi on January 03, 2025, 03:28:14 PMThe question remains, CreateWindowEx (and any API call) has the same number of parameters for 32- and 64-bit.
same param count
Title: Re: Defining Windows API functions
Post by: sinsi on January 03, 2025, 04:33:06 PM
 :cool:
On the same note, constants are the same?
I know the definition of "constant" but remember MS redefining boolean as 0, 1, or other.
Title: Re: Defining Windows API functions
Post by: TimoVJL on January 03, 2025, 04:50:21 PM
WinDEF. h (https://github.com/tpn/winsdk-7/blob/master/v7.1A/Include/WinDef.h)
WinGDI.h (https://github.com/tpn/winsdk-7/blob/master/v7.1A/Include/WinGDI.h)

0 FALSE
1 TRUE
Title: Re: Defining Windows API functions
Post by: sinsi on January 03, 2025, 04:57:35 PM
I was referring to this
When will GetMessage return -1? (https://devblogs.microsoft.com/oldnewthing/20130322-00/?p=4873)

QuoteThe solution (if that's what you want to call it) was to have GetMessage return the not-really-a-BOOL-but-we'll-pretend-it-is value -1 to signal an invalid parameter error.