e6a47461781fa51a172bcfa7520e51836d458288
[reactos.git] / reactos / dll / win32 / wdmaud.drv / wdmaud.c
1 /*
2 * PROJECT: ReactOS Sound System
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/wdmaud.drv/wdmaud.c
5 *
6 * PURPOSE: WDM Audio Driver (User-mode part)
7 * PROGRAMMERS: Andrew Greenwood (silverblade@reactos.org)
8 *
9 * NOTES: Looking for wodMessage & co? You won't find them here. Try
10 * the MME Buddy library, which is where these routines are
11 * actually implemented.
12 *
13 */
14
15 #include <windows.h>
16 #include <ntddsnd.h>
17 #include <sndtypes.h>
18 #include <mmddk.h>
19 #include <mmebuddy.h>
20
21 #define KERNEL_DEVICE_NAME L"\\\\Device\\wdmaud"
22
23 HANDLE KernelHandle = INVALID_HANDLE_VALUE;
24
25 APIENTRY LONG
26 DriverProc(
27 DWORD DriverId,
28 HANDLE DriverHandle,
29 UINT Message,
30 LONG Parameter1,
31 LONG Parameter2)
32 {
33 MMRESULT Result;
34
35 switch ( Message )
36 {
37 case DRV_LOAD :
38 {
39 SND_TRACE(L"DRV_LOAD\n");
40
41 Result = InitEntrypointMutexes();
42
43 if ( ! MMSUCCESS(Result) )
44 return 0L;
45
46 KernelHandle = CreateFile(KERNEL_DEVICE_NAME,
47 GENERIC_READ | GENERIC_WRITE,
48 FILE_SHARE_WRITE, // ok?
49 NULL,
50 OPEN_EXISTING,
51 FILE_FLAG_OVERLAPPED,
52 NULL);
53
54 if ( KernelHandle == INVALID_HANDLE_VALUE )
55 {
56 SND_ERR(L"Failed to open %s\n", KERNEL_DEVICE_NAME);
57 CleanupEntrypointMutexes();
58
59 UnlistAllSoundDevices();
60
61 return 0L;
62 }
63
64 SND_TRACE(L"Initialisation complete\n");
65
66 return 1L;
67 }
68
69 case DRV_FREE :
70 {
71 SND_TRACE(L"DRV_FREE\n");
72
73 if ( KernelHandle != INVALID_HANDLE_VALUE )
74 {
75 CloseHandle(KernelHandle);
76 KernelHandle = INVALID_HANDLE_VALUE;
77 }
78
79 /* TODO: Clean up the path names! */
80 UnlistAllSoundDevices();
81
82 CleanupEntrypointMutexes();
83
84 SND_TRACE(L"Unfreed memory blocks: %d\n",
85 GetMemoryAllocationCount());
86
87 return 1L;
88 }
89
90 case DRV_ENABLE :
91 case DRV_DISABLE :
92 {
93 SND_TRACE(L"DRV_ENABLE / DRV_DISABLE\n");
94 return 1L;
95 }
96
97 case DRV_OPEN :
98 case DRV_CLOSE :
99 {
100 SND_TRACE(L"DRV_OPEN / DRV_CLOSE\n");
101 return 1L;
102 }
103
104 case DRV_QUERYCONFIGURE :
105 {
106 SND_TRACE(L"DRV_QUERYCONFIGURE\n");
107 return 0L;
108 }
109 case DRV_CONFIGURE :
110 return DRVCNF_OK;
111
112 default :
113 SND_TRACE(L"Unhandled message %d\n", Message);
114 return DefDriverProc(DriverId,
115 DriverHandle,
116 Message,
117 Parameter1,
118 Parameter2);
119 }
120 }
121
122
123 BOOL WINAPI DllMain(
124 HINSTANCE hinstDLL,
125 DWORD fdwReason,
126 LPVOID lpvReserved)
127 {
128 switch ( fdwReason )
129 {
130 case DLL_PROCESS_ATTACH :
131 SND_TRACE(L"WDMAUD.DRV - Process attached\n");
132 break;
133 case DLL_PROCESS_DETACH :
134 SND_TRACE(L"WDMAUD.DRV - Process detached\n");
135 break;
136 case DLL_THREAD_ATTACH :
137 SND_TRACE(L"WDMAUD.DRV - Thread attached\n");
138 break;
139 case DLL_THREAD_DETACH :
140 SND_TRACE(L"WDMAUD.DRV - Thread detached\n");
141 break;
142 }
143
144 return TRUE;
145 }