From dbc75f12e13587f3c2109cbe9ce685b5524aebee Mon Sep 17 00:00:00 2001 From: kinect-bot Date: Wed, 25 Nov 2026 15:37:19 -0500 Subject: [PATCH] feat(windows-nui): log next to the DLL + DllMain load marker (robust log location) --- fallback/windows-nui/src/exports.cpp | 2 ++ fallback/windows-nui/src/shim_log.h | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/fallback/windows-nui/src/exports.cpp b/fallback/windows-nui/src/exports.cpp index b7d4cc5..4c7d941 100644 --- a/fallback/windows-nui/src/exports.cpp +++ b/fallback/windows-nui/src/exports.cpp @@ -200,7 +200,9 @@ void* WINAPI KinectShimReserved1(void) { return nullptr; } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD reason, LPVOID) { switch (reason) { case DLL_PROCESS_ATTACH: + nui_shim::ShimModuleHandle() = hinstDLL; DisableThreadLibraryCalls(hinstDLL); + nui_shim::ShimLog("DllMain PROCESS_ATTACH (Kinect10 shim loaded)"); break; case DLL_PROCESS_DETACH: DestroyGlobalSensor(); diff --git a/fallback/windows-nui/src/shim_log.h b/fallback/windows-nui/src/shim_log.h index b3e92c0..9e74e3b 100644 --- a/fallback/windows-nui/src/shim_log.h +++ b/fallback/windows-nui/src/shim_log.h @@ -8,6 +8,11 @@ namespace nui_shim { +inline HINSTANCE& ShimModuleHandle() { + static HINSTANCE handle = nullptr; + return handle; +} + inline CRITICAL_SECTION& ShimLogLock() { static CRITICAL_SECTION cs; static BOOL once = [] { @@ -22,12 +27,25 @@ inline void ShimLog(const char* fmt, ...) { wchar_t path[MAX_PATH]; DWORD n = GetEnvironmentVariableW(L"KINECT_SHIM_LOG", path, MAX_PATH); if (n == 0 || n >= MAX_PATH) { - wchar_t tmp[MAX_PATH]; - DWORD t = GetTempPathW(MAX_PATH, tmp); - if (t == 0 || t >= MAX_PATH) { - return; + wchar_t module_path[MAX_PATH]; + DWORD m = GetModuleFileNameW(ShimModuleHandle(), module_path, MAX_PATH); + if (m != 0 && m < MAX_PATH) { + wchar_t* last_sep = wcsrchr(module_path, L'\\'); + if (last_sep != nullptr) { + *(last_sep + 1) = L'\0'; + _snwprintf(path, MAX_PATH, L"%skinect_shim.log", module_path); + } else { + m = 0; + } + } + if (m == 0 || m >= MAX_PATH) { + wchar_t tmp[MAX_PATH]; + DWORD t = GetTempPathW(MAX_PATH, tmp); + if (t == 0 || t >= MAX_PATH) { + return; + } + _snwprintf(path, MAX_PATH, L"%skinect_shim.log", tmp); } - _snwprintf(path, MAX_PATH, L"%skinect_shim.log", tmp); } EnterCriticalSection(&ShimLogLock());