gdi32: Reject invalid DIB depths in CreateDIBSection.
[wine.git] / dlls / atl / atl_ax.c
blobd9d60a56b9edb63f89e8c6a57dfc9b31fea67a84
1 /*
2 * Active Template Library ActiveX functions (atl.dll)
4 * Copyright 2006 Andrey Turkin
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
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winerror.h"
29 #include "winuser.h"
30 #include "wine/debug.h"
31 #include "objbase.h"
32 #include "objidl.h"
33 #include "ole2.h"
34 #include "exdisp.h"
35 #include "atlbase.h"
36 #include "atliface.h"
37 #include "atlwin.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(atl);
43 typedef struct IOCS {
44 const IOleClientSiteVtbl *lpOleClientSiteVtbl;
45 const IOleContainerVtbl *lpOleContainerVtbl;
46 const IOleInPlaceSiteWindowlessVtbl *lpOleInPlaceSiteWindowlessVtbl;
47 const IOleInPlaceFrameVtbl *lpOleInPlaceFrameVtbl;
48 const IOleControlSiteVtbl *lpOleControlSiteVtbl;
50 LONG ref;
51 HWND hWnd;
52 IOleObject *control;
53 RECT size;
54 WNDPROC OrigWndProc;
55 BOOL fActive, fInPlace, fWindowless;
56 } IOCS;
58 /**********************************************************************
59 * AtlAxWin class window procedure
61 static LRESULT CALLBACK AtlAxWin_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
63 if ( wMsg == WM_CREATE )
65 DWORD len = GetWindowTextLengthW( hWnd ) + 1;
66 WCHAR *ptr = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
67 if (!ptr)
68 return 1;
69 GetWindowTextW( hWnd, ptr, len );
70 AtlAxCreateControlEx( ptr, hWnd, NULL, NULL, NULL, NULL, NULL );
71 HeapFree( GetProcessHeap(), 0, ptr );
72 return 0;
74 return DefWindowProcW( hWnd, wMsg, wParam, lParam );
77 /***********************************************************************
78 * AtlAxWinInit [ATL.@]
79 * Initializes the control-hosting code: registering the AtlAxWin,
80 * AtlAxWin7 and AtlAxWinLic7 window classes and some messages.
82 * RETURNS
83 * TRUE or FALSE
86 BOOL WINAPI AtlAxWinInit(void)
88 WNDCLASSEXW wcex;
89 const WCHAR AtlAxWin[] = {'A','t','l','A','x','W','i','n',0};
91 FIXME("semi-stub\n");
93 if ( FAILED( OleInitialize(NULL) ) )
94 return FALSE;
96 wcex.cbSize = sizeof(wcex);
97 wcex.style = 0;
98 wcex.cbClsExtra = 0;
99 wcex.cbWndExtra = 0;
100 wcex.hInstance = GetModuleHandleW( NULL );
101 wcex.hIcon = NULL;
102 wcex.hCursor = NULL;
103 wcex.hbrBackground = NULL;
104 wcex.lpszMenuName = NULL;
105 wcex.hIconSm = 0;
107 wcex.lpfnWndProc = AtlAxWin_wndproc;
108 wcex.lpszClassName = AtlAxWin;
109 if ( !RegisterClassExW( &wcex ) )
110 return FALSE;
112 return TRUE;
115 /***********************************************************************
116 * Atl container component implementation
120 static ULONG IOCS_AddRef(IOCS *This)
122 ULONG ref = InterlockedIncrement(&This->ref);
124 TRACE( "(%p) : AddRef from %d\n", This, ref - 1 );
126 return ref;
129 #define THIS2IOLECLIENTSITE(This) ((IOleClientSite*)&(This)->lpOleClientSiteVtbl)
130 #define THIS2IOLECONTAINER(This) (&(This)->lpOleContainerVtbl)
131 #define THIS2IOLEINPLACESITEWINDOWLESS(This) (&(This)->lpOleInPlaceSiteWindowlessVtbl)
132 #define THIS2IOLEINPLACEFRAME(This) (&(This)->lpOleInPlaceFrameVtbl)
133 #define THIS2IOLECONTROLSITE(This) (&(This)->lpOleControlSiteVtbl)
135 static HRESULT IOCS_QueryInterface(IOCS *This, REFIID riid, void **ppv)
137 *ppv = NULL;
139 if ( IsEqualIID( &IID_IUnknown, riid )
140 || IsEqualIID( &IID_IOleClientSite, riid ) )
142 *ppv = THIS2IOLECLIENTSITE(This);
143 } else if ( IsEqualIID( &IID_IOleContainer, riid ) )
145 *ppv = THIS2IOLECONTAINER(This);
146 } else if ( IsEqualIID( &IID_IOleInPlaceSite, riid ) || IsEqualIID( &IID_IOleInPlaceSiteEx, riid ) || IsEqualIID( &IID_IOleInPlaceSiteWindowless, riid ) )
148 *ppv = THIS2IOLEINPLACESITEWINDOWLESS(This);
149 } else if ( IsEqualIID( &IID_IOleInPlaceFrame, riid ) )
151 *ppv = THIS2IOLEINPLACEFRAME(This);
152 } else if ( IsEqualIID( &IID_IOleControlSite, riid ) )
154 *ppv = THIS2IOLECONTROLSITE(This);
157 if (*ppv)
159 IOCS_AddRef( This );
160 return S_OK;
163 WARN("unsupported interface %s\n", debugstr_guid( riid ) );
164 *ppv = NULL;
165 return E_NOINTERFACE;
168 static HRESULT IOCS_Detach( IOCS *This );
169 static ULONG IOCS_Release(IOCS *This)
171 ULONG ref = InterlockedDecrement(&This->ref);
173 TRACE( "(%p) : ReleaseRef to %d\n", This, ref );
175 if (!ref)
177 IOCS_Detach( This );
178 HeapFree( GetProcessHeap(), 0, This );
181 return ref;
184 #define DEFINE_THIS(cls,ifc,iface) ((cls*)((BYTE*)(iface)-offsetof(cls,lp ## ifc ## Vtbl)))
186 /****** IOleClientSite *****/
187 #undef IFACE2THIS
188 #define IFACE2THIS(iface) DEFINE_THIS(IOCS,OleClientSite, iface)
189 static HRESULT WINAPI OleClientSite_QueryInterface(IOleClientSite *iface, REFIID riid, void **ppv)
191 IOCS *This = IFACE2THIS(iface);
192 return IOCS_QueryInterface(This, riid, ppv);
194 static ULONG WINAPI OleClientSite_AddRef(IOleClientSite *iface)
196 IOCS *This = IFACE2THIS(iface);
197 return IOCS_AddRef(This);
199 static ULONG WINAPI OleClientSite_Release(IOleClientSite *iface)
201 IOCS *This = IFACE2THIS(iface);
202 return IOCS_Release(This);
204 static HRESULT WINAPI OleClientSite_SaveObject(IOleClientSite *iface)
206 IOCS *This = IFACE2THIS(iface);
207 FIXME( "(%p) - stub\n", This );
208 return E_NOTIMPL;
210 static HRESULT WINAPI OleClientSite_GetMoniker(IOleClientSite *iface, DWORD dwAssign, DWORD dwWhichMoniker, IMoniker **ppmk)
212 IOCS *This = IFACE2THIS(iface);
214 FIXME( "(%p, 0x%x, 0x%x, %p)\n", This, dwAssign, dwWhichMoniker, ppmk );
215 return E_NOTIMPL;
217 static HRESULT WINAPI OleClientSite_GetContainer(IOleClientSite *iface, IOleContainer **ppContainer)
219 IOCS *This = IFACE2THIS(iface);
220 TRACE( "(%p, %p)\n", This, ppContainer );
221 return OleClientSite_QueryInterface( iface, &IID_IOleContainer, (void**)ppContainer );
223 static HRESULT WINAPI OleClientSite_ShowObject(IOleClientSite *iface)
225 IOCS *This = IFACE2THIS(iface);
226 FIXME( "(%p) - stub\n", This );
227 return S_OK;
229 static HRESULT WINAPI OleClientSite_OnShowWindow(IOleClientSite *iface, BOOL fShow)
231 IOCS *This = IFACE2THIS(iface);
232 FIXME( "(%p, %s) - stub\n", This, fShow ? "TRUE" : "FALSE" );
233 return E_NOTIMPL;
235 static HRESULT WINAPI OleClientSite_RequestNewObjectLayout(IOleClientSite *iface)
237 IOCS *This = IFACE2THIS(iface);
238 FIXME( "(%p) - stub\n", This );
239 return E_NOTIMPL;
241 #undef IFACE2THIS
244 /****** IOleContainer *****/
245 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleContainer, iface)
246 static HRESULT WINAPI OleContainer_QueryInterface( IOleContainer* iface, REFIID riid, void** ppv)
248 IOCS *This = IFACE2THIS(iface);
249 return IOCS_QueryInterface( This, riid, ppv );
251 static ULONG WINAPI OleContainer_AddRef(IOleContainer* iface)
253 IOCS *This = IFACE2THIS(iface);
254 return IOCS_AddRef(This);
256 static ULONG WINAPI OleContainer_Release(IOleContainer* iface)
258 IOCS *This = IFACE2THIS(iface);
259 return IOCS_Release(This);
261 static HRESULT WINAPI OleContainer_ParseDisplayName(IOleContainer* iface, IBindCtx* pbc,
262 LPOLESTR pszDisplayName, ULONG* pchEaten, IMoniker** ppmkOut)
264 IOCS *This = IFACE2THIS(iface);
265 FIXME( "(%p,%p,%s,%p,%p) - stub\n", This, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
266 return E_NOTIMPL;
268 static HRESULT WINAPI OleContainer_EnumObjects(IOleContainer* iface, DWORD grfFlags, IEnumUnknown** ppenum)
270 IOCS *This = IFACE2THIS(iface);
271 FIXME( "(%p, %u, %p) - stub\n", This, grfFlags, ppenum );
272 return E_NOTIMPL;
274 static HRESULT WINAPI OleContainer_LockContainer(IOleContainer* iface, BOOL fLock)
276 IOCS *This = IFACE2THIS(iface);
277 FIXME( "(%p, %s) - stub\n", This, fLock?"TRUE":"FALSE" );
278 return E_NOTIMPL;
280 #undef IFACE2THIS
283 /****** IOleInPlaceSiteWindowless *******/
284 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceSiteWindowless, iface)
285 static HRESULT WINAPI OleInPlaceSiteWindowless_QueryInterface(IOleInPlaceSiteWindowless *iface, REFIID riid, void **ppv)
287 IOCS *This = IFACE2THIS(iface);
288 return IOCS_QueryInterface(This, riid, ppv);
290 static ULONG WINAPI OleInPlaceSiteWindowless_AddRef(IOleInPlaceSiteWindowless *iface)
292 IOCS *This = IFACE2THIS(iface);
293 return IOCS_AddRef(This);
295 static ULONG WINAPI OleInPlaceSiteWindowless_Release(IOleInPlaceSiteWindowless *iface)
297 IOCS *This = IFACE2THIS(iface);
298 return IOCS_Release(This);
300 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindow(IOleInPlaceSiteWindowless* iface, HWND* phwnd)
302 IOCS *This = IFACE2THIS(iface);
304 TRACE("(%p,%p)\n", This, phwnd);
305 *phwnd = This->hWnd;
306 return S_OK;
308 static HRESULT WINAPI OleInPlaceSiteWindowless_ContextSensitiveHelp(IOleInPlaceSiteWindowless* iface, BOOL fEnterMode)
310 IOCS *This = IFACE2THIS(iface);
311 FIXME("(%p,%d) - stub\n", This, fEnterMode);
312 return E_NOTIMPL;
314 static HRESULT WINAPI OleInPlaceSiteWindowless_CanInPlaceActivate(IOleInPlaceSiteWindowless *iface)
316 IOCS *This = IFACE2THIS(iface);
317 TRACE("(%p)\n", This);
318 return S_OK;
320 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivate(IOleInPlaceSiteWindowless *iface)
322 IOCS *This = IFACE2THIS(iface);
324 TRACE("(%p)\n", This);
326 This->fInPlace = TRUE;
327 return S_OK;
329 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIActivate(IOleInPlaceSiteWindowless *iface)
331 IOCS *This = IFACE2THIS(iface);
333 TRACE("(%p)\n", This);
335 return S_OK;
337 static HRESULT WINAPI OleInPlaceSiteWindowless_GetWindowContext(IOleInPlaceSiteWindowless *iface,
338 IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect,
339 LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
341 IOCS *This = IFACE2THIS(iface);
343 TRACE("(%p,%p,%p,%p,%p,%p)\n", This, ppFrame, ppDoc, lprcPosRect, lprcClipRect, lpFrameInfo);
345 if ( lprcClipRect )
346 *lprcClipRect = This->size;
347 if ( lprcPosRect )
348 *lprcPosRect = This->size;
350 if ( ppFrame )
352 IOCS_QueryInterface( This, &IID_IOleInPlaceFrame, (void**) ppFrame );
355 if ( ppDoc )
356 *ppDoc = NULL;
358 if ( lpFrameInfo )
360 lpFrameInfo->fMDIApp = FALSE;
361 lpFrameInfo->hwndFrame = This->hWnd;
362 lpFrameInfo->haccel = NULL;
363 lpFrameInfo->cAccelEntries = 0;
366 return S_OK;
368 static HRESULT WINAPI OleInPlaceSiteWindowless_Scroll(IOleInPlaceSiteWindowless *iface, SIZE scrollExtent)
370 IOCS *This = IFACE2THIS(iface);
371 FIXME("(%p) - stub\n", This);
372 return E_NOTIMPL;
374 static HRESULT WINAPI OleInPlaceSiteWindowless_OnUIDeactivate(IOleInPlaceSiteWindowless *iface, BOOL fUndoable)
376 IOCS *This = IFACE2THIS(iface);
377 FIXME("(%p,%d) - stub\n", This, fUndoable);
378 return E_NOTIMPL;
380 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivate(IOleInPlaceSiteWindowless *iface)
382 IOCS *This = IFACE2THIS(iface);
384 TRACE("(%p)\n", This);
386 This->fInPlace = This->fWindowless = FALSE;
387 return S_OK;
389 static HRESULT WINAPI OleInPlaceSiteWindowless_DiscardUndoState(IOleInPlaceSiteWindowless *iface)
391 IOCS *This = IFACE2THIS(iface);
392 FIXME("(%p) - stub\n", This);
393 return E_NOTIMPL;
395 static HRESULT WINAPI OleInPlaceSiteWindowless_DeactivateAndUndo(IOleInPlaceSiteWindowless *iface)
397 IOCS *This = IFACE2THIS(iface);
398 FIXME("(%p) - stub\n", This);
399 return E_NOTIMPL;
401 static HRESULT WINAPI OleInPlaceSiteWindowless_OnPosRectChange(IOleInPlaceSiteWindowless *iface, LPCRECT lprcPosRect)
403 IOCS *This = IFACE2THIS(iface);
404 FIXME("(%p,%p) - stub\n", This, lprcPosRect);
405 return E_NOTIMPL;
407 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceActivateEx( IOleInPlaceSiteWindowless *iface, BOOL* pfNoRedraw, DWORD dwFlags)
409 IOCS *This = IFACE2THIS(iface);
411 TRACE("\n");
413 This->fActive = This->fInPlace = TRUE;
414 if ( dwFlags & ACTIVATE_WINDOWLESS )
415 This->fWindowless = TRUE;
416 return S_OK;
418 static HRESULT WINAPI OleInPlaceSiteWindowless_OnInPlaceDeactivateEx( IOleInPlaceSiteWindowless *iface, BOOL fNoRedraw)
420 IOCS *This = IFACE2THIS(iface);
422 TRACE("\n");
424 This->fActive = This->fInPlace = This->fWindowless = FALSE;
425 return S_OK;
427 static HRESULT WINAPI OleInPlaceSiteWindowless_RequestUIActivate( IOleInPlaceSiteWindowless *iface)
429 FIXME("\n");
430 return E_NOTIMPL;
432 static HRESULT WINAPI OleInPlaceSiteWindowless_CanWindowlessActivate( IOleInPlaceSiteWindowless *iface)
434 FIXME("\n");
435 return S_OK;
437 static HRESULT WINAPI OleInPlaceSiteWindowless_GetCapture( IOleInPlaceSiteWindowless *iface)
439 FIXME("\n");
440 return E_NOTIMPL;
442 static HRESULT WINAPI OleInPlaceSiteWindowless_SetCapture( IOleInPlaceSiteWindowless *iface, BOOL fCapture)
444 FIXME("\n");
445 return E_NOTIMPL;
447 static HRESULT WINAPI OleInPlaceSiteWindowless_GetFocus( IOleInPlaceSiteWindowless *iface)
449 FIXME("\n");
450 return E_NOTIMPL;
452 static HRESULT WINAPI OleInPlaceSiteWindowless_SetFocus( IOleInPlaceSiteWindowless *iface, BOOL fFocus)
454 FIXME("\n");
455 return E_NOTIMPL;
457 static HRESULT WINAPI OleInPlaceSiteWindowless_GetDC( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, DWORD grfFlags, HDC* phDC)
459 FIXME("\n");
460 return E_NOTIMPL;
462 static HRESULT WINAPI OleInPlaceSiteWindowless_ReleaseDC( IOleInPlaceSiteWindowless *iface, HDC hDC)
464 FIXME("\n");
465 return E_NOTIMPL;
467 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRect( IOleInPlaceSiteWindowless *iface, LPCRECT pRect, BOOL fErase)
469 FIXME("\n");
470 return E_NOTIMPL;
472 static HRESULT WINAPI OleInPlaceSiteWindowless_InvalidateRgn( IOleInPlaceSiteWindowless *iface, HRGN hRGN, BOOL fErase)
474 FIXME("\n");
475 return E_NOTIMPL;
477 static HRESULT WINAPI OleInPlaceSiteWindowless_ScrollRect( IOleInPlaceSiteWindowless *iface, INT dx, INT dy, LPCRECT pRectScroll, LPCRECT pRectClip)
479 FIXME("\n");
480 return E_NOTIMPL;
482 static HRESULT WINAPI OleInPlaceSiteWindowless_AdjustRect( IOleInPlaceSiteWindowless *iface, LPRECT prc)
484 FIXME("\n");
485 return E_NOTIMPL;
487 static HRESULT WINAPI OleInPlaceSiteWindowless_OnDefWindowMessage( IOleInPlaceSiteWindowless *iface, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult)
489 FIXME("\n");
490 return E_NOTIMPL;
492 #undef IFACE2THIS
495 /****** IOleInPlaceFrame *******/
496 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleInPlaceFrame, iface)
497 static HRESULT WINAPI OleInPlaceFrame_QueryInterface(IOleInPlaceFrame *iface, REFIID riid, void **ppv)
499 IOCS *This = IFACE2THIS(iface);
500 return IOCS_QueryInterface(This, riid, ppv);
502 static ULONG WINAPI OleInPlaceFrame_AddRef(IOleInPlaceFrame *iface)
504 IOCS *This = IFACE2THIS(iface);
505 return IOCS_AddRef(This);
507 static ULONG WINAPI OleInPlaceFrame_Release(IOleInPlaceFrame *iface)
509 IOCS *This = IFACE2THIS(iface);
510 return IOCS_Release(This);
512 static HRESULT WINAPI OleInPlaceFrame_GetWindow(IOleInPlaceFrame *iface, HWND *phWnd)
514 IOCS *This = IFACE2THIS(iface);
516 TRACE( "(%p,%p)\n", This, phWnd );
518 *phWnd = This->hWnd;
519 return S_OK;
522 static HRESULT WINAPI OleInPlaceFrame_ContextSensitiveHelp(IOleInPlaceFrame *iface, BOOL fEnterMode)
524 IOCS *This = IFACE2THIS(iface);
526 FIXME( "(%p,%d) - stub\n", This, fEnterMode );
527 return E_NOTIMPL;
530 static HRESULT WINAPI OleInPlaceFrame_GetBorder(IOleInPlaceFrame *iface, LPRECT lprectBorder)
532 IOCS *This = IFACE2THIS(iface);
534 FIXME( "(%p,%p) - stub\n", This, lprectBorder );
535 return E_NOTIMPL;
538 static HRESULT WINAPI OleInPlaceFrame_RequestBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
540 IOCS *This = IFACE2THIS(iface);
542 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
543 return E_NOTIMPL;
546 static HRESULT WINAPI OleInPlaceFrame_SetBorderSpace(IOleInPlaceFrame *iface, LPCBORDERWIDTHS pborderwidths)
548 IOCS *This = IFACE2THIS(iface);
550 FIXME( "(%p,%p) - stub\n", This, pborderwidths );
551 return E_NOTIMPL;
554 static HRESULT WINAPI OleInPlaceFrame_SetActiveObject(IOleInPlaceFrame *iface, IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
556 IOCS *This = IFACE2THIS(iface);
558 FIXME( "(%p,%p,%s) - stub\n", This, pActiveObject, debugstr_w(pszObjName) );
559 return S_OK;
562 static HRESULT WINAPI OleInPlaceFrame_InsertMenus(IOleInPlaceFrame *iface, HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
564 IOCS *This = IFACE2THIS(iface);
566 FIXME( "(%p,%p,%p) - stub\n", This, hmenuShared, lpMenuWidths );
567 return E_NOTIMPL;
570 static HRESULT WINAPI OleInPlaceFrame_SetMenu(IOleInPlaceFrame *iface, HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
572 IOCS *This = IFACE2THIS(iface);
574 FIXME( "(%p,%p,%p,%p) - stub\n", This, hmenuShared, holemenu, hwndActiveObject );
575 return E_NOTIMPL;
577 static HRESULT WINAPI OleInPlaceFrame_RemoveMenus(IOleInPlaceFrame *iface, HMENU hmenuShared)
579 IOCS *This = IFACE2THIS(iface);
581 FIXME( "(%p, %p) - stub\n", This, hmenuShared );
582 return E_NOTIMPL;
585 static HRESULT WINAPI OleInPlaceFrame_SetStatusText(IOleInPlaceFrame *iface, LPCOLESTR pszStatusText)
587 IOCS *This = IFACE2THIS(iface);
589 FIXME( "(%p, %s) - stub\n", This, debugstr_w( pszStatusText ) );
590 return E_NOTIMPL;
593 static HRESULT WINAPI OleInPlaceFrame_EnableModeless(IOleInPlaceFrame *iface, BOOL fEnable)
595 IOCS *This = IFACE2THIS(iface);
597 FIXME( "(%p, %d) - stub\n", This, fEnable );
598 return E_NOTIMPL;
601 static HRESULT WINAPI OleInPlaceFrame_TranslateAccelerator(IOleInPlaceFrame *iface, LPMSG lpmsg, WORD wID)
603 IOCS *This = IFACE2THIS(iface);
605 FIXME( "(%p, %p, %x) - stub\n", This, lpmsg, wID );
606 return E_NOTIMPL;
608 #undef IFACE2THIS
611 /****** IOleControlSite *******/
612 #define IFACE2THIS(iface) DEFINE_THIS(IOCS, OleControlSite, iface)
613 static HRESULT WINAPI OleControlSite_QueryInterface(IOleControlSite *iface, REFIID riid, void **ppv)
615 IOCS *This = IFACE2THIS(iface);
616 return IOCS_QueryInterface(This, riid, ppv);
618 static ULONG WINAPI OleControlSite_AddRef(IOleControlSite *iface)
620 IOCS *This = IFACE2THIS(iface);
621 return IOCS_AddRef(This);
623 static ULONG WINAPI OleControlSite_Release(IOleControlSite *iface)
625 IOCS *This = IFACE2THIS(iface);
626 return IOCS_Release(This);
628 static HRESULT WINAPI OleControlSite_OnControlInfoChanged( IOleControlSite* This)
630 FIXME( "\n" );
631 return E_NOTIMPL;
633 static HRESULT WINAPI OleControlSite_LockInPlaceActive( IOleControlSite* This, BOOL fLock)
635 FIXME( "\n" );
636 return E_NOTIMPL;
638 static HRESULT WINAPI OleControlSite_GetExtendedControl( IOleControlSite* This, IDispatch** ppDisp)
640 FIXME( "\n" );
641 return E_NOTIMPL;
643 static HRESULT WINAPI OleControlSite_TransformCoords( IOleControlSite* This, POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
645 FIXME( "\n" );
646 return E_NOTIMPL;
648 static HRESULT WINAPI OleControlSite_TranslateAccelerator( IOleControlSite* This, MSG* pMsg, DWORD grfModifiers)
650 FIXME( "\n" );
651 return E_NOTIMPL;
653 static HRESULT WINAPI OleControlSite_OnFocus( IOleControlSite* This, BOOL fGotFocus)
655 FIXME( "\n" );
656 return E_NOTIMPL;
658 static HRESULT WINAPI OleControlSite_ShowPropertyFrame( IOleControlSite* This)
660 FIXME( "\n" );
661 return E_NOTIMPL;
663 #undef IFACE2THIS
667 static const IOleClientSiteVtbl OleClientSite_vtbl = {
668 OleClientSite_QueryInterface,
669 OleClientSite_AddRef,
670 OleClientSite_Release,
671 OleClientSite_SaveObject,
672 OleClientSite_GetMoniker,
673 OleClientSite_GetContainer,
674 OleClientSite_ShowObject,
675 OleClientSite_OnShowWindow,
676 OleClientSite_RequestNewObjectLayout
678 static const IOleContainerVtbl OleContainer_vtbl = {
679 OleContainer_QueryInterface,
680 OleContainer_AddRef,
681 OleContainer_Release,
682 OleContainer_ParseDisplayName,
683 OleContainer_EnumObjects,
684 OleContainer_LockContainer
686 static const IOleInPlaceSiteWindowlessVtbl OleInPlaceSiteWindowless_vtbl = {
687 OleInPlaceSiteWindowless_QueryInterface,
688 OleInPlaceSiteWindowless_AddRef,
689 OleInPlaceSiteWindowless_Release,
690 OleInPlaceSiteWindowless_GetWindow,
691 OleInPlaceSiteWindowless_ContextSensitiveHelp,
692 OleInPlaceSiteWindowless_CanInPlaceActivate,
693 OleInPlaceSiteWindowless_OnInPlaceActivate,
694 OleInPlaceSiteWindowless_OnUIActivate,
695 OleInPlaceSiteWindowless_GetWindowContext,
696 OleInPlaceSiteWindowless_Scroll,
697 OleInPlaceSiteWindowless_OnUIDeactivate,
698 OleInPlaceSiteWindowless_OnInPlaceDeactivate,
699 OleInPlaceSiteWindowless_DiscardUndoState,
700 OleInPlaceSiteWindowless_DeactivateAndUndo,
701 OleInPlaceSiteWindowless_OnPosRectChange,
702 OleInPlaceSiteWindowless_OnInPlaceActivateEx,
703 OleInPlaceSiteWindowless_OnInPlaceDeactivateEx,
704 OleInPlaceSiteWindowless_RequestUIActivate,
705 OleInPlaceSiteWindowless_CanWindowlessActivate,
706 OleInPlaceSiteWindowless_GetCapture,
707 OleInPlaceSiteWindowless_SetCapture,
708 OleInPlaceSiteWindowless_GetFocus,
709 OleInPlaceSiteWindowless_SetFocus,
710 OleInPlaceSiteWindowless_GetDC,
711 OleInPlaceSiteWindowless_ReleaseDC,
712 OleInPlaceSiteWindowless_InvalidateRect,
713 OleInPlaceSiteWindowless_InvalidateRgn,
714 OleInPlaceSiteWindowless_ScrollRect,
715 OleInPlaceSiteWindowless_AdjustRect,
716 OleInPlaceSiteWindowless_OnDefWindowMessage
718 static const IOleInPlaceFrameVtbl OleInPlaceFrame_vtbl =
720 OleInPlaceFrame_QueryInterface,
721 OleInPlaceFrame_AddRef,
722 OleInPlaceFrame_Release,
723 OleInPlaceFrame_GetWindow,
724 OleInPlaceFrame_ContextSensitiveHelp,
725 OleInPlaceFrame_GetBorder,
726 OleInPlaceFrame_RequestBorderSpace,
727 OleInPlaceFrame_SetBorderSpace,
728 OleInPlaceFrame_SetActiveObject,
729 OleInPlaceFrame_InsertMenus,
730 OleInPlaceFrame_SetMenu,
731 OleInPlaceFrame_RemoveMenus,
732 OleInPlaceFrame_SetStatusText,
733 OleInPlaceFrame_EnableModeless,
734 OleInPlaceFrame_TranslateAccelerator
736 static const IOleControlSiteVtbl OleControlSite_vtbl =
738 OleControlSite_QueryInterface,
739 OleControlSite_AddRef,
740 OleControlSite_Release,
741 OleControlSite_OnControlInfoChanged,
742 OleControlSite_LockInPlaceActive,
743 OleControlSite_GetExtendedControl,
744 OleControlSite_TransformCoords,
745 OleControlSite_TranslateAccelerator,
746 OleControlSite_OnFocus,
747 OleControlSite_ShowPropertyFrame
750 static HRESULT IOCS_Detach( IOCS *This ) /* remove subclassing */
752 if ( This->hWnd )
754 SetWindowLongPtrW( This->hWnd, GWLP_WNDPROC, (ULONG_PTR) This->OrigWndProc );
755 SetWindowLongPtrW( This->hWnd, GWLP_USERDATA, 0 );
756 This->hWnd = NULL;
758 if ( This->control )
760 IOleObject *control = This->control;
762 This->control = NULL;
763 IOleObject_SetClientSite( control, NULL );
764 IOleObject_Release( control );
766 return S_OK;
769 static void IOCS_OnSize( IOCS* This, LPCRECT rect )
771 SIZEL inPix, inHi;
773 This->size.left = rect->left; This->size.right = rect->right; This->size.top = rect->top; This->size.bottom = rect->bottom;
775 if ( !This->control )
776 return;
778 inPix.cx = rect->right - rect->left;
779 inPix.cy = rect->bottom - rect->top;
780 AtlPixelToHiMetric( &inPix, &inHi );
781 IOleObject_SetExtent( This->control, DVASPECT_CONTENT, &inHi );
783 if ( This->fInPlace )
785 IOleInPlaceObject *wl;
787 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IOleInPlaceObject, (void**)&wl ) ) )
789 IOleInPlaceObject_SetObjectRects( wl, rect, rect );
790 IOleInPlaceObject_Release( wl );
795 static void IOCS_OnShow( IOCS *This, BOOL fShow )
797 if (!This->control || This->fActive || !fShow )
798 return;
800 This->fActive = TRUE;
803 static void IOCS_OnDraw( IOCS *This )
805 IViewObject *view;
807 if ( !This->control || !This->fWindowless )
808 return;
810 if ( SUCCEEDED( IOleObject_QueryInterface( This->control, &IID_IViewObject, (void**)&view ) ) )
812 HDC dc = GetDC( This->hWnd );
813 RECTL rect;
815 rect.left = This->size.left; rect.top = This->size.top;
816 rect.bottom = This->size.bottom; rect.right = This->size.right;
818 IViewObject_Draw( view, DVASPECT_CONTENT, ~0, NULL, NULL, 0, dc, &rect, &rect, NULL, 0 );
819 IViewObject_Release( view );
820 ReleaseDC( This->hWnd, dc );
824 static LRESULT IOCS_OnWndProc( IOCS *This, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
826 WNDPROC OrigWndProc = This->OrigWndProc;
828 switch( uMsg )
830 case WM_DESTROY:
831 IOCS_Detach( This );
832 break;
833 case WM_SIZE:
835 RECT r;
836 r.left = r.top = 0;
837 r.right = LOWORD( lParam );
838 r.bottom = HIWORD( lParam );
839 IOCS_OnSize( This, &r );
841 break;
842 case WM_SHOWWINDOW:
843 IOCS_OnShow( This, (BOOL) wParam );
844 break;
845 case WM_PAINT:
846 IOCS_OnDraw( This );
847 break;
850 return CallWindowProcW( OrigWndProc, hWnd, uMsg, wParam, lParam );
853 static LRESULT CALLBACK AtlHost_wndproc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam )
855 IOCS *This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
856 return IOCS_OnWndProc( This, hWnd, wMsg, wParam, lParam );
859 static HRESULT IOCS_Attach( IOCS *This, HWND hWnd, IUnknown *pUnkControl ) /* subclass hWnd */
861 This->hWnd = hWnd;
862 IUnknown_QueryInterface( pUnkControl, &IID_IOleObject, (void**)&This->control );
863 IOleObject_SetClientSite( This->control, THIS2IOLECLIENTSITE( This ) );
864 SetWindowLongPtrW( hWnd, GWLP_USERDATA, (ULONG_PTR) This );
865 This->OrigWndProc = (WNDPROC)SetWindowLongPtrW( hWnd, GWLP_WNDPROC, (ULONG_PTR) AtlHost_wndproc );
867 return S_OK;
870 static HRESULT IOCS_Init( IOCS *This )
872 RECT rect;
873 static const WCHAR AXWIN[] = {'A','X','W','I','N',0};
875 IOleObject_SetHostNames( This->control, AXWIN, AXWIN );
877 GetClientRect( This->hWnd, &rect );
878 IOCS_OnSize( This, &rect );
879 IOleObject_DoVerb( This->control, OLEIVERB_INPLACEACTIVATE, NULL, THIS2IOLECLIENTSITE( This ), 0, This->hWnd, &rect );
881 return S_OK;
884 /**********************************************************************
885 * Create new instance of Atl host component and attach it to window *
887 static HRESULT IOCS_Create( HWND hWnd, IUnknown *pUnkControl, IOCS **ppSite )
889 HRESULT hr;
890 IOCS *This;
892 *ppSite = NULL;
893 This = HeapAlloc(GetProcessHeap(), 0, sizeof(IOCS));
895 if (!This)
896 return E_OUTOFMEMORY;
898 This->lpOleClientSiteVtbl = &OleClientSite_vtbl;
899 This->lpOleContainerVtbl = &OleContainer_vtbl;
900 This->lpOleInPlaceSiteWindowlessVtbl = &OleInPlaceSiteWindowless_vtbl;
901 This->lpOleInPlaceFrameVtbl = &OleInPlaceFrame_vtbl;
902 This->lpOleControlSiteVtbl = &OleControlSite_vtbl;
903 This->ref = 1;
905 This->OrigWndProc = NULL;
906 This->hWnd = NULL;
907 This->fWindowless = This->fActive = This->fInPlace = FALSE;
909 hr = IOCS_Attach( This, hWnd, pUnkControl );
910 if ( SUCCEEDED( hr ) )
911 hr = IOCS_Init( This );
912 if ( SUCCEEDED( hr ) )
913 *ppSite = This;
914 else
915 IOCS_Release( This );
917 return hr;
921 /***********************************************************************
922 * AtlAxCreateControl [ATL.@]
924 HRESULT WINAPI AtlAxCreateControl(LPCOLESTR lpszName, HWND hWnd,
925 IStream *pStream, IUnknown **ppUnkContainer)
927 return AtlAxCreateControlEx( lpszName, hWnd, pStream, ppUnkContainer,
928 NULL, NULL, NULL );
931 /***********************************************************************
932 * AtlAxCreateControlEx [ATL.@]
934 * REMARKS
935 * See http://www.codeproject.com/com/cwebpage.asp for some background
938 HRESULT WINAPI AtlAxCreateControlEx(LPCOLESTR lpszName, HWND hWnd,
939 IStream *pStream, IUnknown **ppUnkContainer, IUnknown **ppUnkControl,
940 REFIID iidSink, IUnknown *punkSink)
942 CLSID controlId;
943 HRESULT hRes;
944 IOleObject *pControl;
945 IUnknown *pUnkControl;
946 IPersistStreamInit *pPSInit;
947 IUnknown *pContainer;
948 enum {IsGUID=0,IsHTML=1,IsURL=2} content;
950 TRACE("(%s %p %p %p %p %p %p)\n", debugstr_w(lpszName), hWnd, pStream,
951 ppUnkContainer, ppUnkControl, iidSink, punkSink);
953 hRes = CLSIDFromString( lpszName, &controlId );
954 if ( FAILED(hRes) )
955 hRes = CLSIDFromProgID( lpszName, &controlId );
956 if ( SUCCEEDED( hRes ) )
957 content = IsGUID;
958 else {
959 /* FIXME - check for MSHTML: prefix! */
960 content = IsURL;
961 controlId = CLSID_WebBrowser;
964 hRes = CoCreateInstance( &controlId, 0, CLSCTX_ALL, &IID_IOleObject,
965 (void**) &pControl );
966 if ( FAILED( hRes ) )
968 WARN( "cannot create ActiveX control %s instance - error 0x%08x\n",
969 debugstr_guid( &controlId ), hRes );
970 return hRes;
973 hRes = IOleObject_QueryInterface( pControl, &IID_IPersistStreamInit, (void**) &pPSInit );
974 if ( SUCCEEDED( hRes ) )
976 if (!pStream)
977 IPersistStreamInit_InitNew( pPSInit );
978 else
979 IPersistStreamInit_Load( pPSInit, pStream );
980 IPersistStreamInit_Release( pPSInit );
981 } else
982 WARN("cannot get IID_IPersistStreamInit out of control\n");
984 IOleObject_QueryInterface( pControl, &IID_IUnknown, (void**) &pUnkControl );
985 IOleObject_Release( pControl );
988 hRes = AtlAxAttachControl( pUnkControl, hWnd, &pContainer );
989 if ( FAILED( hRes ) )
990 WARN("cannot attach control to window\n");
992 if ( content == IsURL )
994 IWebBrowser2 *browser;
996 hRes = IOleObject_QueryInterface( pControl, &IID_IWebBrowser2, (void**) &browser );
997 if ( !browser )
998 WARN( "Cannot query IWebBrowser2 interface: %08x\n", hRes );
999 else {
1000 VARIANT url;
1002 IWebBrowser2_put_Visible( browser, VARIANT_TRUE ); /* it seems that native does this on URL (but do not on MSHTML:! why? */
1004 V_VT(&url) = VT_BSTR;
1005 V_BSTR(&url) = SysAllocString( lpszName );
1007 hRes = IWebBrowser2_Navigate2( browser, &url, NULL, NULL, NULL, NULL );
1008 if ( FAILED( hRes ) )
1009 WARN( "IWebBrowser2::Navigate2 failed: %08x\n", hRes );
1010 SysFreeString( V_BSTR(&url) );
1012 IWebBrowser2_Release( browser );
1016 if (ppUnkContainer)
1018 *ppUnkContainer = pContainer;
1019 if ( pContainer )
1020 IUnknown_AddRef( pContainer );
1022 if (ppUnkControl)
1024 *ppUnkControl = pUnkControl;
1025 if ( pUnkControl )
1026 IUnknown_AddRef( pUnkControl );
1029 if ( pUnkControl )
1030 IUnknown_Release( pUnkControl );
1031 if ( pContainer )
1032 IUnknown_Release( pContainer );
1034 return S_OK;
1037 /***********************************************************************
1038 * AtlAxAttachControl [ATL.@]
1040 HRESULT WINAPI AtlAxAttachControl(IUnknown* pControl, HWND hWnd, IUnknown** ppUnkContainer)
1042 IOCS *pUnkContainer;
1043 HRESULT hr;
1045 TRACE( "%p %p %p\n", pControl, hWnd, ppUnkContainer );
1047 if (!pControl)
1048 return E_INVALIDARG;
1050 hr = IOCS_Create( hWnd, pControl, &pUnkContainer );
1051 if ( SUCCEEDED( hr ) && ppUnkContainer)
1053 *ppUnkContainer = (IUnknown*) pUnkContainer;
1056 return hr;
1059 /**********************************************************************
1060 * Helper function for AX_ConvertDialogTemplate
1062 static inline BOOL advance_array(WORD **pptr, DWORD *palloc, DWORD *pfilled, const WORD *data, DWORD size)
1064 if ( (*pfilled + size) > *palloc )
1066 *palloc = ((*pfilled+size) + 0xFF) & ~0xFF;
1067 *pptr = HeapReAlloc( GetProcessHeap(), 0, *pptr, *palloc * sizeof(WORD) );
1068 if (!*pptr)
1069 return FALSE;
1071 RtlMoveMemory( *pptr+*pfilled, data, size * sizeof(WORD) );
1072 *pfilled += size;
1073 return TRUE;
1076 /**********************************************************************
1077 * Convert ActiveX control templates to AtlAxWin class instances
1079 static LPDLGTEMPLATEW AX_ConvertDialogTemplate(LPCDLGTEMPLATEW src_tmpl)
1081 #define GET_WORD(x) (*(const WORD *)(x))
1082 #define GET_DWORD(x) (*(const DWORD *)(x))
1083 #define PUT_BLOCK(x,y) do {if (!advance_array(&output, &allocated, &filled, (x), (y))) return NULL;} while (0)
1084 #define PUT_WORD(x) do {WORD w = (x);PUT_BLOCK(&w, 1);} while(0)
1085 #define PUT_DWORD(x) do {DWORD w = (x);PUT_BLOCK(&w, 2);} while(0)
1086 const WORD *tmp, *src = (const WORD *)src_tmpl;
1087 WORD *output;
1088 DWORD allocated, filled; /* in WORDs */
1089 BOOL ext;
1090 WORD signature, dlgver, rescount;
1091 DWORD style;
1093 filled = 0; allocated = 256;
1094 output = HeapAlloc( GetProcessHeap(), 0, allocated * sizeof(WORD) );
1095 if (!output)
1096 return NULL;
1098 /* header */
1099 tmp = src;
1100 signature = GET_WORD(src);
1101 dlgver = GET_WORD(src + 1);
1102 if (signature == 1 && dlgver == 0xFFFF)
1104 ext = TRUE;
1105 src += 6;
1106 style = GET_DWORD(src);
1107 src += 2;
1108 rescount = GET_WORD(src++);
1109 src += 4;
1110 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1111 src += 2;
1112 else
1113 src += strlenW(src) + 1;
1114 if ( GET_WORD(src) == 0xFFFF ) /* class */
1115 src += 2;
1116 else
1117 src += strlenW(src) + 1;
1118 src += strlenW(src) + 1; /* title */
1119 if ( style & (DS_SETFONT | DS_SHELLFONT) )
1121 src += 3;
1122 src += strlenW(src) + 1;
1124 } else {
1125 ext = FALSE;
1126 style = GET_DWORD(src);
1127 src += 4;
1128 rescount = GET_WORD(src++);
1129 src += 4;
1130 if ( GET_WORD(src) == 0xFFFF ) /* menu */
1131 src += 2;
1132 else
1133 src += strlenW(src) + 1;
1134 if ( GET_WORD(src) == 0xFFFF ) /* class */
1135 src += 2;
1136 else
1137 src += strlenW(src) + 1;
1138 src += strlenW(src) + 1; /* title */
1139 if ( style & DS_SETFONT )
1141 src++;
1142 src += strlenW(src) + 1;
1145 PUT_BLOCK(tmp, src-tmp);
1147 while(rescount--)
1149 src = (const WORD *)( ( ((ULONG_PTR)src) + 3) & ~3); /* align on DWORD boundary */
1150 filled = (filled + 1) & ~1; /* depends on DWORD-aligned allocation unit */
1152 tmp = src;
1153 if (ext)
1154 src += 12;
1155 else
1156 src += 9;
1157 PUT_BLOCK(tmp, src-tmp);
1159 tmp = src;
1160 if ( GET_WORD(src) == 0xFFFF ) /* class */
1162 src += 2;
1163 } else
1165 src += strlenW(src) + 1;
1167 src += strlenW(src) + 1; /* title */
1168 if ( GET_WORD(tmp) == '{' ) /* all this mess created because of this line */
1170 static const WCHAR AtlAxWin[9]={'A','t','l','A','x','W','i','n',0};
1171 PUT_BLOCK(AtlAxWin, sizeof(AtlAxWin)/sizeof(WCHAR));
1172 PUT_BLOCK(tmp, strlenW(tmp)+1);
1173 } else
1174 PUT_BLOCK(tmp, src-tmp);
1176 if ( GET_WORD(src) )
1178 WORD size = (GET_WORD(src)+sizeof(WORD)-1) / sizeof(WORD); /* quite ugly :( Maybe use BYTE* instead of WORD* everywhere ? */
1179 PUT_BLOCK(src, size);
1180 src+=size;
1182 else
1184 PUT_WORD(0);
1185 src++;
1188 return (LPDLGTEMPLATEW) output;
1191 /***********************************************************************
1192 * AtlAxCreateDialogA [ATL.@]
1194 * Creates a dialog window
1196 * PARAMS
1197 * hInst [I] Application instance
1198 * name [I] Dialog box template name
1199 * owner [I] Dialog box parent HWND
1200 * dlgProc [I] Dialog box procedure
1201 * param [I] This value will be passed to dlgProc as WM_INITDIALOG's message lParam
1203 * RETURNS
1204 * Window handle of dialog window.
1206 HWND WINAPI AtlAxCreateDialogA(HINSTANCE hInst, LPCSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1208 HWND res = NULL;
1209 int length;
1210 WCHAR *nameW;
1212 if (IS_INTRESOURCE(name))
1213 return AtlAxCreateDialogW( hInst, (LPCWSTR) name, owner, dlgProc, param );
1215 length = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1216 nameW = HeapAlloc( GetProcessHeap(), 0, length * sizeof(WCHAR) );
1217 if (nameW)
1219 MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, length );
1220 res = AtlAxCreateDialogW( hInst, nameW, owner, dlgProc, param );
1221 HeapFree( GetProcessHeap(), 0, nameW );
1223 return res;
1226 /***********************************************************************
1227 * AtlAxCreateDialogW [ATL.@]
1229 * See AtlAxCreateDialogA
1232 HWND WINAPI AtlAxCreateDialogW(HINSTANCE hInst, LPCWSTR name, HWND owner, DLGPROC dlgProc ,LPARAM param)
1234 HRSRC hrsrc;
1235 HGLOBAL hgl;
1236 LPCDLGTEMPLATEW ptr;
1237 LPDLGTEMPLATEW newptr;
1238 HWND res;
1240 TRACE("(%p %s %p %p %lx)\n", hInst, debugstr_w(name), owner, dlgProc, param);
1242 hrsrc = FindResourceW( hInst, name, (LPWSTR)RT_DIALOG );
1243 if ( !hrsrc )
1244 return NULL;
1245 hgl = LoadResource (hInst, hrsrc);
1246 if ( !hgl )
1247 return NULL;
1248 ptr = LockResource ( hgl );
1249 if (!ptr)
1251 FreeResource( hgl );
1252 return NULL;
1254 newptr = AX_ConvertDialogTemplate( ptr );
1255 if ( newptr )
1257 res = CreateDialogIndirectParamW( hInst, newptr, owner, dlgProc, param );
1258 HeapFree( GetProcessHeap(), 0, newptr );
1259 } else
1260 res = NULL;
1261 FreeResource ( hrsrc );
1262 return res;
1265 /***********************************************************************
1266 * AtlAxGetHost [ATL.@]
1269 HRESULT WINAPI AtlAxGetHost(HWND hWnd, IUnknown **pUnk)
1271 IOCS *This;
1273 TRACE( "(%p, %p)\n", hWnd, pUnk );
1275 *pUnk = NULL;
1277 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1278 if ( !This )
1280 WARN("No container attached to %p\n", hWnd );
1281 return E_FAIL;
1284 return IOCS_QueryInterface( This, &IID_IUnknown, (void**) pUnk );
1287 /***********************************************************************
1288 * AtlAxGetControl [ATL.@]
1291 HRESULT WINAPI AtlAxGetControl(HWND hWnd, IUnknown **pUnk)
1293 IOCS *This;
1295 TRACE( "(%p, %p)\n", hWnd, pUnk );
1297 *pUnk = NULL;
1299 This = (IOCS*) GetWindowLongPtrW( hWnd, GWLP_USERDATA );
1300 if ( !This || !This->control )
1302 WARN("No control attached to %p\n", hWnd );
1303 return E_FAIL;
1306 return IOleObject_QueryInterface( This->control, &IID_IUnknown, (void**) pUnk );