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