-
Notifications
You must be signed in to change notification settings - Fork 1
/
rwinmm.c
37 lines (28 loc) · 904 Bytes
/
rwinmm.c
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
#include <windows.h>
#include "wgmus.h"
static HINSTANCE winmm = 0;
HINSTANCE getWinmmHandle()
{
return winmm;
}
/* watches for the app to close, unloads the library when it does */
/* since FreeLibrary is dangerous in DllMain */
void ExitMonitor(LPVOID DLLHandle)
{
WaitForSingleObject(DLLHandle, INFINITE);
FreeLibrary(getWinmmHandle());
}
/* if winmm.dll is already loaded, return its handle */
/* otherwise, load it */
HINSTANCE loadRealDLL()
{
if (winmm)
return winmm;
char winmm_path[MAX_PATH];
GetSystemDirectory(winmm_path, MAX_PATH);
strncat(winmm_path, "\\winmm.DLL", 11); /* fixed gcc overflow warning */
winmm = LoadLibrary(winmm_path);
/* start watcher thread to close the library */
CreateThread(NULL, 500, (LPTHREAD_START_ROUTINE)ExitMonitor, GetCurrentThread(), 0, NULL);
return winmm;
}