[IEFRAME]
[reactos.git] / reactos / dll / win32 / atl / atl_main.c
1 /*
2 * Implementation of Active Template Library (atl.dll)
3 *
4 * Copyright 2004 Aric Stewart for CodeWeavers
5 * Copyright 2005 Jacek Caban
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #define WIN32_NO_STATUS
23 #define _INC_WINDOWS
24 #define COM_NO_WINDOWS_H
25
26 #include <stdio.h>
27
28 #define COBJMACROS
29
30 #include <windef.h>
31 #include <winbase.h>
32 #include <ole2.h>
33 #include <oleauto.h>
34
35 //#include "objidl.h"
36 #include <atlbase.h>
37 #include <atlwin.h>
38
39 #include <wine/debug.h>
40 #include <wine/unicode.h>
41
42 WINE_DEFAULT_DEBUG_CHANNEL(atl);
43
44 static HINSTANCE hInst;
45
46 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
47 {
48 TRACE("(0x%p, %d, %p)\n",hinstDLL,fdwReason,lpvReserved);
49
50 if (fdwReason == DLL_PROCESS_ATTACH) {
51 DisableThreadLibraryCalls(hinstDLL);
52 hInst = hinstDLL;
53 }
54 return TRUE;
55 }
56
57 #define ATLVer1Size FIELD_OFFSET(_ATL_MODULEW, dwAtlBuildVer)
58
59 HRESULT WINAPI AtlModuleInit(_ATL_MODULEW* pM, _ATL_OBJMAP_ENTRYW* p, HINSTANCE h)
60 {
61 INT i;
62 UINT size;
63
64 TRACE("(%p %p %p)\n", pM, p, h);
65
66 size = pM->cbSize;
67 switch (size)
68 {
69 case ATLVer1Size:
70 case sizeof(_ATL_MODULEW):
71 #ifdef _WIN64
72 case sizeof(_ATL_MODULEW) + sizeof(void *):
73 #endif
74 break;
75 default:
76 WARN("Unknown structure version (size %i)\n",size);
77 return E_INVALIDARG;
78 }
79
80 memset(pM,0,pM->cbSize);
81 pM->cbSize = size;
82 pM->m_hInst = h;
83 pM->m_hInstResource = h;
84 pM->m_hInstTypeLib = h;
85 pM->m_pObjMap = p;
86 pM->m_hHeap = GetProcessHeap();
87
88 InitializeCriticalSection(&pM->u.m_csTypeInfoHolder);
89 InitializeCriticalSection(&pM->m_csWindowCreate);
90 InitializeCriticalSection(&pM->m_csObjMap);
91
92 /* call mains */
93 i = 0;
94 if (pM->m_pObjMap != NULL && size > ATLVer1Size)
95 {
96 while (pM->m_pObjMap[i].pclsid != NULL)
97 {
98 TRACE("Initializing object %i %p\n",i,p[i].pfnObjectMain);
99 if (p[i].pfnObjectMain)
100 p[i].pfnObjectMain(TRUE);
101 i++;
102 }
103 }
104
105 return S_OK;
106 }
107
108 static _ATL_OBJMAP_ENTRYW_V1 *get_objmap_entry( _ATL_MODULEW *mod, unsigned int index )
109 {
110 _ATL_OBJMAP_ENTRYW_V1 *ret;
111
112 if (mod->cbSize == ATLVer1Size)
113 ret = (_ATL_OBJMAP_ENTRYW_V1 *)mod->m_pObjMap + index;
114 else
115 ret = (_ATL_OBJMAP_ENTRYW_V1 *)(mod->m_pObjMap + index);
116
117 if (!ret->pclsid) ret = NULL;
118 return ret;
119 }
120
121 HRESULT WINAPI AtlModuleLoadTypeLib(_ATL_MODULEW *pM, LPCOLESTR lpszIndex,
122 BSTR *pbstrPath, ITypeLib **ppTypeLib)
123 {
124 TRACE("(%p, %s, %p, %p)\n", pM, debugstr_w(lpszIndex), pbstrPath, ppTypeLib);
125
126 if (!pM)
127 return E_INVALIDARG;
128
129 return AtlLoadTypeLib(pM->m_hInstTypeLib, lpszIndex, pbstrPath, ppTypeLib);
130 }
131
132 HRESULT WINAPI AtlModuleTerm(_ATL_MODULE *pM)
133 {
134 _ATL_TERMFUNC_ELEM *iter, *tmp;
135
136 TRACE("(%p)\n", pM);
137
138 if (pM->cbSize > ATLVer1Size)
139 {
140 iter = pM->m_pTermFuncs;
141
142 while(iter) {
143 iter->pFunc(iter->dw);
144 tmp = iter;
145 iter = iter->pNext;
146 HeapFree(GetProcessHeap(), 0, tmp);
147 }
148 }
149
150 return S_OK;
151 }
152
153 HRESULT WINAPI AtlModuleAddTermFunc(_ATL_MODULEW *pM, _ATL_TERMFUNC *pFunc, DWORD_PTR dw)
154 {
155 _ATL_TERMFUNC_ELEM *termfunc_elem;
156
157 TRACE("(%p %p %ld)\n", pM, pFunc, dw);
158
159 if (pM->cbSize > ATLVer1Size)
160 {
161 termfunc_elem = HeapAlloc(GetProcessHeap(), 0, sizeof(_ATL_TERMFUNC_ELEM));
162 termfunc_elem->pFunc = pFunc;
163 termfunc_elem->dw = dw;
164 termfunc_elem->pNext = pM->m_pTermFuncs;
165
166 pM->m_pTermFuncs = termfunc_elem;
167 }
168
169 return S_OK;
170 }
171
172 HRESULT WINAPI AtlModuleRegisterClassObjects(_ATL_MODULEW *pM, DWORD dwClsContext,
173 DWORD dwFlags)
174 {
175 _ATL_OBJMAP_ENTRYW_V1 *obj;
176 int i=0;
177
178 TRACE("(%p %i %i)\n",pM, dwClsContext, dwFlags);
179
180 if (pM == NULL)
181 return E_INVALIDARG;
182
183 while ((obj = get_objmap_entry( pM, i++ )))
184 {
185 IUnknown* pUnknown;
186 HRESULT rc;
187
188 TRACE("Registering object %i\n",i);
189 if (obj->pfnGetClassObject)
190 {
191 rc = obj->pfnGetClassObject(obj->pfnCreateInstance, &IID_IUnknown,
192 (LPVOID*)&pUnknown);
193 if (SUCCEEDED (rc) )
194 {
195 rc = CoRegisterClassObject(obj->pclsid, pUnknown, dwClsContext,
196 dwFlags, &obj->dwRegister);
197
198 if (FAILED (rc) )
199 WARN("Failed to register object %i: 0x%08x\n", i, rc);
200
201 if (pUnknown)
202 IUnknown_Release(pUnknown);
203 }
204 }
205 }
206
207 return S_OK;
208 }
209
210 HRESULT WINAPI AtlModuleUnregisterServerEx(_ATL_MODULEW* pM, BOOL bUnRegTypeLib, const CLSID* pCLSID)
211 {
212 FIXME("(%p, %i, %p) stub\n", pM, bUnRegTypeLib, pCLSID);
213 return S_OK;
214 }
215
216 /***********************************************************************
217 * AtlModuleRegisterServer [ATL.@]
218 *
219 */
220 HRESULT WINAPI AtlModuleRegisterServer(_ATL_MODULEW* pM, BOOL bRegTypeLib, const CLSID* clsid)
221 {
222 const _ATL_OBJMAP_ENTRYW_V1 *obj;
223 int i;
224 HRESULT hRes;
225
226 TRACE("%p %d %s\n", pM, bRegTypeLib, debugstr_guid(clsid));
227
228 if (pM == NULL)
229 return E_INVALIDARG;
230
231 for (i = 0; (obj = get_objmap_entry( pM, i )) != NULL; i++) /* register CLSIDs */
232 {
233 if (!clsid || IsEqualCLSID(obj->pclsid, clsid))
234 {
235 TRACE("Registering clsid %s\n", debugstr_guid(obj->pclsid));
236 hRes = obj->pfnUpdateRegistry(TRUE); /* register */
237 if (FAILED(hRes))
238 return hRes;
239
240 if(pM->cbSize > ATLVer1Size) {
241 const struct _ATL_CATMAP_ENTRY *catmap;
242
243 catmap = ((const _ATL_OBJMAP_ENTRYW*)obj)->pfnGetCategoryMap();
244 if(catmap) {
245 hRes = AtlRegisterClassCategoriesHelper(obj->pclsid, catmap, TRUE);
246 if(FAILED(hRes))
247 return hRes;
248 }
249 }
250 }
251 }
252
253 if (bRegTypeLib)
254 {
255 hRes = AtlRegisterTypeLib(pM->m_hInstTypeLib, NULL);
256 if (FAILED(hRes))
257 return hRes;
258 }
259
260 return S_OK;
261 }
262
263 /***********************************************************************
264 * AtlModuleGetClassObject [ATL.@]
265 */
266 HRESULT WINAPI AtlModuleGetClassObject(_ATL_MODULEW *pm, REFCLSID rclsid,
267 REFIID riid, LPVOID *ppv)
268 {
269 _ATL_OBJMAP_ENTRYW_V1 *obj;
270 int i;
271 HRESULT hres = CLASS_E_CLASSNOTAVAILABLE;
272
273 TRACE("%p %s %s %p\n", pm, debugstr_guid(rclsid), debugstr_guid(riid), ppv);
274
275 if (pm == NULL)
276 return E_INVALIDARG;
277
278 for (i = 0; (obj = get_objmap_entry( pm, i )) != NULL; i++)
279 {
280 if (IsEqualCLSID(obj->pclsid, rclsid))
281 {
282 TRACE("found object %i\n", i);
283 if (obj->pfnGetClassObject)
284 {
285 if (!obj->pCF)
286 hres = obj->pfnGetClassObject(obj->pfnCreateInstance,
287 &IID_IUnknown,
288 (void **)&obj->pCF);
289 if (obj->pCF)
290 hres = IUnknown_QueryInterface(obj->pCF, riid, ppv);
291 break;
292 }
293 }
294 }
295
296 WARN("no class object found for %s\n", debugstr_guid(rclsid));
297
298 return hres;
299 }
300
301 /***********************************************************************
302 * AtlModuleGetClassObject [ATL.@]
303 */
304 HRESULT WINAPI AtlModuleRegisterTypeLib(_ATL_MODULEW *pm, LPCOLESTR lpszIndex)
305 {
306 TRACE("%p %s\n", pm, debugstr_w(lpszIndex));
307
308 if (!pm)
309 return E_INVALIDARG;
310
311 return AtlRegisterTypeLib(pm->m_hInstTypeLib, lpszIndex);
312 }
313
314 /***********************************************************************
315 * AtlModuleRevokeClassObjects [ATL.@]
316 */
317 HRESULT WINAPI AtlModuleRevokeClassObjects(_ATL_MODULEW *pm)
318 {
319 FIXME("%p\n", pm);
320 return E_FAIL;
321 }
322
323 /***********************************************************************
324 * AtlModuleUnregisterServer [ATL.@]
325 */
326 HRESULT WINAPI AtlModuleUnregisterServer(_ATL_MODULEW *pm, const CLSID *clsid)
327 {
328 FIXME("%p %s\n", pm, debugstr_guid(clsid));
329 return E_FAIL;
330 }
331
332 /***********************************************************************
333 * AtlModuleRegisterWndClassInfoA [ATL.@]
334 *
335 * See AtlModuleRegisterWndClassInfoW.
336 */
337 ATOM WINAPI AtlModuleRegisterWndClassInfoA(_ATL_MODULEA *pm, _ATL_WNDCLASSINFOA *wci, WNDPROC *pProc)
338 {
339 ATOM atom;
340
341 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
342
343 atom = wci->m_atom;
344 if (!atom)
345 {
346 WNDCLASSEXA wc;
347
348 TRACE("wci->m_wc.lpszClassName = %s\n", wci->m_wc.lpszClassName);
349
350 if (wci->m_lpszOrigName)
351 FIXME( "subclassing %s not implemented\n", debugstr_a(wci->m_lpszOrigName));
352
353 if (!wci->m_wc.lpszClassName)
354 {
355 snprintf(wci->m_szAutoName, sizeof(wci->m_szAutoName), "ATL%08lx", (UINT_PTR)wci);
356 TRACE("auto-generated class name %s\n", wci->m_szAutoName);
357 wci->m_wc.lpszClassName = wci->m_szAutoName;
358 }
359
360 atom = GetClassInfoExA(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
361 if (!atom)
362 {
363 wci->m_wc.hInstance = pm->m_hInst;
364 wci->m_wc.hCursor = LoadCursorA( wci->m_bSystemCursor ? NULL : pm->m_hInst,
365 wci->m_lpszCursorID );
366 atom = RegisterClassExA(&wci->m_wc);
367 }
368 wci->pWndProc = wci->m_wc.lpfnWndProc;
369 wci->m_atom = atom;
370 }
371
372 if (wci->m_lpszOrigName) *pProc = wci->pWndProc;
373
374 TRACE("returning 0x%04x\n", atom);
375 return atom;
376 }
377
378 /***********************************************************************
379 * AtlModuleRegisterWndClassInfoW [ATL.@]
380 *
381 * PARAMS
382 * pm [IO] Information about the module registering the window.
383 * wci [IO] Information about the window being registered.
384 * pProc [O] Window procedure of the registered class.
385 *
386 * RETURNS
387 * Atom representing the registered class.
388 *
389 * NOTES
390 * Can be called multiple times without error, unlike RegisterClassEx().
391 *
392 * If the class name is NULL, then a class with a name of "ATLxxxxxxxx" is
393 * registered, where the 'x's represent a unique value.
394 *
395 */
396 ATOM WINAPI AtlModuleRegisterWndClassInfoW(_ATL_MODULEW *pm, _ATL_WNDCLASSINFOW *wci, WNDPROC *pProc)
397 {
398 ATOM atom;
399
400 FIXME("%p %p %p semi-stub\n", pm, wci, pProc);
401
402 atom = wci->m_atom;
403 if (!atom)
404 {
405 WNDCLASSEXW wc;
406
407 TRACE("wci->m_wc.lpszClassName = %s\n", debugstr_w(wci->m_wc.lpszClassName));
408
409 if (wci->m_lpszOrigName)
410 FIXME( "subclassing %s not implemented\n", debugstr_w(wci->m_lpszOrigName));
411
412 if (!wci->m_wc.lpszClassName)
413 {
414 static const WCHAR szFormat[] = {'A','T','L','%','0','8','l','x',0};
415 snprintfW(wci->m_szAutoName, sizeof(wci->m_szAutoName)/sizeof(WCHAR), szFormat, (UINT_PTR)wci);
416 TRACE("auto-generated class name %s\n", debugstr_w(wci->m_szAutoName));
417 wci->m_wc.lpszClassName = wci->m_szAutoName;
418 }
419
420 atom = GetClassInfoExW(pm->m_hInst, wci->m_wc.lpszClassName, &wc);
421 if (!atom)
422 {
423 wci->m_wc.hInstance = pm->m_hInst;
424 wci->m_wc.hCursor = LoadCursorW( wci->m_bSystemCursor ? NULL : pm->m_hInst,
425 wci->m_lpszCursorID );
426 atom = RegisterClassExW(&wci->m_wc);
427 }
428 wci->pWndProc = wci->m_wc.lpfnWndProc;
429 wci->m_atom = atom;
430 }
431
432 if (wci->m_lpszOrigName) *pProc = wci->pWndProc;
433
434 TRACE("returning 0x%04x\n", atom);
435 return atom;
436 }
437
438 /***********************************************************************
439 * AtlModuleAddCreateWndData [ATL.@]
440 */
441 void WINAPI AtlModuleAddCreateWndData(_ATL_MODULEW *pM, _AtlCreateWndData *pData, void* pvObject)
442 {
443 TRACE("(%p, %p, %p)\n", pM, pData, pvObject);
444
445 pData->m_pThis = pvObject;
446 pData->m_dwThreadID = GetCurrentThreadId();
447
448 EnterCriticalSection(&pM->m_csWindowCreate);
449 pData->m_pNext = pM->m_pCreateWndList;
450 pM->m_pCreateWndList = pData;
451 LeaveCriticalSection(&pM->m_csWindowCreate);
452 }
453
454 /***********************************************************************
455 * AtlModuleExtractCreateWndData [ATL.@]
456 *
457 * NOTE: Tests show that this function extracts one of _AtlCreateWndData
458 * records from the current thread from a list
459 *
460 */
461 void* WINAPI AtlModuleExtractCreateWndData(_ATL_MODULEW *pM)
462 {
463 _AtlCreateWndData **ppData;
464 void *ret = NULL;
465
466 TRACE("(%p)\n", pM);
467
468 EnterCriticalSection(&pM->m_csWindowCreate);
469
470 for(ppData = &pM->m_pCreateWndList; *ppData!=NULL; ppData = &(*ppData)->m_pNext)
471 {
472 if ((*ppData)->m_dwThreadID == GetCurrentThreadId())
473 {
474 _AtlCreateWndData *pData = *ppData;
475 *ppData = pData->m_pNext;
476 ret = pData->m_pThis;
477 break;
478 }
479 }
480
481 LeaveCriticalSection(&pM->m_csWindowCreate);
482 return ret;
483 }
484
485 /***********************************************************************
486 * AtlModuleUpdateRegistryFromResourceD [ATL.@]
487 *
488 */
489 HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes,
490 BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg)
491 {
492 TRACE("(%p %s %d %p %p)\n", pM, debugstr_w(lpszRes), bRegister, pMapEntries, pReg);
493
494 return AtlUpdateRegistryFromResourceD(pM->m_hInst, lpszRes, bRegister, pMapEntries, pReg);
495 }
496
497 static HRESULT WINAPI RegistrarCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppvObject)
498 {
499 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject);
500
501 if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IClassFactory, riid)) {
502 *ppvObject = iface;
503 IClassFactory_AddRef( iface );
504 return S_OK;
505 }
506
507 return E_NOINTERFACE;
508 }
509
510 static ULONG WINAPI RegistrarCF_AddRef(IClassFactory *iface)
511 {
512 return 2;
513 }
514
515 static ULONG WINAPI RegistrarCF_Release(IClassFactory *iface)
516 {
517 return 1;
518 }
519
520 static HRESULT WINAPI RegistrarCF_CreateInstance(IClassFactory *iface, LPUNKNOWN pUnkOuter,
521 REFIID riid, void **ppv)
522 {
523 IRegistrar *registrar;
524 HRESULT hres;
525
526 TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
527
528 if(pUnkOuter) {
529 *ppv = NULL;
530 return CLASS_E_NOAGGREGATION;
531 }
532
533 hres = AtlCreateRegistrar(&registrar);
534 if(FAILED(hres))
535 return hres;
536
537 hres = IRegistrar_QueryInterface(registrar, riid, ppv);
538 IRegistrar_Release(registrar);
539 return hres;
540 }
541
542 static HRESULT WINAPI RegistrarCF_LockServer(IClassFactory *iface, BOOL lock)
543 {
544 TRACE("(%p)->(%x)\n", iface, lock);
545 return S_OK;
546 }
547
548 static const IClassFactoryVtbl IRegistrarCFVtbl = {
549 RegistrarCF_QueryInterface,
550 RegistrarCF_AddRef,
551 RegistrarCF_Release,
552 RegistrarCF_CreateInstance,
553 RegistrarCF_LockServer
554 };
555
556 static IClassFactory RegistrarCF = { &IRegistrarCFVtbl };
557
558 static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll,
559 LPCOLESTR wszId, BOOL do_register,
560 const struct _ATL_REGMAP_ENTRY* pMapEntries)
561 {
562 IRegistrar *registrar;
563 HRESULT hres;
564 const struct _ATL_REGMAP_ENTRY *pMapEntry;
565
566 static const WCHAR wszModule[] = {'M','O','D','U','L','E',0};
567 static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0};
568
569 if(pRegistrar) {
570 registrar = pRegistrar;
571 }else {
572 hres = AtlCreateRegistrar(&registrar);
573 if(FAILED(hres))
574 return hres;
575 }
576
577 IRegistrar_AddReplacement(registrar, wszModule, wszDll);
578
579 for (pMapEntry = pMapEntries; pMapEntry && pMapEntry->szKey; pMapEntry++)
580 IRegistrar_AddReplacement(registrar, pMapEntry->szKey, pMapEntry->szData);
581
582 if(do_register)
583 hres = IRegistrar_ResourceRegisterSz(registrar, wszDll, wszId, wszRegistry);
584 else
585 hres = IRegistrar_ResourceUnregisterSz(registrar, wszDll, wszId, wszRegistry);
586
587 if(registrar != pRegistrar)
588 IRegistrar_Release(registrar);
589 return hres;
590 }
591
592 static HRESULT do_register_server(BOOL do_register)
593 {
594 static const WCHAR CLSID_RegistrarW[] =
595 {'C','L','S','I','D','_','R','e','g','i','s','t','r','a','r',0};
596 static const WCHAR atl_dllW[] = {'a','t','l','.','d','l','l',0};
597
598 WCHAR clsid_str[40];
599 const struct _ATL_REGMAP_ENTRY reg_map[] = {{CLSID_RegistrarW, clsid_str}, {NULL,NULL}};
600
601 StringFromGUID2(&CLSID_Registrar, clsid_str, sizeof(clsid_str)/sizeof(WCHAR));
602 return do_register_dll_server(NULL, atl_dllW, MAKEINTRESOURCEW(101), do_register, reg_map);
603 }
604
605 /**************************************************************
606 * DllGetClassObject (ATL.2)
607 */
608 HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, LPVOID *ppvObject)
609 {
610 TRACE("(%s %s %p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppvObject);
611
612 if(IsEqualGUID(&CLSID_Registrar, clsid))
613 return IClassFactory_QueryInterface( &RegistrarCF, riid, ppvObject );
614
615 FIXME("Not supported class %s\n", debugstr_guid(clsid));
616 return CLASS_E_CLASSNOTAVAILABLE;
617 }
618
619 /***********************************************************************
620 * DllRegisterServer (ATL.@)
621 */
622 HRESULT WINAPI DllRegisterServer(void)
623 {
624 /* Note: we can't use __wine_register_server here because it uses CLSID_Registrar which isn't registred yet */
625 return do_register_server(TRUE);
626 }
627
628 /***********************************************************************
629 * DllUnRegisterServer (ATL.@)
630 */
631 HRESULT WINAPI DllUnregisterServer(void)
632 {
633 return do_register_server(FALSE);
634 }
635
636 /***********************************************************************
637 * DllCanUnloadNow (ATL.@)
638 */
639 HRESULT WINAPI DllCanUnloadNow(void)
640 {
641 return S_FALSE;
642 }
643
644 /***********************************************************************
645 * AtlGetVersion [ATL.@]
646 */
647 DWORD WINAPI AtlGetVersion(void *pReserved)
648 {
649 return _ATL_VER;
650 }
651
652 /**********************************************************************
653 * AtlAxWin class window procedure
654 */
655 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
656 {
657 if ( wMsg == WM_CREATE )
658 {
659 DWORD len = GetWindowTextLengthW( hWnd ) + 1;
660 WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
661 if (!ptr)
662 return 1;
663 GetWindowTextW( hWnd, ptr, len );
664 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
665 HeapFree( GetProcessHeap(), 0, ptr );
666 return 0;
667 }
668 return DefWindowProcW( hWnd, wMsg, wParam, lParam );
669 }
670
671 BOOL WINAPI AtlAxWinInit(void)
672 {
673 WNDCLASSEXW wcex;
674 const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n',0};
675
676 FIXME("semi-stub\n");
677
678 if ( FAILED( OleInitialize(NULL) ) )
679 return FALSE;
680
681 wcex.cbSize = sizeof(wcex);
682 wcex.style = CS_GLOBALCLASS;
683 wcex.cbClsExtra = 0;
684 wcex.cbWndExtra = 0;
685 wcex.hInstance = GetModuleHandleW( NULL );
686 wcex.hIcon = NULL;
687 wcex.hCursor = NULL;
688 wcex.hbrBackground = NULL;
689 wcex.lpszMenuName = NULL;
690 wcex.hIconSm = 0;
691
692 wcex.lpfnWndProc = AtlAxWin_wndproc;
693 wcex.lpszClassName = AtlAxWin;
694 if ( !RegisterClassExW( &wcex ) )
695 return FALSE;
696
697 return TRUE;
698 }