Fix compatibility with Windows XP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c
index 5a7842a..bcb19ee 100644
--- a/src/render/direct3d12/SDL_render_d3d12.c
+++ b/src/render/direct3d12/SDL_render_d3d12.c
@@ -720,6 +720,13 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
PFN_CREATE_DXGI_FACTORY CreateDXGIFactoryFunc;
PFN_D3D12_CREATE_DEVICE D3D12CreateDeviceFunc;
#endif
+#ifndef __GDK__
+ HMODULE kernel32;
+ typedef HANDLE(WINAPI* PFN_CREATE_EVENT_EX)(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCWSTR lpName, DWORD dwFlags, DWORD dwDesiredAccess);
+ PFN_CREATE_EVENT_EX CreateEventExFunc;
+#else
+#define CreateEventExFunc CreateEventEx
+#endif
D3D12_RenderData* data = (D3D12_RenderData*)renderer->driverdata;
ID3D12Device* d3dDevice = NULL;
HRESULT result = S_OK;
@@ -748,6 +755,21 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
/* See if we need debug interfaces */
createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D11_DEBUG, SDL_FALSE);
+#ifndef __GDK__
+ /* CreateEventEx() arrived in Vista, so we need to load it with GetProcAddress for XP. */
+ kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
+ if (!kernel32) {
+ result = E_FAIL;
+ goto done;
+ }
+
+ CreateEventExFunc = (PFN_CREATE_EVENT_EX) GetProcAddress(kernel32, "CreateEventExW");
+ if (!CreateEventExFunc) {
+ result = E_FAIL;
+ goto done;
+ }
+#endif
+
#if !defined(__XBOXONE__) && !defined(__XBOXSERIES__)
data->hDXGIMod = SDL_LoadObject("dxgi.dll");
if (!data->hDXGIMod) {
@@ -999,7 +1021,7 @@ D3D12_CreateDeviceResources(SDL_Renderer* renderer)
data->fenceValue++;
- data->fenceEvent = CreateEventEx(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
+ data->fenceEvent = CreateEventExFunc(NULL, NULL, 0, EVENT_MODIFY_STATE | SYNCHRONIZE);
if (!data->fenceEvent) {
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("CreateEventEx"), result);
goto done;