MCPcopy Create free account
hub / github.com/audiorouterdev/audio-router / DllMain

Function DllMain

audio-router/main.cpp:53–101  ·  view source on GitHub ↗

FALSE ret val will decrement the ref count TRUE ret val will keep the dll

Source from the content-addressed store, hash-verified

51// FALSE ret val will decrement the ref count
52// TRUE ret val will keep the dll
53BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
54{
55 if(fdwReason == DLL_PROCESS_ATTACH)
56 {
57 HRESULT hr;
58 IMMDeviceEnumerator* pEnumerator;
59 IMMDevice* pDevice;
60
61 hr = CoInitialize(NULL);
62 if(hr != S_OK)
63 return FALSE;
64 hr = CoCreateInstance(
65 __uuidof(MMDeviceEnumerator), NULL,
66 CLSCTX_ALL, __uuidof(IMMDeviceEnumerator),
67 (void**)&pEnumerator);
68 if(hr != S_OK)
69 return FALSE;
70 hr = pEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &pDevice);
71 if(hr != S_OK)
72 {
73 pEnumerator->Release();
74 return FALSE;
75 }
76
77 DWORD* patch_activate_ptr = ((DWORD***)pDevice)[0][3];
78
79 pDevice->Release();
80 pEnumerator->Release();
81
82 InitializeCriticalSectionAndSpinCount(&CriticalSection, 0x00000400);
83 patch_activate.patch(patch_activate_ptr);
84
85 // patch only after the unloading of the library cannot happen
86 if(!apply_explicit_routing() && !apply_implicit_routing())
87 // (patches are automatically reverted)
88 return FALSE;
89 }
90 else if(fdwReason == DLL_THREAD_ATTACH)
91 apply_explicit_routing();
92 else if(fdwReason == DLL_PROCESS_DETACH)
93 {
94 // TODO: include critical sections in the patcher
95 // TODO: decide if delete device id str(practically does not have any effect)
96 // (patches are automatically reverted)
97 DeleteCriticalSection(&CriticalSection);
98 }
99
100 return TRUE;
101}
102
103bool apply_parameters(const local_routing_params& params)
104{

Callers

nothing calls this directly

Calls 4

apply_explicit_routingFunction · 0.85
apply_implicit_routingFunction · 0.85
patchMethod · 0.80
ReleaseMethod · 0.45

Tested by

no test coverage detected