Sync with trunk (r48545)
[reactos.git] / dll / win32 / avicap32 / avicap32.c
1 /*
2 * PROJECT: avicap32
3 * FILE: dll\win32\avicap32\avicap32.c
4 * PURPOSE: Main file
5 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
6 */
7
8 #include <windows.h>
9 #include <winternl.h>
10 #include <vfw.h>
11 #include <wchar.h>
12
13 #include "wine/debug.h"
14
15 #define CAP_DESC_MAX 32
16
17 WINE_DEFAULT_DEBUG_CHANNEL(avicap32);
18
19
20 HINSTANCE hInstance;
21
22
23 /* INTRENAL FUNCTIONS **************************************************/
24
25 LRESULT
26 CALLBACK
27 CaptureWindowProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
28 {
29 switch (Msg)
30 {
31 case WM_CREATE:
32 break;
33
34 case WM_PAINT:
35 break;
36
37 case WM_DESTROY:
38 break;
39 }
40
41 return DefWindowProc(hwnd, Msg, wParam, lParam);
42 }
43
44
45 /* FUNCTIONS ***********************************************************/
46
47 /*
48 * implemented
49 */
50 HWND
51 VFWAPI
52 capCreateCaptureWindowW(LPCWSTR lpszWindowName,
53 DWORD dwStyle,
54 INT x,
55 INT y,
56 INT nWidth,
57 INT nHeight,
58 HWND hWnd,
59 INT nID)
60 {
61 WCHAR szWindowClass[] = L"ClsCapWin";
62 WNDCLASSEXW WndClass = {0};
63 DWORD dwExStyle = 0;
64
65 FIXME("capCreateCaptureWindowW() not fully implemented!\n");
66
67 WndClass.cbSize = sizeof(WNDCLASSEXW);
68 WndClass.lpszClassName = szWindowClass;
69 WndClass.lpfnWndProc = CaptureWindowProc; /* TODO: Implement CaptureWindowProc */
70 WndClass.hInstance = hInstance;
71 WndClass.style = CS_HREDRAW | CS_VREDRAW;
72 WndClass.hCursor = LoadCursorW(0, IDC_ARROW);
73 WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
74
75 if (RegisterClassExW(&WndClass) == (ATOM)0)
76 {
77 if (GetLastError() != ERROR_ALREADY_EXISTS)
78 return NULL;
79 }
80
81 return CreateWindowExW(dwExStyle,
82 szWindowClass,
83 lpszWindowName,
84 dwStyle,
85 x, y,
86 nWidth,
87 nHeight,
88 hWnd,
89 ULongToHandle(nID),
90 hInstance,
91 NULL);
92 }
93
94 /*
95 * implemented
96 */
97 HWND
98 VFWAPI
99 capCreateCaptureWindowA(LPCSTR lpszWindowName,
100 DWORD dwStyle,
101 INT x,
102 INT y,
103 INT nWidth,
104 INT nHeight,
105 HWND hWnd,
106 INT nID)
107 {
108 UNICODE_STRING Name;
109 HWND Wnd;
110
111 if (lpszWindowName)
112 RtlCreateUnicodeStringFromAsciiz(&Name, lpszWindowName);
113 else
114 Name.Buffer = NULL;
115
116 Wnd = capCreateCaptureWindowW(Name.Buffer,
117 dwStyle,
118 x, y,
119 nWidth,
120 nHeight,
121 hWnd,
122 nID);
123
124 RtlFreeUnicodeString(&Name);
125 return Wnd;
126 }
127
128
129 /*
130 * implemented
131 */
132 BOOL
133 VFWAPI
134 capGetDriverDescriptionW(WORD wDriverIndex,
135 LPWSTR lpszName,
136 INT cbName,
137 LPWSTR lpszVer,
138 INT cbVer)
139 {
140 DWORD dwSize, dwIndex = 0;
141 WCHAR szDriver[MAX_PATH];
142 WCHAR szDriverName[MAX_PATH];
143 WCHAR szFileName[MAX_PATH];
144 WCHAR szVersion[MAX_PATH];
145 HKEY hKey, hSubKey;
146
147 /* TODO: Add support of data acquisition from system.ini */
148 FIXME("capGetDriverDescriptionW() not fully implemented!\n");
149
150 if (lpszName && cbName)
151 lpszName[0] = L'\0';
152
153 if (lpszVer && cbVer)
154 lpszVer[0] = L'\0';
155
156 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
157 L"SYSTEM\\CurrentControlSet\\Control\\MediaResources\\msvideo",
158 0,
159 KEY_READ,
160 &hKey) != ERROR_SUCCESS)
161 {
162 return FALSE;
163 }
164
165 dwSize = sizeof(szDriver) / sizeof(WCHAR);
166
167 while (RegEnumKeyExW(hKey, dwIndex,
168 szDriver, &dwSize,
169 NULL, NULL,
170 NULL, NULL) == ERROR_SUCCESS)
171 {
172 if (RegOpenKeyW(hKey, szDriver, &hSubKey) == ERROR_SUCCESS)
173 {
174 dwSize = sizeof(szFileName) / sizeof(WCHAR);
175
176 if (RegQueryValueExW(hSubKey,
177 L"Driver",
178 NULL,
179 NULL,
180 (LPBYTE)&szFileName,
181 &dwSize) == ERROR_SUCCESS)
182 {
183 dwSize = sizeof(szDriverName) / sizeof(WCHAR);
184
185 if (RegQueryValueExW(hSubKey,
186 L"FriendlyName",
187 NULL,
188 NULL,
189 (LPBYTE)&szDriverName,
190 &dwSize) != ERROR_SUCCESS)
191 {
192 wcscpy(szDriverName, L"Unknown Driver Name");
193 }
194
195 if (dwIndex == (DWORD)wDriverIndex)
196 {
197 if (lpszName && cbName)
198 {
199 lstrcpynW(lpszName, szDriverName, cbName);
200 }
201
202 if (lpszVer && cbVer)
203 {
204 LPVOID Version, Ms;
205 DWORD dwInfoSize;
206 VS_FIXEDFILEINFO FileInfo;
207 UINT Ls;
208
209 dwInfoSize = GetFileVersionInfoSize(szFileName, NULL);
210 if (dwInfoSize)
211 {
212 Version = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
213
214 GetFileVersionInfo(szFileName, 0, dwInfoSize, Version);
215
216 if (VerQueryValueW(Version, L"\\", &Ms, &Ls))
217 {
218 memmove(&FileInfo, Ms, Ls);
219 swprintf(szVersion, L"Version: %d.%d.%d.%d",
220 HIWORD(FileInfo.dwFileVersionMS),
221 LOWORD(FileInfo.dwFileVersionMS),
222 HIWORD(FileInfo.dwFileVersionLS),
223 LOWORD(FileInfo.dwFileVersionLS));
224
225 lstrcpynW(lpszVer, szVersion, cbVer);
226 }
227 HeapFree(GetProcessHeap(), 0, Version);
228 }
229 }
230
231 RegCloseKey(hSubKey);
232 RegCloseKey(hKey);
233 return TRUE;
234 }
235 }
236
237 RegCloseKey(hSubKey);
238 }
239
240 dwSize = sizeof(szDriver) / sizeof(WCHAR);
241 dwIndex++;
242 }
243
244 RegCloseKey(hKey);
245
246 return FALSE;
247 }
248
249
250 /*
251 * implemented
252 */
253 BOOL
254 VFWAPI
255 capGetDriverDescriptionA(WORD wDriverIndex,
256 LPSTR lpszName,
257 INT cbName,
258 LPSTR lpszVer,
259 INT cbVer)
260 {
261 WCHAR DevName[CAP_DESC_MAX], DevVer[CAP_DESC_MAX];
262 BOOL Result;
263
264 Result = capGetDriverDescriptionW(wDriverIndex, DevName, CAP_DESC_MAX, DevVer, CAP_DESC_MAX);
265 if (Result)
266 {
267 WideCharToMultiByte(CP_ACP, 0, DevName, -1, lpszName, cbName, NULL, NULL);
268 WideCharToMultiByte(CP_ACP, 0, DevVer, -1, lpszVer, cbVer, NULL, NULL);
269 }
270
271 return Result;
272 }
273
274
275 /*
276 * unimplemented
277 */
278 VOID
279 VFWAPI
280 AppCleanup(HINSTANCE hInst)
281 {
282 UNIMPLEMENTED;
283 }
284
285
286 /*
287 * unimplemented
288 */
289 DWORD
290 VFWAPI
291 videoThunk32(DWORD dwUnknown1, DWORD dwUnknown2, DWORD dwUnknown3, DWORD dwUnknown4, DWORD dwUnknown5)
292 {
293 UNIMPLEMENTED;
294 return 0;
295 }
296
297
298 BOOL
299 WINAPI
300 DllMain(IN HINSTANCE hinstDLL,
301 IN DWORD dwReason,
302 IN LPVOID lpvReserved)
303 {
304 switch (dwReason)
305 {
306 case DLL_PROCESS_ATTACH:
307 TRACE("avicap32 attached!\n");
308 hInstance = hinstDLL;
309 break;
310 }
311
312 return TRUE;
313 }