jscript: Return 'unknown' in typeof operator for native object's values that can...
[wine] / dlls / devenum / devenum_main.c
1 /*
2  *      exported dll functions for devenum.dll
3  *
4  * Copyright (C) 2002 John K. Hohm
5  * Copyright (C) 2002 Robert Shearman
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "devenum_private.h"
23 #include "rpcproxy.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
27
28 LONG dll_refs;
29 HINSTANCE DEVENUM_hInstance;
30
31 typedef struct
32 {
33     REFCLSID clsid;
34     LPCWSTR friendly_name;
35     BOOL instance;
36 } register_info;
37
38 static void DEVENUM_RegisterQuartz(void);
39
40 /***********************************************************************
41  *              Global string constant definitions
42  */
43 const WCHAR clsid_keyname[6] = { 'C', 'L', 'S', 'I', 'D', 0 };
44
45 /***********************************************************************
46  *              DllEntryPoint
47  */
48 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
49 {
50     TRACE("%p 0x%x %p\n", hinstDLL, fdwReason, fImpLoad);
51
52     switch(fdwReason) {
53     case DLL_PROCESS_ATTACH:
54         DEVENUM_hInstance = hinstDLL;
55         DisableThreadLibraryCalls(hinstDLL);
56         break;
57
58     case DLL_PROCESS_DETACH:
59         DEVENUM_hInstance = 0;
60         break;
61     }
62     return TRUE;
63 }
64
65 /***********************************************************************
66  *              DllGetClassObject (DEVENUM.@)
67  */
68 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
69 {
70     TRACE("(%s, %s, %p)\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
71
72     *ppv = NULL;
73
74     /* FIXME: we should really have two class factories.
75      * Oh well - works just fine as it is */
76     if (IsEqualGUID(rclsid, &CLSID_SystemDeviceEnum) ||
77         IsEqualGUID(rclsid, &CLSID_CDeviceMoniker))
78         return IClassFactory_QueryInterface((IClassFactory*)&DEVENUM_ClassFactory, iid, ppv);
79
80     FIXME("CLSID: %s, IID: %s\n", debugstr_guid(rclsid), debugstr_guid(iid));
81     return CLASS_E_CLASSNOTAVAILABLE;
82 }
83
84 /***********************************************************************
85  *              DllCanUnloadNow (DEVENUM.@)
86  */
87 HRESULT WINAPI DllCanUnloadNow(void)
88 {
89     return dll_refs != 0 ? S_FALSE : S_OK;
90 }
91
92 /***********************************************************************
93  *              DllRegisterServer (DEVENUM.@)
94  */
95 HRESULT WINAPI DllRegisterServer(void)
96 {
97     HRESULT res;
98     IFilterMapper2 * pMapper = NULL;
99     LPVOID mapvptr;
100
101     TRACE("\n");
102
103     res = __wine_register_resources( DEVENUM_hInstance, NULL );
104
105     /* Quartz is needed for IFilterMapper2 */
106     DEVENUM_RegisterQuartz();
107
108 /*** ActiveMovieFilter Categories ***/
109
110     CoInitialize(NULL);
111     
112     res = CoCreateInstance(&CLSID_FilterMapper2, NULL, CLSCTX_INPROC,
113                            &IID_IFilterMapper2,  &mapvptr);
114     if (SUCCEEDED(res))
115     {
116         static const WCHAR friendlyvidcap[] = {'V','i','d','e','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
117         static const WCHAR friendlydshow[] = {'D','i','r','e','c','t','S','h','o','w',' ','F','i','l','t','e','r','s',0};
118         static const WCHAR friendlyvidcomp[] = {'V','i','d','e','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
119         static const WCHAR friendlyaudcap[] = {'A','u','d','i','o',' ','C','a','p','t','u','r','e',' ','S','o','u','r','c','e','s',0};
120         static const WCHAR friendlyaudcomp[] = {'A','u','d','i','o',' ','C','o','m','p','r','e','s','s','o','r','s',0};
121         static const WCHAR friendlyaudrend[] = {'A','u','d','i','o',' ','R','e','n','d','e','r','e','r','s',0};
122         static const WCHAR friendlymidirend[] = {'M','i','d','i',' ','R','e','n','d','e','r','e','r','s',0};
123         static const WCHAR friendlyextrend[] = {'E','x','t','e','r','n','a','l',' ','R','e','n','d','e','r','e','r','s',0};
124         static const WCHAR friendlydevctrl[] = {'D','e','v','i','c','e',' ','C','o','n','t','r','o','l',' ','F','i','l','t','e','r','s',0};
125
126         pMapper = mapvptr;
127
128         IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoInputDeviceCategory, MERIT_DO_NOT_USE, friendlyvidcap);
129         IFilterMapper2_CreateCategory(pMapper, &CLSID_LegacyAmFilterCategory, MERIT_NORMAL, friendlydshow);
130         IFilterMapper2_CreateCategory(pMapper, &CLSID_VideoCompressorCategory, MERIT_DO_NOT_USE, friendlyvidcomp);
131         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioInputDeviceCategory, MERIT_DO_NOT_USE, friendlyaudcap);
132         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioCompressorCategory, MERIT_DO_NOT_USE, friendlyaudcomp);
133         IFilterMapper2_CreateCategory(pMapper, &CLSID_AudioRendererCategory, MERIT_NORMAL, friendlyaudrend);
134         IFilterMapper2_CreateCategory(pMapper, &CLSID_MidiRendererCategory, MERIT_NORMAL, friendlymidirend);
135         IFilterMapper2_CreateCategory(pMapper, &CLSID_TransmitCategory, MERIT_DO_NOT_USE, friendlyextrend);
136         IFilterMapper2_CreateCategory(pMapper, &CLSID_DeviceControlCategory, MERIT_DO_NOT_USE, friendlydevctrl);
137
138         IFilterMapper2_Release(pMapper);
139     }
140
141     CoUninitialize();
142
143     return res;
144 }
145
146 /***********************************************************************
147  *              DllUnregisterServer (DEVENUM.@)
148  */
149 HRESULT WINAPI DllUnregisterServer(void)
150 {
151     FIXME("stub!\n");
152     return __wine_unregister_resources( DEVENUM_hInstance, NULL );
153 }
154
155 typedef HRESULT (WINAPI *DllRegisterServer_func)(void);
156
157 /* calls DllRegisterServer() for the Quartz DLL */
158 static void DEVENUM_RegisterQuartz(void)
159 {
160     HANDLE hDLL = LoadLibraryA("quartz.dll");
161     DllRegisterServer_func pDllRegisterServer = NULL;
162     if (hDLL)
163         pDllRegisterServer = (DllRegisterServer_func)GetProcAddress(hDLL, "DllRegisterServer");
164     if (pDllRegisterServer)
165     {
166         HRESULT hr = pDllRegisterServer();
167         if (FAILED(hr))
168             ERR("Failed to register Quartz. Error was 0x%x)\n", hr);
169     }
170 }