1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Use _beginthreadex instead of CreateThread

This commit is contained in:
narzoul 2021-02-28 22:34:47 +01:00
parent 75f8f7e689
commit 0d91170fb5
5 changed files with 21 additions and 12 deletions

View File

@ -240,7 +240,7 @@ namespace
} }
} }
DWORD WINAPI vsyncThreadProc(LPVOID /*lpParameter*/) unsigned WINAPI vsyncThreadProc(LPVOID /*lpParameter*/)
{ {
while (!g_stopVsyncThread) while (!g_stopVsyncThread)
{ {
@ -323,8 +323,7 @@ namespace D3dDdi
Compat::hookIatFunction(origDDrawModule, "gdi32.dll", "D3DKMTQueryAdapterInfo", queryAdapterInfo); Compat::hookIatFunction(origDDrawModule, "gdi32.dll", "D3DKMTQueryAdapterInfo", queryAdapterInfo);
Compat::hookIatFunction(origDDrawModule, "gdi32.dll", "D3DKMTSetGammaRamp", setGammaRamp); Compat::hookIatFunction(origDDrawModule, "gdi32.dll", "D3DKMTSetGammaRamp", setGammaRamp);
g_vsyncThread = CreateThread(nullptr, 0, &vsyncThreadProc, nullptr, 0, nullptr); g_vsyncThread = Dll::createThread(&vsyncThreadProc, nullptr, THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(g_vsyncThread, THREAD_PRIORITY_TIME_CRITICAL);
} }
void setDcFormatOverride(UINT format) void setDcFormatOverride(UINT format)

View File

@ -213,7 +213,7 @@ namespace
} }
} }
DWORD WINAPI updateThreadProc(LPVOID /*lpParameter*/) unsigned WINAPI updateThreadProc(LPVOID /*lpParameter*/)
{ {
bool skipWaitForVsync = false; bool skipWaitForVsync = false;
@ -356,8 +356,7 @@ namespace DDraw
void RealPrimarySurface::init() void RealPrimarySurface::init()
{ {
g_updateThread = CreateThread(nullptr, 0, &updateThreadProc, nullptr, 0, nullptr); g_updateThread = Dll::createThread(&updateThreadProc, nullptr, THREAD_PRIORITY_TIME_CRITICAL);
SetThreadPriority(g_updateThread, THREAD_PRIORITY_TIME_CRITICAL);
} }
bool RealPrimarySurface::isFullScreen() bool RealPrimarySurface::isFullScreen()

View File

@ -1,3 +1,5 @@
#include <process.h>
#include <Dll/Dll.h> #include <Dll/Dll.h>
namespace Dll namespace Dll
@ -5,6 +7,16 @@ namespace Dll
HMODULE g_currentModule = nullptr; HMODULE g_currentModule = nullptr;
Procs g_origProcs = {}; Procs g_origProcs = {};
Procs g_jmpTargetProcs = {}; Procs g_jmpTargetProcs = {};
HANDLE createThread(unsigned(__stdcall* threadProc)(void*), unsigned int* threadId, int priority)
{
HANDLE thread = reinterpret_cast<HANDLE>(_beginthreadex(nullptr, 0, threadProc, nullptr, 0, threadId));
if (thread)
{
SetThreadPriority(thread, priority);
}
return thread;
}
} }
#define CREATE_PROC_STUB(procName) \ #define CREATE_PROC_STUB(procName) \

View File

@ -67,6 +67,8 @@ namespace Dll
#undef ADD_FARPROC_MEMBER #undef ADD_FARPROC_MEMBER
}; };
HANDLE createThread(unsigned(__stdcall* threadProc)(void*), unsigned int* threadId, int priority);
extern HMODULE g_currentModule; extern HMODULE g_currentModule;
extern Procs g_origProcs; extern Procs g_origProcs;
extern Procs g_jmpTargetProcs; extern Procs g_jmpTargetProcs;

View File

@ -10,7 +10,7 @@ namespace
const UINT WM_SETPRESENTATIONWINDOWRGN = WM_USER + 2; const UINT WM_SETPRESENTATIONWINDOWRGN = WM_USER + 2;
HANDLE g_presentationWindowThread = nullptr; HANDLE g_presentationWindowThread = nullptr;
DWORD g_presentationWindowThreadId = 0; unsigned g_presentationWindowThreadId = 0;
HWND g_messageWindow = nullptr; HWND g_messageWindow = nullptr;
LRESULT CALLBACK messageWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK messageWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@ -80,10 +80,8 @@ namespace
return CALL_ORIG_FUNC(DefWindowProc)(hwnd, uMsg, wParam, lParam); return CALL_ORIG_FUNC(DefWindowProc)(hwnd, uMsg, wParam, lParam);
} }
DWORD WINAPI presentationWindowThreadProc(LPVOID /*lpParameter*/) unsigned WINAPI presentationWindowThreadProc(LPVOID /*lpParameter*/)
{ {
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
WNDCLASS wc = {}; WNDCLASS wc = {};
wc.lpfnWndProc = &messageWindowProc; wc.lpfnWndProc = &messageWindowProc;
wc.hInstance = Dll::g_currentModule; wc.hInstance = Dll::g_currentModule;
@ -138,8 +136,7 @@ namespace Gdi
wc.lpszClassName = "DDrawCompatPresentationWindow"; wc.lpszClassName = "DDrawCompatPresentationWindow";
CALL_ORIG_FUNC(RegisterClassA)(&wc); CALL_ORIG_FUNC(RegisterClassA)(&wc);
g_presentationWindowThread = CreateThread( Dll::createThread(presentationWindowThreadProc, &g_presentationWindowThreadId, THREAD_PRIORITY_TIME_CRITICAL);
nullptr, 0, &presentationWindowThreadProc, nullptr, 0, &g_presentationWindowThreadId);
int i = 0; int i = 0;
while (!g_messageWindow && i < 1000) while (!g_messageWindow && i < 1000)