* Sync up to trunk r55544.
[reactos.git] / dll / win32 / msimtf / main.c
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "ole2.h"
31 #include "rpcproxy.h"
32 #include "dimm.h"
33
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(msimtf);
37
38 extern HRESULT ActiveIMMApp_Constructor(IUnknown *punkOuter, IUnknown **ppOut);
39
40 static HINSTANCE msimtf_instance;
41
42 /******************************************************************
43 * DllMain (msimtf.@)
44 */
45 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
46 {
47 switch(fdwReason)
48 {
49 case DLL_WINE_PREATTACH:
50 return FALSE; /* prefer native version */
51 case DLL_PROCESS_ATTACH:
52 msimtf_instance = hInstDLL;
53 DisableThreadLibraryCalls(hInstDLL);
54 break;
55 case DLL_PROCESS_DETACH:
56 break;
57 }
58 return TRUE;
59 }
60
61 typedef struct {
62 IClassFactory IClassFactory_iface;
63
64 HRESULT (*cf)(IUnknown*,IUnknown**);
65 } ClassFactory;
66
67 static inline ClassFactory *impl_from_IClassFactory(IClassFactory *iface)
68 {
69 return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
70 }
71
72 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface,
73 REFIID riid, void **ppv)
74 {
75 *ppv = NULL;
76
77 if(IsEqualGUID(&IID_IUnknown, riid)) {
78 TRACE("(IID_IUnknown %p)\n", ppv);
79 *ppv = iface;
80 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
81 TRACE("IID_IClassFactory %p)\n", ppv);
82 *ppv = iface;
83 }
84
85 if(*ppv) {
86 IUnknown_AddRef((IUnknown*)*ppv);
87 return S_OK;
88 }
89
90 FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
91 return E_NOINTERFACE;
92 }
93
94 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
95 {
96 return 2;
97 }
98
99 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
100 {
101 return 1;
102 }
103
104 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
105 IUnknown *pOuter, REFIID riid, void **ppv)
106 {
107 ClassFactory *This = impl_from_IClassFactory(iface);
108 HRESULT ret;
109 IUnknown *obj;
110 TRACE("(%p, %p, %s, %p)\n", iface, pOuter, debugstr_guid(riid), ppv);
111
112 ret = This->cf(pOuter, &obj);
113 if (FAILED(ret))
114 return ret;
115
116 ret = IUnknown_QueryInterface(obj,riid,ppv);
117 IUnknown_Release(obj);
118 return ret;
119 }
120
121 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
122 {
123 FIXME("(%d)\n", dolock);
124 return S_OK;
125 }
126
127 static const IClassFactoryVtbl ClassFactoryVtbl = {
128 ClassFactory_QueryInterface,
129 ClassFactory_AddRef,
130 ClassFactory_Release,
131 ClassFactory_CreateInstance,
132 ClassFactory_LockServer
133 };
134
135 /******************************************************************
136 * DllGetClassObject (msimtf.@)
137 */
138 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
139 {
140 if(IsEqualGUID(&CLSID_CActiveIMM, rclsid)) {
141 static ClassFactory cf = {
142 { &ClassFactoryVtbl },
143 ActiveIMMApp_Constructor,
144 };
145
146 return IClassFactory_QueryInterface((IClassFactory*)&cf, riid, ppv);
147 }
148
149 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
150 return CLASS_E_CLASSNOTAVAILABLE;
151 }
152
153 /******************************************************************
154 * DllCanUnloadNow (msimtf.@)
155 */
156 HRESULT WINAPI DllCanUnloadNow(void)
157 {
158 return S_FALSE;
159 }
160
161 /***********************************************************************
162 * DllRegisterServer (msimtf.@)
163 */
164 HRESULT WINAPI DllRegisterServer(void)
165 {
166 return __wine_register_resources( msimtf_instance );
167 }
168
169 /***********************************************************************
170 * DllUnregisterServer (msimtf.@)
171 */
172 HRESULT WINAPI DllUnregisterServer(void)
173 {
174 return __wine_unregister_resources( msimtf_instance );
175 }