Closed KrishBaidya closed 2 hours ago
Well, your subclass window procedure is badly defined. I wouldn't be surprised if this is causing truncation and sign extension resulting in the access violation of a kernel mode pointer.
The actual signature of a window procedure is:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
This is important for two reasons. First, the CALLBACK
marks the function as __stdcall. For 32 bit applications, this sets the correct calling convention. It is ignored for 64 bit applications. The third and fourth parameters are typedefs for 64 bit types for 64 bit applications. WPARAM
is a typedef for unsinged long long
(uint64_t
). LPARAM
is a typedef for long long
(int64_t
). The type you use, INT
is a typedef for int
, a 32 bit unsigned type. This means that any types being passed into the window procedure will be truncated to 32 bits, and then sign extended again.
Yeah, I just found this. In my main project I was having different issue, that's why I created a sample C# with chatGPT, it was working fine and I copy pasted. Sorry, I have now close this.
Describe the bug
I am having issues with subclassing in C++, but it works correctly in C#.
The issue I am Getting is - Exception thrown at 0x00007FF9C7231DD4 (user32.dll) in WinUICPPTest.exe: 0xC0000005: Access violation reading location 0xFFFFFFFF9E76E4C0.
On this line return CallWindowProc(originalWndProc, hWnd, uMsg, wParam, lParam);
Here is the C++ version-
And Here is the C# version
Steps to reproduce the bug
Expected behavior
The Window Subclassing should work fine without throwing the above exception. The Window should have invoked when HotKey is pressed.
Screenshots
No response
NuGet package version
None
Windows version
No response
Additional context
I am working on a WinUI3 app with C++, but this is the issue I am getting. I tried this on a C# WinUI 3 App and that's working correctly.