feat(windows-nui): log next to the DLL + DllMain load marker (robust log location)
This commit is contained in:
1 parent
e88e0e5c58
commit
dbc75f12e1
2 files changed
+25
-5
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user