-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseh_wrapper.cpp
More file actions
62 lines (57 loc) · 2.11 KB
/
seh_wrapper.cpp
File metadata and controls
62 lines (57 loc) · 2.11 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
// seh_wrapper.cpp
#include <stdio.h> // For swprintf_s
#include <windows.h>
// Forward declaration of the class with explicit method we need to access
class ArgumentDebuggerWindow
{
public:
// Only declare the method we're calling from here
DWORD AudioCaptureThreadImpl(LPVOID param);
};
// Log function declarations - simplified version for SEH context
extern void LogSEH(const wchar_t* message);
// Note: WINAPI is defined as __stdcall for compatibility with Windows API types
extern "C" DWORD WINAPI RawAudioThreadWithSEH(LPVOID param) noexcept
{
DWORD exitCode = 0;
__try
{
// Check if param is valid
if (!param)
{
return 0xC0000005; // EXCEPTION_ACCESS_VIOLATION
}
// Forward to the real implementation
// Note: This expects param to point to an object with AudioCaptureThreadImpl method
ArgumentDebuggerWindow* self = static_cast<ArgumentDebuggerWindow*>(param);
exitCode = self->AudioCaptureThreadImpl(param);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
DWORD code = GetExceptionCode();
// Log through OutputDebugString to avoid std::wstring
wchar_t buf[128];
if (code == EXCEPTION_ACCESS_VIOLATION)
{
OutputDebugStringW(L"SEH: Access violation in audio thread (0xC0000005)\n");
LogSEH(L"SEH: Access violation in audio thread (0xC0000005)");
exitCode = 0xC0000005; // EXCEPTION_ACCESS_VIOLATION
}
else if (code == EXCEPTION_STACK_OVERFLOW)
{
OutputDebugStringW(L"SEH: Stack overflow in audio thread (0xC00000FD)\n");
LogSEH(L"SEH: Stack overflow in audio thread (0xC00000FD)");
exitCode = 0xC00000FD; // EXCEPTION_STACK_OVERFLOW
}
else
{
// Use wsprintfW instead of swprintf_s for better backward compatibility
wsprintfW(buf, L"SEH: Exception in audio thread, code=0x%08X", code);
OutputDebugStringW(buf);
OutputDebugStringW(L"\n");
LogSEH(buf);
exitCode = code;
}
}
return exitCode;
}