2 * Copyright 2012 Stefan Leichter
3 * Copyright 2012 Jacek Caban for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(atl
);
29 #define ATLVer1Size FIELD_OFFSET(_ATL_MODULEW, dwAtlBuildVer)
31 typedef unsigned char cpp_bool
;
33 static ICatRegister
*catreg
;
35 /***********************************************************************
36 * AtlAdvise [atl100.@]
38 HRESULT WINAPI
AtlAdvise(IUnknown
*pUnkCP
, IUnknown
*pUnk
, const IID
*iid
, DWORD
*pdw
)
40 IConnectionPointContainer
*container
;
44 TRACE("%p %p %p %p\n", pUnkCP
, pUnk
, iid
, pdw
);
49 hres
= IUnknown_QueryInterface(pUnkCP
, &IID_IConnectionPointContainer
, (void**)&container
);
53 hres
= IConnectionPointContainer_FindConnectionPoint(container
, iid
, &cp
);
54 IConnectionPointContainer_Release(container
);
58 hres
= IConnectionPoint_Advise(cp
, pUnk
, pdw
);
59 IConnectionPoint_Release(cp
);
63 /***********************************************************************
64 * AtlUnadvise [atl100.@]
66 HRESULT WINAPI
AtlUnadvise(IUnknown
*pUnkCP
, const IID
*iid
, DWORD dw
)
68 IConnectionPointContainer
*container
;
72 TRACE("%p %p %ld\n", pUnkCP
, iid
, dw
);
77 hres
= IUnknown_QueryInterface(pUnkCP
, &IID_IConnectionPointContainer
, (void**)&container
);
81 hres
= IConnectionPointContainer_FindConnectionPoint(container
, iid
, &cp
);
82 IConnectionPointContainer_Release(container
);
86 hres
= IConnectionPoint_Unadvise(cp
, dw
);
87 IConnectionPoint_Release(cp
);
91 /***********************************************************************
92 * AtlFreeMarshalStream [atl100.@]
94 HRESULT WINAPI
AtlFreeMarshalStream(IStream
*stm
)
100 /***********************************************************************
101 * AtlMarshalPtrInProc [atl100.@]
103 HRESULT WINAPI
AtlMarshalPtrInProc(IUnknown
*pUnk
, const IID
*iid
, IStream
**pstm
)
105 FIXME("%p %p %p\n", pUnk
, iid
, pstm
);
109 /***********************************************************************
110 * AtlUnmarshalPtr [atl100.@]
112 HRESULT WINAPI
AtlUnmarshalPtr(IStream
*stm
, const IID
*iid
, IUnknown
**ppUnk
)
114 FIXME("%p %p %p\n", stm
, iid
, ppUnk
);
118 /***********************************************************************
119 * AtlCreateTargetDC [atl100.@]
121 HDC WINAPI
AtlCreateTargetDC( HDC hdc
, DVTARGETDEVICE
*dv
)
123 const WCHAR
*driver
= NULL
, *device
= NULL
, *port
= NULL
;
124 DEVMODEW
*devmode
= NULL
;
126 TRACE( "(%p, %p)\n", hdc
, dv
);
130 if (dv
->tdDriverNameOffset
) driver
= (WCHAR
*)((char *)dv
+ dv
->tdDriverNameOffset
);
131 if (dv
->tdDeviceNameOffset
) device
= (WCHAR
*)((char *)dv
+ dv
->tdDeviceNameOffset
);
132 if (dv
->tdPortNameOffset
) port
= (WCHAR
*)((char *)dv
+ dv
->tdPortNameOffset
);
133 if (dv
->tdExtDevmodeOffset
) devmode
= (DEVMODEW
*)((char *)dv
+ dv
->tdExtDevmodeOffset
);
140 return CreateDCW( driver
, device
, port
, devmode
);
143 /***********************************************************************
144 * AtlHiMetricToPixel [atl100.@]
146 void WINAPI
AtlHiMetricToPixel(const SIZEL
* lpHiMetric
, SIZEL
* lpPix
)
148 HDC dc
= GetDC(NULL
);
149 lpPix
->cx
= lpHiMetric
->cx
* GetDeviceCaps( dc
, LOGPIXELSX
) / 100;
150 lpPix
->cy
= lpHiMetric
->cy
* GetDeviceCaps( dc
, LOGPIXELSY
) / 100;
151 ReleaseDC( NULL
, dc
);
154 /***********************************************************************
155 * AtlPixelToHiMetric [atl100.@]
157 void WINAPI
AtlPixelToHiMetric(const SIZEL
* lpPix
, SIZEL
* lpHiMetric
)
159 HDC dc
= GetDC(NULL
);
160 lpHiMetric
->cx
= 100 * lpPix
->cx
/ GetDeviceCaps( dc
, LOGPIXELSX
);
161 lpHiMetric
->cy
= 100 * lpPix
->cy
/ GetDeviceCaps( dc
, LOGPIXELSY
);
162 ReleaseDC( NULL
, dc
);
165 /***********************************************************************
166 * AtlComPtrAssign [atl100.@]
168 IUnknown
* WINAPI
AtlComPtrAssign(IUnknown
** pp
, IUnknown
*p
)
170 TRACE("(%p %p)\n", pp
, p
);
172 if (p
) IUnknown_AddRef(p
);
173 if (*pp
) IUnknown_Release(*pp
);
178 /***********************************************************************
179 * AtlComQIPtrAssign [atl100.@]
181 IUnknown
* WINAPI
AtlComQIPtrAssign(IUnknown
** pp
, IUnknown
*p
, REFIID riid
)
183 IUnknown
*new_p
= NULL
;
185 TRACE("(%p %p %s)\n", pp
, p
, debugstr_guid(riid
));
187 if (p
) IUnknown_QueryInterface(p
, riid
, (void **)&new_p
);
188 if (*pp
) IUnknown_Release(*pp
);
193 /***********************************************************************
194 * AtlInternalQueryInterface [atl100.@]
196 HRESULT WINAPI
AtlInternalQueryInterface(void* this, const _ATL_INTMAP_ENTRY
* pEntries
, REFIID iid
, void** ppvObject
)
199 HRESULT rc
= E_NOINTERFACE
;
200 TRACE("(%p, %p, %s, %p)\n",this, pEntries
, debugstr_guid(iid
), ppvObject
);
202 if (IsEqualGUID(iid
,&IID_IUnknown
))
204 TRACE("Returning IUnknown\n");
205 *ppvObject
= ((LPSTR
)this+pEntries
[0].dw
);
206 IUnknown_AddRef((IUnknown
*)*ppvObject
);
210 while (pEntries
[i
].pFunc
!= 0)
212 TRACE("Trying entry %i (%s %Ix %p)\n",i
,debugstr_guid(pEntries
[i
].piid
),
213 pEntries
[i
].dw
, pEntries
[i
].pFunc
);
215 if (!pEntries
[i
].piid
|| IsEqualGUID(iid
,pEntries
[i
].piid
))
218 if (pEntries
[i
].pFunc
== (_ATL_CREATORARGFUNC
*)1)
221 *ppvObject
= ((LPSTR
)this+pEntries
[i
].dw
);
222 IUnknown_AddRef((IUnknown
*)*ppvObject
);
228 rc
= pEntries
[i
].pFunc(this, iid
, ppvObject
, pEntries
[i
].dw
);
229 if(rc
==S_OK
|| pEntries
[i
].piid
)
235 TRACE("Done returning (0x%lx)\n",rc
);
239 /***********************************************************************
240 * AtlIPersistStreamInit_Load [atl100.@]
242 HRESULT WINAPI
AtlIPersistStreamInit_Load( LPSTREAM pStm
, ATL_PROPMAP_ENTRY
*pMap
,
243 void *pThis
, IUnknown
*pUnk
)
245 FIXME("(%p, %p, %p, %p)\n", pStm
, pMap
, pThis
, pUnk
);
250 /***********************************************************************
251 * AtlIPersistStreamInit_Save [atl100.@]
253 HRESULT WINAPI
AtlIPersistStreamInit_Save(LPSTREAM pStm
, BOOL fClearDirty
,
254 ATL_PROPMAP_ENTRY
*pMap
, void *pThis
,
257 FIXME("(%p, %d, %p, %p, %p)\n", pStm
, fClearDirty
, pMap
, pThis
, pUnk
);
262 /***********************************************************************
263 * AtlIPersistPropertyBag_Load [atl100.@]
265 HRESULT WINAPI
AtlIPersistPropertyBag_Load(LPPROPERTYBAG pPropBag
, LPERRORLOG pErrorLog
,
266 ATL_PROPMAP_ENTRY
*pMap
, void *pThis
,
269 FIXME("(%p, %p, %p, %p, %p)\n", pPropBag
, pErrorLog
, pMap
, pThis
, pUnk
);
274 /***********************************************************************
275 * AtlIPersistPropertyBag_Save [atl100.@]
277 HRESULT WINAPI
AtlIPersistPropertyBag_Save(LPPROPERTYBAG pPropBag
, BOOL fClearDirty
,
278 BOOL fSaveAll
, ATL_PROPMAP_ENTRY
*pMap
,
279 void *pThis
, IUnknown
*pUnk
)
281 FIXME("(%p, %d, %d, %p, %p, %p)\n", pPropBag
, fClearDirty
, fSaveAll
, pMap
, pThis
, pUnk
);
286 /***********************************************************************
287 * AtlModuleAddTermFunc [atl100.@]
289 HRESULT WINAPI
AtlModuleAddTermFunc(_ATL_MODULE
*pM
, _ATL_TERMFUNC
*pFunc
, DWORD_PTR dw
)
291 _ATL_TERMFUNC_ELEM
*termfunc_elem
;
293 TRACE("version %04x (%p %p %Id)\n", _ATL_VER
, pM
, pFunc
, dw
);
295 if (_ATL_VER
> _ATL_VER_30
|| pM
->cbSize
> ATLVer1Size
) {
296 termfunc_elem
= malloc(sizeof(*termfunc_elem
));
297 termfunc_elem
->pFunc
= pFunc
;
298 termfunc_elem
->dw
= dw
;
299 termfunc_elem
->pNext
= pM
->m_pTermFuncs
;
301 pM
->m_pTermFuncs
= termfunc_elem
;
307 #if _ATL_VER > _ATL_VER_30
309 /***********************************************************************
310 * AtlCallTermFunc [atl100.@]
312 void WINAPI
AtlCallTermFunc(_ATL_MODULE
*pM
)
314 _ATL_TERMFUNC_ELEM
*iter
= pM
->m_pTermFuncs
, *tmp
;
319 iter
->pFunc(iter
->dw
);
325 pM
->m_pTermFuncs
= NULL
;
330 /***********************************************************************
331 * AtlLoadTypeLib [atl100.56]
333 HRESULT WINAPI
AtlLoadTypeLib(HINSTANCE inst
, LPCOLESTR lpszIndex
,
334 BSTR
*pbstrPath
, ITypeLib
**ppTypeLib
)
336 size_t path_len
, index_len
;
337 ITypeLib
*typelib
= NULL
;
341 TRACE("(%p %s %p %p)\n", inst
, debugstr_w(lpszIndex
), pbstrPath
, ppTypeLib
);
343 index_len
= lpszIndex
? lstrlenW(lpszIndex
) : 0;
344 path
= malloc((MAX_PATH
+index_len
)*sizeof(WCHAR
) + sizeof(L
".tlb"));
346 return E_OUTOFMEMORY
;
348 path_len
= GetModuleFileNameW(inst
, path
, MAX_PATH
);
351 return HRESULT_FROM_WIN32(GetLastError());
355 memcpy(path
+path_len
, lpszIndex
, (index_len
+1)*sizeof(WCHAR
));
357 hres
= LoadTypeLib(path
, &typelib
);
361 for(ptr
= path
+path_len
-1; ptr
> path
&& *ptr
!= '\\' && *ptr
!= '.'; ptr
--);
364 lstrcpyW(ptr
, L
".tlb");
365 hres
= LoadTypeLib(path
, &typelib
);
368 if(SUCCEEDED(hres
)) {
369 *pbstrPath
= SysAllocString(path
);
371 ITypeLib_Release(typelib
);
372 hres
= E_OUTOFMEMORY
;
380 *ppTypeLib
= typelib
;
384 #if _ATL_VER <= _ATL_VER_80
386 /***********************************************************************
387 * AtlRegisterTypeLib [atl80.19]
389 HRESULT WINAPI
AtlRegisterTypeLib(HINSTANCE inst
, const WCHAR
*index
)
395 TRACE("(%p %s)\n", inst
, debugstr_w(index
));
397 hres
= AtlLoadTypeLib(inst
, index
, &path
, &typelib
);
401 hres
= RegisterTypeLib(typelib
, path
, NULL
); /* FIXME: pass help directory */
402 ITypeLib_Release(typelib
);
409 #if _ATL_VER > _ATL_VER_30
411 /***********************************************************************
412 * AtlWinModuleInit [atl100.65]
414 HRESULT WINAPI
AtlWinModuleInit(_ATL_WIN_MODULE
*winmod
)
416 TRACE("(%p)\n", winmod
);
418 if(winmod
->cbSize
!= sizeof(*winmod
))
421 InitializeCriticalSection(&winmod
->m_csWindowCreate
);
422 winmod
->m_pCreateWndList
= NULL
;
426 /***********************************************************************
427 * AtlWinModuleAddCreateWndData [atl100.43]
429 void WINAPI
AtlWinModuleAddCreateWndData(_ATL_WIN_MODULE
*pM
, _AtlCreateWndData
*pData
, void *pvObject
)
431 TRACE("(%p, %p, %p)\n", pM
, pData
, pvObject
);
433 pData
->m_pThis
= pvObject
;
434 pData
->m_dwThreadID
= GetCurrentThreadId();
436 EnterCriticalSection(&pM
->m_csWindowCreate
);
437 pData
->m_pNext
= pM
->m_pCreateWndList
;
438 pM
->m_pCreateWndList
= pData
;
439 LeaveCriticalSection(&pM
->m_csWindowCreate
);
442 /***********************************************************************
443 * AtlWinModuleExtractCreateWndData [atl100.44]
445 void* WINAPI
AtlWinModuleExtractCreateWndData(_ATL_WIN_MODULE
*winmod
)
447 _AtlCreateWndData
*iter
, *prev
= NULL
;
450 TRACE("(%p)\n", winmod
);
452 thread_id
= GetCurrentThreadId();
454 EnterCriticalSection(&winmod
->m_csWindowCreate
);
456 for(iter
= winmod
->m_pCreateWndList
; iter
&& iter
->m_dwThreadID
!= thread_id
; iter
= iter
->m_pNext
)
460 prev
->m_pNext
= iter
->m_pNext
;
462 winmod
->m_pCreateWndList
= iter
->m_pNext
;
465 LeaveCriticalSection(&winmod
->m_csWindowCreate
);
467 return iter
? iter
->m_pThis
: NULL
;
470 /***********************************************************************
471 * AtlComModuleGetClassObject [atl100.15]
473 #if _ATL_VER < _ATL_VER_110
474 HRESULT WINAPI
AtlComModuleGetClassObject(_ATL_COM_MODULE
*pm
, REFCLSID rclsid
, REFIID riid
, void **ppv
)
476 _ATL_OBJMAP_ENTRY
**iter
;
479 TRACE("(%p %s %s %p)\n", pm
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
484 for(iter
= pm
->m_ppAutoObjMapFirst
; iter
< pm
->m_ppAutoObjMapLast
; iter
++) {
485 if(*iter
&& IsEqualCLSID((*iter
)->pclsid
, rclsid
) && (*iter
)->pfnGetClassObject
) {
487 hres
= (*iter
)->pfnGetClassObject((*iter
)->pfnCreateInstance
, &IID_IUnknown
, (void**)&(*iter
)->pCF
);
489 hres
= IUnknown_QueryInterface((*iter
)->pCF
, riid
, ppv
);
490 TRACE("returning %p (%08lx)\n", *ppv
, hres
);
495 WARN("Class %s not found\n", debugstr_guid(rclsid
));
496 return CLASS_E_CLASSNOTAVAILABLE
;
499 HRESULT WINAPI
AtlComModuleGetClassObject(_ATL_COM_MODULE
*pm
, REFCLSID rclsid
, REFIID riid
, void **ppv
)
501 _ATL_OBJMAP_ENTRY_EX
**iter
;
504 TRACE("(%p %s %s %p)\n", pm
, debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
509 for(iter
= pm
->m_ppAutoObjMapFirst
; iter
< pm
->m_ppAutoObjMapLast
; iter
++) {
510 if(*iter
&& IsEqualCLSID((*iter
)->pclsid
, rclsid
) && (*iter
)->pfnGetClassObject
) {
511 if(!(*iter
)->pCache
->pCF
)
512 hres
= (*iter
)->pfnGetClassObject((*iter
)->pfnCreateInstance
, &IID_IUnknown
, (void**)&(*iter
)->pCache
->pCF
);
513 if((*iter
)->pCache
->pCF
)
514 hres
= IUnknown_QueryInterface((*iter
)->pCache
->pCF
, riid
, ppv
);
515 TRACE("returning %p (%08lx)\n", *ppv
, hres
);
520 WARN("Class %s not found\n", debugstr_guid(rclsid
));
521 return CLASS_E_CLASSNOTAVAILABLE
;
525 /***********************************************************************
526 * AtlComModuleRegisterClassObjects [atl100.17]
528 #if _ATL_VER < _ATL_VER_110
529 HRESULT WINAPI
AtlComModuleRegisterClassObjects(_ATL_COM_MODULE
*module
, DWORD context
, DWORD flags
)
531 _ATL_OBJMAP_ENTRY
**iter
;
535 TRACE("(%p %lx %lx)\n", module
, context
, flags
);
540 for(iter
= module
->m_ppAutoObjMapFirst
; iter
< module
->m_ppAutoObjMapLast
; iter
++) {
541 if(!(*iter
) || !(*iter
)->pfnGetClassObject
)
544 hres
= (*iter
)->pfnGetClassObject((*iter
)->pfnCreateInstance
, &IID_IUnknown
, (void**)&unk
);
548 hres
= CoRegisterClassObject((*iter
)->pclsid
, unk
, context
, flags
, &(*iter
)->dwRegister
);
549 IUnknown_Release(unk
);
557 HRESULT WINAPI
AtlComModuleRegisterClassObjects(_ATL_COM_MODULE
*module
, DWORD context
, DWORD flags
)
559 _ATL_OBJMAP_ENTRY_EX
**iter
;
563 TRACE("(%p %lx %lx)\n", module
, context
, flags
);
568 for(iter
= module
->m_ppAutoObjMapFirst
; iter
< module
->m_ppAutoObjMapLast
; iter
++) {
569 if(!(*iter
) || !(*iter
)->pfnGetClassObject
)
572 hres
= (*iter
)->pfnGetClassObject((*iter
)->pfnCreateInstance
, &IID_IUnknown
, (void**)&unk
);
576 hres
= CoRegisterClassObject((*iter
)->pclsid
, unk
, context
, flags
, &(*iter
)->pCache
->dwRegister
);
577 IUnknown_Release(unk
);
586 /***********************************************************************
587 * AtlComModuleRevokeClassObjects [atl100.20]
589 #if _ATL_VER < _ATL_VER_110
590 HRESULT WINAPI
AtlComModuleRevokeClassObjects(_ATL_COM_MODULE
*module
)
592 _ATL_OBJMAP_ENTRY
**iter
;
595 TRACE("(%p)\n", module
);
600 for(iter
= module
->m_ppAutoObjMapFirst
; iter
< module
->m_ppAutoObjMapLast
; iter
++) {
604 hres
= CoRevokeClassObject((*iter
)->dwRegister
);
612 HRESULT WINAPI
AtlComModuleRevokeClassObjects(_ATL_COM_MODULE
*module
)
614 _ATL_OBJMAP_ENTRY_EX
**iter
;
617 TRACE("(%p)\n", module
);
622 for(iter
= module
->m_ppAutoObjMapFirst
; iter
< module
->m_ppAutoObjMapLast
; iter
++) {
626 hres
= CoRevokeClassObject((*iter
)->pCache
->dwRegister
);
635 /***********************************************************************
636 * AtlComModuleUnregisterServer [atl100.22]
638 #if _ATL_VER < _ATL_VER_110
639 HRESULT WINAPI
AtlComModuleUnregisterServer(_ATL_COM_MODULE
*mod
, BOOL bRegTypeLib
, const CLSID
*clsid
)
641 const struct _ATL_CATMAP_ENTRY
*catmap
;
642 _ATL_OBJMAP_ENTRY
**iter
;
645 TRACE("(%p %x %s)\n", mod
, bRegTypeLib
, debugstr_guid(clsid
));
647 for(iter
= mod
->m_ppAutoObjMapFirst
; iter
< mod
->m_ppAutoObjMapLast
; iter
++) {
648 if(!*iter
|| (clsid
&& !IsEqualCLSID((*iter
)->pclsid
, clsid
)))
651 TRACE("Unregistering clsid %s\n", debugstr_guid((*iter
)->pclsid
));
653 catmap
= (*iter
)->pfnGetCategoryMap();
655 hres
= AtlRegisterClassCategoriesHelper((*iter
)->pclsid
, catmap
, FALSE
);
660 hres
= (*iter
)->pfnUpdateRegistry(FALSE
);
670 hres
= AtlLoadTypeLib(mod
->m_hInstTypeLib
, NULL
, &path
, &typelib
);
675 hres
= ITypeLib_GetLibAttr(typelib
, &attr
);
676 if(SUCCEEDED(hres
)) {
677 hres
= UnRegisterTypeLib(&attr
->guid
, attr
->wMajorVerNum
, attr
->wMinorVerNum
, attr
->lcid
, attr
->syskind
);
678 ITypeLib_ReleaseTLibAttr(typelib
, attr
);
680 ITypeLib_Release(typelib
);
688 HRESULT WINAPI
AtlComModuleUnregisterServer(_ATL_COM_MODULE
*mod
, BOOL bRegTypeLib
, const CLSID
*clsid
)
690 const struct _ATL_CATMAP_ENTRY
*catmap
;
691 _ATL_OBJMAP_ENTRY_EX
**iter
;
694 TRACE("(%p %x %s)\n", mod
, bRegTypeLib
, debugstr_guid(clsid
));
696 for(iter
= mod
->m_ppAutoObjMapFirst
; iter
< mod
->m_ppAutoObjMapLast
; iter
++) {
697 if(!*iter
|| (clsid
&& !IsEqualCLSID((*iter
)->pclsid
, clsid
)))
700 TRACE("Unregistering clsid %s\n", debugstr_guid((*iter
)->pclsid
));
702 catmap
= (*iter
)->pfnGetCategoryMap();
704 hres
= AtlRegisterClassCategoriesHelper((*iter
)->pclsid
, catmap
, FALSE
);
709 hres
= (*iter
)->pfnUpdateRegistry(FALSE
);
719 hres
= AtlLoadTypeLib(mod
->m_hInstTypeLib
, NULL
, &path
, &typelib
);
724 hres
= ITypeLib_GetLibAttr(typelib
, &attr
);
725 if(SUCCEEDED(hres
)) {
726 hres
= UnRegisterTypeLib(&attr
->guid
, attr
->wMajorVerNum
, attr
->wMinorVerNum
, attr
->lcid
, attr
->syskind
);
727 ITypeLib_ReleaseTLibAttr(typelib
, attr
);
729 ITypeLib_Release(typelib
);
740 /***********************************************************************
741 * AtlRegisterClassCategoriesHelper [atl100.49]
743 HRESULT WINAPI
AtlRegisterClassCategoriesHelper(REFCLSID clsid
, const struct _ATL_CATMAP_ENTRY
*catmap
, BOOL reg
)
745 const struct _ATL_CATMAP_ENTRY
*iter
;
748 TRACE("(%s %p %x)\n", debugstr_guid(clsid
), catmap
, reg
);
754 ICatRegister
*new_catreg
;
756 hres
= CoCreateInstance(&CLSID_StdComponentCategoriesMgr
, NULL
, CLSCTX_INPROC_SERVER
,
757 &IID_ICatRegister
, (void**)&new_catreg
);
761 if(InterlockedCompareExchangePointer((void**)&catreg
, new_catreg
, NULL
))
762 ICatRegister_Release(new_catreg
);
765 for(iter
= catmap
; iter
->iType
!= _ATL_CATMAP_ENTRY_END
; iter
++) {
766 CATID catid
= *iter
->pcatid
; /* For stupid lack of const in ICatRegister declaration. */
768 if(iter
->iType
== _ATL_CATMAP_ENTRY_IMPLEMENTED
) {
770 hres
= ICatRegister_RegisterClassImplCategories(catreg
, clsid
, 1, &catid
);
772 hres
= ICatRegister_UnRegisterClassImplCategories(catreg
, clsid
, 1, &catid
);
775 hres
= ICatRegister_RegisterClassReqCategories(catreg
, clsid
, 1, &catid
);
777 hres
= ICatRegister_UnRegisterClassReqCategories(catreg
, clsid
, 1, &catid
);
784 WCHAR reg_path
[256] = L
"CLSID\\", *ptr
= reg_path
+6;
786 ptr
+= StringFromGUID2(clsid
, ptr
, 64)-1;
789 lstrcpyW(ptr
, L
"Implemented Categories");
790 RegDeleteKeyW(HKEY_CLASSES_ROOT
, reg_path
);
792 lstrcpyW(ptr
, L
"Required Categories");
793 RegDeleteKeyW(HKEY_CLASSES_ROOT
, reg_path
);
799 /***********************************************************************
800 * AtlWaitWithMessageLoop [atl100.24]
802 BOOL WINAPI
AtlWaitWithMessageLoop(HANDLE handle
)
807 TRACE("(%p)\n", handle
);
810 res
= MsgWaitForMultipleObjects(1, &handle
, FALSE
, INFINITE
, QS_ALLINPUT
);
814 case WAIT_OBJECT_0
+1:
815 if(GetMessageW(&msg
, NULL
, 0, 0) < 0)
818 TranslateMessage(&msg
);
819 DispatchMessageW(&msg
);
827 static HRESULT
get_default_source(ITypeLib
*typelib
, const CLSID
*clsid
, IID
*iid
)
829 ITypeInfo
*typeinfo
, *src_typeinfo
= NULL
;
835 hres
= ITypeLib_GetTypeInfoOfGuid(typelib
, clsid
, &typeinfo
);
839 hres
= ITypeInfo_GetTypeAttr(typeinfo
, &attr
);
841 ITypeInfo_Release(typeinfo
);
845 for(i
=0; i
< attr
->cImplTypes
; i
++) {
846 hres
= ITypeInfo_GetImplTypeFlags(typeinfo
, i
, &type_flags
);
847 if(SUCCEEDED(hres
) && type_flags
== (IMPLTYPEFLAG_FSOURCE
|IMPLTYPEFLAG_FDEFAULT
)) {
850 hres
= ITypeInfo_GetRefTypeOfImplType(typeinfo
, i
, &ref
);
852 hres
= ITypeInfo_GetRefTypeInfo(typeinfo
, ref
, &src_typeinfo
);
857 ITypeInfo_ReleaseTypeAttr(typeinfo
, attr
);
858 ITypeInfo_Release(typeinfo
);
867 hres
= ITypeInfo_GetTypeAttr(src_typeinfo
, &attr
);
868 if(SUCCEEDED(hres
)) {
870 ITypeInfo_ReleaseTypeAttr(src_typeinfo
, attr
);
872 ITypeInfo_Release(src_typeinfo
);
876 /***********************************************************************
877 * AtlGetObjectSourceInterface [atl100.54]
879 HRESULT WINAPI
AtlGetObjectSourceInterface(IUnknown
*unk
, GUID
*libid
, IID
*iid
, unsigned short *major
, unsigned short *minor
)
881 IProvideClassInfo2
*classinfo
;
888 TRACE("(%p %p %p %p %p)\n", unk
, libid
, iid
, major
, minor
);
890 hres
= IUnknown_QueryInterface(unk
, &IID_IDispatch
, (void**)&disp
);
894 hres
= IDispatch_GetTypeInfo(disp
, 0, 0, &typeinfo
);
895 IDispatch_Release(disp
);
899 hres
= ITypeInfo_GetContainingTypeLib(typeinfo
, &typelib
, 0);
900 ITypeInfo_Release(typeinfo
);
901 if(SUCCEEDED(hres
)) {
904 hres
= ITypeLib_GetLibAttr(typelib
, &attr
);
905 if(SUCCEEDED(hres
)) {
907 *major
= attr
->wMajorVerNum
;
908 *minor
= attr
->wMinorVerNum
;
909 ITypeLib_ReleaseTLibAttr(typelib
, attr
);
911 ITypeLib_Release(typelib
);
917 hres
= IUnknown_QueryInterface(unk
, &IID_IProvideClassInfo2
, (void**)&classinfo
);
918 if(SUCCEEDED(hres
)) {
919 hres
= IProvideClassInfo2_GetGUID(classinfo
, GUIDKIND_DEFAULT_SOURCE_DISP_IID
, iid
);
920 IProvideClassInfo2_Release(classinfo
);
921 ITypeLib_Release(typelib
);
925 hres
= IUnknown_QueryInterface(unk
, &IID_IPersist
, (void**)&persist
);
926 if(SUCCEEDED(hres
)) {
929 hres
= IPersist_GetClassID(persist
, &clsid
);
931 hres
= get_default_source(typelib
, &clsid
, iid
);
932 IPersist_Release(persist
);
938 #if _ATL_VER >= _ATL_VER90
940 /***********************************************************************
941 * AtlSetPerUserRegistration [atl100.67]
943 HRESULT WINAPI
AtlSetPerUserRegistration(cpp_bool bEnable
)
945 FIXME("stub: bEnable: %d\n", bEnable
);
949 /***********************************************************************
950 * AtlGetPerUserRegistration [atl100.68]
952 HRESULT WINAPI
AtlGetPerUserRegistration(cpp_bool
*pbEnabled
)
954 FIXME("stub: returning false\n");
961 /***********************************************************************
962 * AtlGetVersion [atl100.@]
964 DWORD WINAPI
AtlGetVersion(void *pReserved
)
966 TRACE("version %04x (%p)\n", _ATL_VER
, pReserved
);
970 BOOL WINAPI
DllMain(HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
972 TRACE("(0x%p, %ld, %p)\n", hinstDLL
, fdwReason
, lpvReserved
);
975 case DLL_PROCESS_ATTACH
:
976 DisableThreadLibraryCalls(hinstDLL
);
978 case DLL_PROCESS_DETACH
:
979 if (lpvReserved
) break;
981 ICatRegister_Release(catreg
);