I am developing software to manage gamepads connected to a PC.
It almost works, but pressing the close button causes an access violation error in XInputUap.dll.
This program raises an exception when you close one of the two windows you created.
As far as I tried it at hand, just creating and closing one window didn't raise an exception.
I can also select libraries to link exclusively in xinput9_1_0.lib, xinput.lib, and windowsapp.lib, but only reproduce when you link windowsapp.lib only
・Use C++/WinRT, linking windowsapp.lib
・OS:Windows 10 Pro 2004 64bit, 19041.1052 Build
・VisualStudio 2019, version 16.10.1
・Windows SDK version:10.0.19041.0
・MSVC Toolset version:14.27.29110, 14.28.29910, 14.29.30037 (Occured in any version)
The following is the reproduction code.
#include <windows.h>
#include <XInput.h>
//#pragma comment(lib, "xinput9_1_0.lib") // use xinput9_1_0.dll & xinput1_4.dll, OK
//#pragma comment(lib, "xinput.lib") // use xinput1_4.dll, OK
#pragma comment(lib, "windowsapp.lib") // use xinpuntuap.dll, Access violation in XInputUap.dll
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
{
XINPUT_CAPABILITIES capabilities = {};
XInputGetCapabilities(0, XINPUT_FLAG_GAMEPAD, &capabilities);
return 0;
}
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
WNDCLASSEX GetWindowClass(LRESULT (*WndProc)(HWND, UINT, WPARAM, LPARAM), LPCWSTR className)
{
WNDCLASSEX windowClass;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = 0;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = GetModuleHandle(nullptr);
windowClass.hIcon = nullptr;
windowClass.hCursor = nullptr;
windowClass.hbrBackground = nullptr;
windowClass.lpszMenuName = nullptr;
windowClass.lpszClassName = className;
windowClass.hIconSm = nullptr;
return windowClass;
}
int main()
{
{
auto wndCls = GetWindowClass(WndProc, L"Window1");
if (RegisterClassEx(&wndCls) == 0)
return 0;
HWND hwnd = CreateWindowEx(0, L"Window1", L"WindowName1",
WS_VISIBLE | WS_SYSMENU, 0, 0, 100, 100,
nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
}
{
auto wndCls = GetWindowClass(WndProc, L"Window2");
if (RegisterClassEx(&wndCls) == 0)
return 0;
HWND hwnd = CreateWindowEx(0, L"Window2", L"WindowName2",
WS_VISIBLE | WS_SYSMENU, 200, 0, 100, 100,
nullptr, nullptr, GetModuleHandle(nullptr), nullptr);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
}
MSG msg;
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}