Sync with trunk rev.61910 to get latest improvements and bugfixes.
[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 "precomp.h"
20
21 #include <rpcproxy.h>
22
23 extern HRESULT ActiveIMMApp_Constructor(IUnknown *punkOuter, IUnknown **ppOut);
24
25 static HINSTANCE msimtf_instance;
26
27 /******************************************************************
28 * DllMain (msimtf.@)
29 */
30 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
31 {
32 switch(fdwReason)
33 {
34 case DLL_WINE_PREATTACH:
35 return FALSE; /* prefer native version */
36 case DLL_PROCESS_ATTACH:
37 msimtf_instance = hInstDLL;
38 DisableThreadLibraryCalls(hInstDLL);
39 break;
40 }
41 return TRUE;
42 }
43
44 typedef struct {
45 IClassFactory IClassFactory_iface;
46
47 HRESULT (*cf)(IUnknown*,IUnknown**);
48 } ClassFactory;
49
50 static inline ClassFactory *impl_from_IClassFactory(IClassFactory *iface)
51 {
52 return CONTAINING_RECORD(iface, ClassFactory, IClassFactory_iface);
53 }
54
55 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface,
56 REFIID riid, void **ppv)
57 {
58 *ppv = NULL;
59
60 if(IsEqualGUID(&IID_IUnknown, riid)) {
61 TRACE("(IID_IUnknown %p)\n", ppv);
62 *ppv = iface;
63 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
64 TRACE("IID_IClassFactory %p)\n", ppv);
65 *ppv = iface;
66 }
67
68 if(*ppv) {
69 IUnknown_AddRef((IUnknown*)*ppv);
70 return S_OK;
71 }
72
73 FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
74 return E_NOINTERFACE;
75 }
76
77 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
78 {
79 return 2;
80 }
81
82 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
83 {
84 return 1;
85 }
86
87 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
88 IUnknown *pOuter, REFIID riid, void **ppv)
89 {
90 ClassFactory *This = impl_from_IClassFactory(iface);
91 HRESULT ret;
92 IUnknown *obj;
93 TRACE("(%p, %p, %s, %p)\n", iface, pOuter, debugstr_guid(riid), ppv);
94
95 ret = This->cf(pOuter, &obj);
96 if (FAILED(ret))
97 return ret;
98
99 ret = IUnknown_QueryInterface(obj,riid,ppv);
100 IUnknown_Release(obj);
101 return ret;
102 }
103
104 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
105 {
106 FIXME("(%d)\n", dolock);
107 return S_OK;
108 }
109
110 static const IClassFactoryVtbl ClassFactoryVtbl = {
111 ClassFactory_QueryInterface,
112 ClassFactory_AddRef,
113 ClassFactory_Release,
114 ClassFactory_CreateInstance,
115 ClassFactory_LockServer
116 };
117
118 /******************************************************************
119 * DllGetClassObject (msimtf.@)
120 */
121 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
122 {
123 if(IsEqualGUID(&CLSID_CActiveIMM, rclsid)) {
124 static ClassFactory cf = {
125 { &ClassFactoryVtbl },
126 ActiveIMMApp_Constructor,
127 };
128
129 return IClassFactory_QueryInterface((IClassFactory*)&cf, riid, ppv);
130 }
131
132 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
133 return CLASS_E_CLASSNOTAVAILABLE;
134 }
135
136 /******************************************************************
137 * DllCanUnloadNow (msimtf.@)
138 */
139 HRESULT WINAPI DllCanUnloadNow(void)
140 {
141 return S_FALSE;
142 }
143
144 /***********************************************************************
145 * DllRegisterServer (msimtf.@)
146 */
147 HRESULT WINAPI DllRegisterServer(void)
148 {
149 return __wine_register_resources( msimtf_instance );
150 }
151
152 /***********************************************************************
153 * DllUnregisterServer (msimtf.@)
154 */
155 HRESULT WINAPI DllUnregisterServer(void)
156 {
157 return __wine_unregister_resources( msimtf_instance );
158 }