quartz: Fix string buffer overflow.
[wine.git] / dlls / msimtf / main.c
blobda675aa18a2ab76bb7084b1f6a9b50316ceef243
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "advpub.h"
32 #include "ole2.h"
33 #include "dimm.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msimtf);
39 static HINSTANCE msimtf_instance;
41 static HRESULT CActiveIMM_Create(IUnknown *outer, REFIID riid, void **ppv)
43 FIXME("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
44 return E_NOINTERFACE;
47 /******************************************************************
48 * DllMain (msimtf.@)
50 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
52 switch(fdwReason)
54 case DLL_WINE_PREATTACH:
55 return FALSE; /* prefer native version */
56 case DLL_PROCESS_ATTACH:
57 msimtf_instance = hInstDLL;
58 DisableThreadLibraryCalls(hInstDLL);
59 break;
60 case DLL_PROCESS_DETACH:
61 break;
63 return TRUE;
66 typedef struct {
67 const IClassFactoryVtbl *lpClassFactoryVtbl;
69 HRESULT (*cf)(IUnknown*,REFIID,void**);
70 } ClassFactory;
72 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface,
73 REFIID riid, void **ppv)
75 *ppv = NULL;
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;
85 if(*ppv) {
86 IUnknown_AddRef((IUnknown*)*ppv);
87 return S_OK;
90 FIXME("(%s %p)\n", debugstr_guid(riid), ppv);
91 return E_NOINTERFACE;
94 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
96 return 2;
99 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
101 return 1;
104 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
105 IUnknown *pOuter, REFIID riid, void **ppv)
107 ClassFactory *This = (ClassFactory*)iface;
108 return This->cf(pOuter, riid, ppv);
111 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
113 FIXME("(%d)\n", dolock);
114 return S_OK;
117 static const IClassFactoryVtbl ClassFactoryVtbl = {
118 ClassFactory_QueryInterface,
119 ClassFactory_AddRef,
120 ClassFactory_Release,
121 ClassFactory_CreateInstance,
122 ClassFactory_LockServer
125 /******************************************************************
126 * DllGetClassObject (msimtf.@)
128 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
130 if(IsEqualGUID(&CLSID_CActiveIMM, rclsid)) {
131 static ClassFactory cf = {
132 &ClassFactoryVtbl,
133 CActiveIMM_Create
136 TRACE("CLSID_CActiveIMM\n");
138 return IClassFactory_QueryInterface((IClassFactory*)&cf, riid, ppv);
141 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
142 return CLASS_E_CLASSNOTAVAILABLE;
145 /******************************************************************
146 * DllCanUnloadNow (msimtf.@)
148 HRESULT WINAPI DllCanUnloadNow(void)
150 FIXME("()\n");
151 return S_FALSE;
154 #define INF_SET_CLSID(clsid) \
155 do \
157 static CHAR name[] = "CLSID_" #clsid; \
159 pse[i].pszName = name; \
160 clsids[i++] = &CLSID_ ## clsid; \
161 } while (0)
163 static HRESULT register_server(BOOL doregister)
165 HRESULT hres;
166 HMODULE hAdvpack;
167 HRESULT (WINAPI *pRegInstall)(HMODULE hm, LPCSTR pszSection, const STRTABLEA* pstTable);
168 STRTABLEA strtable;
169 STRENTRYA pse[1];
170 static CLSID const *clsids[34];
171 int i = 0;
173 static const WCHAR wszAdvpack[] = {'a','d','v','p','a','c','k','.','d','l','l',0};
175 INF_SET_CLSID(CActiveIMM);
177 for(i = 0; i < sizeof(pse)/sizeof(pse[0]); i++) {
178 pse[i].pszValue = HeapAlloc(GetProcessHeap(), 0, 39);
179 sprintf(pse[i].pszValue, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
180 clsids[i]->Data1, clsids[i]->Data2, clsids[i]->Data3, clsids[i]->Data4[0],
181 clsids[i]->Data4[1], clsids[i]->Data4[2], clsids[i]->Data4[3], clsids[i]->Data4[4],
182 clsids[i]->Data4[5], clsids[i]->Data4[6], clsids[i]->Data4[7]);
185 strtable.cEntries = sizeof(pse)/sizeof(pse[0]);
186 strtable.pse = pse;
188 hAdvpack = LoadLibraryW(wszAdvpack);
189 pRegInstall = (void *)GetProcAddress(hAdvpack, "RegInstall");
191 hres = pRegInstall(msimtf_instance, doregister ? "RegisterDll" : "UnregisterDll", &strtable);
193 for(i=0; i < sizeof(pse)/sizeof(pse[0]); i++)
194 HeapFree(GetProcessHeap(), 0, pse[i].pszValue);
196 return hres;
199 #undef INF_SET_CLSID
201 /***********************************************************************
202 * DllRegisterServer (msimtf.@)
204 HRESULT WINAPI DllRegisterServer(void)
206 return register_server(TRUE);
209 /***********************************************************************
210 * DllUnregisterServer (msimtf.@)
212 HRESULT WINAPI DllUnregisterServer(void)
214 return register_server(FALSE);