4 * Copyright 2008 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
38 #include "msctf_internal.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msctf
);
42 static LONG MSCTF_refCount
;
44 static HINSTANCE MSCTF_hinstance
;
46 typedef HRESULT (*LPFNCONSTRUCTOR
)(IUnknown
*pUnkOuter
, IUnknown
**ppvOut
);
52 {&CLSID_TF_ThreadMgr
, ThreadMgr_Constructor
},
56 typedef struct tagClassFactory
58 const IClassFactoryVtbl
*vtbl
;
63 static void ClassFactory_Destructor(ClassFactory
*This
)
65 TRACE("Destroying class factory %p\n", This
);
66 HeapFree(GetProcessHeap(),0,This
);
70 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppvOut
)
73 if (IsEqualIID(riid
, &IID_IClassFactory
) || IsEqualIID(riid
, &IID_IUnknown
)) {
74 IClassFactory_AddRef(iface
);
79 WARN("Unknown interface %s\n", debugstr_guid(riid
));
83 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
85 ClassFactory
*This
= (ClassFactory
*)iface
;
86 return InterlockedIncrement(&This
->ref
);
89 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
91 ClassFactory
*This
= (ClassFactory
*)iface
;
92 ULONG ret
= InterlockedDecrement(&This
->ref
);
95 ClassFactory_Destructor(This
);
99 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID iid
, LPVOID
*ppvOut
)
101 ClassFactory
*This
= (ClassFactory
*)iface
;
105 TRACE("(%p, %p, %s, %p)\n", iface
, punkOuter
, debugstr_guid(iid
), ppvOut
);
106 ret
= This
->ctor(punkOuter
, &obj
);
109 ret
= IUnknown_QueryInterface(obj
, iid
, ppvOut
);
110 IUnknown_Release(obj
);
114 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
116 ClassFactory
*This
= (ClassFactory
*)iface
;
118 TRACE("(%p)->(%x)\n", This
, fLock
);
121 InterlockedIncrement(&MSCTF_refCount
);
123 InterlockedDecrement(&MSCTF_refCount
);
128 static const IClassFactoryVtbl ClassFactoryVtbl
= {
130 ClassFactory_QueryInterface
,
132 ClassFactory_Release
,
135 ClassFactory_CreateInstance
,
136 ClassFactory_LockServer
139 static HRESULT
ClassFactory_Constructor(LPFNCONSTRUCTOR ctor
, LPVOID
*ppvOut
)
141 ClassFactory
*This
= HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory
));
142 This
->vtbl
= &ClassFactoryVtbl
;
145 *ppvOut
= (LPVOID
)This
;
146 TRACE("Created class factory %p\n", This
);
151 /*************************************************************************
154 BOOL WINAPI
DllMain(HINSTANCE hinst
, DWORD fdwReason
, LPVOID fImpLoad
)
156 TRACE("%p 0x%x %p\n", hinst
, fdwReason
, fImpLoad
);
159 case DLL_WINE_PREATTACH
:
160 return FALSE
; /* prefer native version */
161 case DLL_PROCESS_ATTACH
:
162 DisableThreadLibraryCalls(hinst
);
163 MSCTF_hinstance
= hinst
;
169 /*************************************************************************
170 * DllCanUnloadNow (MSCTF.@)
172 HRESULT WINAPI
DllCanUnloadNow(void)
174 return MSCTF_refCount
? S_FALSE
: S_OK
;
177 /***********************************************************************
178 * DllGetClassObject (MSCTF.@)
180 HRESULT WINAPI
DllGetClassObject(REFCLSID clsid
, REFIID iid
, LPVOID
*ppvOut
)
185 if (!IsEqualIID(iid
, &IID_IUnknown
) && !IsEqualIID(iid
, &IID_IClassFactory
))
186 return E_NOINTERFACE
;
188 for (i
= 0; ClassesTable
[i
].clsid
!= NULL
; i
++)
189 if (IsEqualCLSID(ClassesTable
[i
].clsid
, clsid
)) {
190 return ClassFactory_Constructor(ClassesTable
[i
].ctor
, ppvOut
);
192 FIXME("CLSID %s not supported\n", debugstr_guid(clsid
));
193 return CLASS_E_CLASSNOTAVAILABLE
;