4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
7 * Copyright 1999, 2000 Marcus Meissner
8 * Copyright 2005 Juan Lang
9 * Copyright 2011 Adam Martinson for CodeWeavers
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #define NONAMELESSUNION
45 #include "compobj_private.h"
47 #include "wine/list.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
52 WINE_DECLARE_DEBUG_CHANNEL(accel
);
54 /******************************************************************************
55 * These are static/global variables and internal data structures that the
56 * OLE module uses to maintain its state.
58 typedef struct tagTrackerWindowInfo
60 IDataObject
* dataObject
;
61 IDropSource
* dropSource
;
69 HWND curTargetHWND
; /* window the mouse is hovering over */
70 IDropTarget
* curDragTarget
;
71 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
72 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
75 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
77 HWND hwndFrame
; /* The containers frame window */
78 HWND hwndActiveObject
; /* The active objects window */
79 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
80 HMENU hmenuCombined
; /* The combined menu */
81 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
84 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
86 DWORD tid
; /* Thread Id */
87 HANDLE hHeap
; /* Heap this is allocated from */
88 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
89 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
90 struct tagOleMenuHookItem
*next
;
93 static OleMenuHookItem
*hook_list
;
96 * This is the lock count on the OLE library. It is controlled by the
97 * OLEInitialize/OLEUninitialize methods.
99 static LONG OLE_moduleLockCount
= 0;
102 * Name of our registered window class.
104 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
105 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
108 * Name of menu descriptor property.
110 static const WCHAR prop_olemenuW
[] =
111 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
113 /* property to store IDropTarget pointer */
114 static const WCHAR prop_oledroptarget
[] =
115 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
117 /* property to store Marshalled IDropTarget pointer */
118 static const WCHAR prop_marshalleddroptarget
[] =
119 {'W','i','n','e','M','a','r','s','h','a','l','l','e','d','D','r','o','p','T','a','r','g','e','t',0};
121 static const WCHAR emptyW
[] = { 0 };
123 /******************************************************************************
124 * These are the prototypes of miscellaneous utility methods
126 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
128 /******************************************************************************
129 * These are the prototypes of the utility methods used to manage a shared menu
131 static void OLEMenu_Initialize(void);
132 static void OLEMenu_UnInitialize(void);
133 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
134 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
135 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
136 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
137 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
138 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
139 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
141 /******************************************************************************
142 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
144 extern void OLEClipbrd_UnInitialize(void);
145 extern void OLEClipbrd_Initialize(void);
147 /******************************************************************************
148 * These are the prototypes of the utility methods used for OLE Drag n Drop
150 static void OLEDD_Initialize(void);
151 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
152 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
153 static DWORD
OLEDD_GetButtonState(void);
155 /******************************************************************************
156 * OleBuildVersion [OLE32.@]
158 DWORD WINAPI
OleBuildVersion(void)
160 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
161 return (rmm
<<16)+rup
;
164 /***********************************************************************
165 * OleInitialize (OLE32.@)
167 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
171 TRACE("(%p)\n", reserved
);
174 * The first duty of the OleInitialize is to initialize the COM libraries.
176 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
179 * If the CoInitializeEx call failed, the OLE libraries can't be
185 if (!COM_CurrentInfo()->ole_inits
)
191 * Then, it has to initialize the OLE specific modules.
195 * Object linking and Embedding
196 * In-place activation
198 if (!COM_CurrentInfo()->ole_inits
++ &&
199 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
202 * Initialize the libraries.
204 TRACE("() - Initializing the OLE libraries\n");
209 OLEClipbrd_Initialize();
219 OLEMenu_Initialize();
225 /******************************************************************************
226 * OleUninitialize [OLE32.@]
228 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
232 if (COM_CurrentInfo()->ole_inits
== 0)
234 WARN("ole_inits is already 0\n");
238 * If we hit the bottom of the lock stack, free the libraries.
240 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
243 * Actually free the libraries.
245 TRACE("() - Freeing the last reference count\n");
250 OLEClipbrd_UnInitialize();
255 OLEMenu_UnInitialize();
259 * Then, uninitialize the COM libraries.
264 /******************************************************************************
265 * OleInitializeWOW [OLE32.@]
267 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
268 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
272 /*************************************************************
273 * get_droptarget_handle
275 * Retrieve a handle to the map containing the marshalled IDropTarget.
276 * This handle belongs to the process that called RegisterDragDrop.
277 * See get_droptarget_local_handle().
279 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
281 return GetPropW(hwnd
, prop_marshalleddroptarget
);
284 /*************************************************************
287 * Is the window a droptarget.
289 static inline BOOL
is_droptarget(HWND hwnd
)
291 return get_droptarget_handle(hwnd
) != 0;
294 /*************************************************************
295 * get_droptarget_local_handle
297 * Retrieve a handle to the map containing the marshalled IDropTarget.
298 * The handle should be closed when finished with.
300 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
302 HANDLE handle
, local_handle
= 0;
304 handle
= get_droptarget_handle(hwnd
);
311 GetWindowThreadProcessId(hwnd
, &pid
);
312 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
315 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
316 CloseHandle(process
);
322 /***********************************************************************
323 * create_map_from_stream
325 * Helper for RegisterDragDrop. Creates a file mapping object
326 * with the contents of the provided stream. The stream must
327 * be a global memory backed stream.
329 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
336 hr
= GetHGlobalFromStream(stream
, &hmem
);
337 if(FAILED(hr
)) return hr
;
339 size
= GlobalSize(hmem
);
340 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
341 if(!*map
) return E_OUTOFMEMORY
;
343 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
344 memcpy(data
, GlobalLock(hmem
), size
);
346 UnmapViewOfFile(data
);
350 /***********************************************************************
351 * create_stream_from_map
353 * Creates a stream from the provided map.
355 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
357 HRESULT hr
= E_OUTOFMEMORY
;
360 MEMORY_BASIC_INFORMATION info
;
362 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
365 VirtualQuery(data
, &info
, sizeof(info
));
366 TRACE("size %d\n", (int)info
.RegionSize
);
368 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
371 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
373 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
375 UnmapViewOfFile(data
);
379 /* This is to work around apps which break COM rules by not implementing
380 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
381 * doesn't call CoMarshallInterface() in RegisterDragDrop().
382 * The wrapper is only used internally, and only exists for the life of
383 * the marshal. We don't want to hold a ref on the app provided target
384 * as some apps destroy this prior to CoUninitialize without calling
385 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
387 IDropTarget IDropTarget_iface
;
392 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
394 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
397 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
401 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
402 if (IsEqualIID(riid
, &IID_IUnknown
) ||
403 IsEqualIID(riid
, &IID_IDropTarget
))
405 IDropTarget_AddRef(&This
->IDropTarget_iface
);
406 *ppvObject
= &This
->IDropTarget_iface
;
410 return E_NOINTERFACE
;
413 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
415 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
416 return InterlockedIncrement(&This
->refs
);
419 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
421 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
422 ULONG refs
= InterlockedDecrement(&This
->refs
);
423 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
427 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
429 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
430 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
431 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
432 IDropTarget_AddRef( *target
);
436 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
437 IDataObject
* pDataObj
,
443 HRESULT r
= get_target_from_wrapper( iface
, &target
);
447 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
448 IDropTarget_Release( target
);
453 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
459 HRESULT r
= get_target_from_wrapper( iface
, &target
);
463 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
464 IDropTarget_Release( target
);
469 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
472 HRESULT r
= get_target_from_wrapper( iface
, &target
);
476 r
= IDropTarget_DragLeave( target
);
477 IDropTarget_Release( target
);
482 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
483 IDataObject
* pDataObj
,
489 HRESULT r
= get_target_from_wrapper( iface
, &target
);
493 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
494 IDropTarget_Release( target
);
499 static const IDropTargetVtbl DropTargetWrapperVTbl
=
501 DropTargetWrapper_QueryInterface
,
502 DropTargetWrapper_AddRef
,
503 DropTargetWrapper_Release
,
504 DropTargetWrapper_DragEnter
,
505 DropTargetWrapper_DragOver
,
506 DropTargetWrapper_DragLeave
,
507 DropTargetWrapper_Drop
510 static IDropTarget
* WrapDropTarget( HWND hwnd
)
512 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
516 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
520 return &This
->IDropTarget_iface
;
523 /***********************************************************************
524 * get_droptarget_pointer
526 * Retrieves the marshalled IDropTarget from the window.
528 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
530 IDropTarget
*droptarget
= NULL
;
534 map
= get_droptarget_local_handle(hwnd
);
535 if(!map
) return NULL
;
537 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
539 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
540 IStream_Release(stream
);
546 /***********************************************************************
547 * RegisterDragDrop (OLE32.@)
549 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
555 IDropTarget
*wrapper
;
557 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
559 if (!COM_CurrentApt())
561 ERR("COM not initialized\n");
562 return E_OUTOFMEMORY
;
570 ERR("invalid hwnd %p\n", hwnd
);
571 return DRAGDROP_E_INVALIDHWND
;
574 /* block register for other processes windows */
575 GetWindowThreadProcessId(hwnd
, &pid
);
576 if (pid
!= GetCurrentProcessId())
578 FIXME("register for another process windows is disabled\n");
579 return DRAGDROP_E_INVALIDHWND
;
582 /* check if the window is already registered */
583 if (is_droptarget(hwnd
))
584 return DRAGDROP_E_ALREADYREGISTERED
;
587 * Marshal the drop target pointer into a shared memory map and
588 * store the map's handle in a Wine specific window prop. We also
589 * store the drop target pointer itself in the
590 * "OleDropTargetInterface" prop for compatibility with Windows.
593 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
594 if(FAILED(hr
)) return hr
;
596 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
597 wrapper
= WrapDropTarget( hwnd
);
600 IStream_Release(stream
);
601 return E_OUTOFMEMORY
;
603 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
604 IDropTarget_Release(wrapper
);
608 hr
= create_map_from_stream(stream
, &map
);
611 IDropTarget_AddRef(pDropTarget
);
612 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
613 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
619 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
620 CoReleaseMarshalData(stream
);
623 IStream_Release(stream
);
628 /***********************************************************************
629 * RevokeDragDrop (OLE32.@)
631 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
635 IDropTarget
*drop_target
;
638 TRACE("(%p)\n", hwnd
);
642 ERR("invalid hwnd %p\n", hwnd
);
643 return DRAGDROP_E_INVALIDHWND
;
646 /* no registration data */
647 if (!(map
= get_droptarget_handle(hwnd
)))
648 return DRAGDROP_E_NOTREGISTERED
;
650 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
651 if(drop_target
) IDropTarget_Release(drop_target
);
653 RemovePropW(hwnd
, prop_oledroptarget
);
654 RemovePropW(hwnd
, prop_marshalleddroptarget
);
656 hr
= create_stream_from_map(map
, &stream
);
659 CoReleaseMarshalData(stream
);
660 IStream_Release(stream
);
667 /***********************************************************************
668 * OleRegGetUserType (OLE32.@)
670 HRESULT WINAPI
OleRegGetUserType(REFCLSID clsid
, DWORD form
, LPOLESTR
*usertype
)
672 static const WCHAR auxusertypeW
[] = {'A','u','x','U','s','e','r','T','y','p','e','\\','%','d',0};
673 DWORD valuetype
, valuelen
;
674 WCHAR auxkeynameW
[16];
679 TRACE("(%s, %u, %p)\n", debugstr_guid(clsid
), form
, usertype
);
686 /* Return immediately if it's not registered. */
687 hres
= COM_OpenKeyForCLSID(clsid
, NULL
, KEY_READ
, &usertypekey
);
693 /* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
694 if (form
!= USERCLASSTYPE_FULL
)
698 swprintf(auxkeynameW
, ARRAY_SIZE(auxkeynameW
), auxusertypeW
, form
);
699 if (COM_OpenKeyForCLSID(clsid
, auxkeynameW
, KEY_READ
, &auxkey
) == S_OK
)
701 if (!RegQueryValueExW(auxkey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
) && valuelen
)
703 RegCloseKey(usertypekey
);
704 usertypekey
= auxkey
;
712 if (RegQueryValueExW(usertypekey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
))
714 RegCloseKey(usertypekey
);
715 return REGDB_E_READREGDB
;
718 *usertype
= CoTaskMemAlloc(valuelen
);
721 RegCloseKey(usertypekey
);
722 return E_OUTOFMEMORY
;
725 ret
= RegQueryValueExW(usertypekey
,
731 RegCloseKey(usertypekey
);
732 if (ret
!= ERROR_SUCCESS
)
734 CoTaskMemFree(*usertype
);
736 return REGDB_E_READREGDB
;
742 /***********************************************************************
743 * DoDragDrop [OLE32.@]
745 HRESULT WINAPI
DoDragDrop (
746 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
747 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
748 DWORD dwOKEffect
, /* [in] effects allowed by the source */
749 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
751 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
752 TrackerWindowInfo trackerInfo
;
753 HWND hwndTrackWindow
;
756 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
758 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
762 * Setup the drag n drop tracking window.
765 trackerInfo
.dataObject
= pDataObject
;
766 trackerInfo
.dropSource
= pDropSource
;
767 trackerInfo
.dwOKEffect
= dwOKEffect
;
768 trackerInfo
.pdwEffect
= pdwEffect
;
769 trackerInfo
.trackingDone
= FALSE
;
770 trackerInfo
.inTrackCall
= FALSE
;
771 trackerInfo
.escPressed
= FALSE
;
772 trackerInfo
.curTargetHWND
= 0;
773 trackerInfo
.curDragTarget
= 0;
775 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
776 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
777 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
783 * Capture the mouse input
785 SetCapture(hwndTrackWindow
);
790 * Pump messages. All mouse input should go to the capture window.
792 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
794 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
795 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
796 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
798 if ( (msg
.message
>= WM_KEYFIRST
) &&
799 (msg
.message
<= WM_KEYLAST
) )
802 * When keyboard messages are sent to windows on this thread, we
803 * want to ignore notify the drop source that the state changed.
804 * in the case of the Escape key, we also notify the drop source
805 * we give it a special meaning.
807 if ( (msg
.message
==WM_KEYDOWN
) &&
808 (msg
.wParam
==VK_ESCAPE
) )
810 trackerInfo
.escPressed
= TRUE
;
814 * Notify the drop source.
816 OLEDD_TrackStateChange(&trackerInfo
);
821 * Dispatch the messages only when it's not a keyboard message.
823 DispatchMessageW(&msg
);
827 /* re-post the quit message to outer message loop */
828 if (msg
.message
== WM_QUIT
)
829 PostQuitMessage(msg
.wParam
);
831 * Destroy the temporary window.
833 DestroyWindow(hwndTrackWindow
);
835 return trackerInfo
.returnValue
;
841 /***********************************************************************
842 * OleQueryLinkFromData [OLE32.@]
844 HRESULT WINAPI
OleQueryLinkFromData(
845 IDataObject
* pSrcDataObject
)
847 FIXME("(%p),stub!\n", pSrcDataObject
);
851 /***********************************************************************
852 * OleRegGetMiscStatus [OLE32.@]
854 HRESULT WINAPI
OleRegGetMiscStatus(
859 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
860 static const WCHAR dfmtW
[] = {'%','d',0};
867 TRACE("(%s, %d, %p)\n", debugstr_guid(clsid
), dwAspect
, pdwStatus
);
869 if (!pdwStatus
) return E_INVALIDARG
;
873 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
875 hr
= COM_OpenKeyForCLSID(clsid
, miscstatusW
, KEY_READ
, &miscStatusKey
);
877 /* missing key is not a failure */
878 return hr
== REGDB_E_KEYMISSING
? S_OK
: hr
;
880 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
883 * Open the key specific to the requested aspect.
885 swprintf(keyName
, ARRAY_SIZE(keyName
), dfmtW
, dwAspect
);
887 result
= open_classes_key(miscStatusKey
, keyName
, KEY_READ
, &aspectKey
);
888 if (result
== ERROR_SUCCESS
)
890 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
891 RegCloseKey(aspectKey
);
894 RegCloseKey(miscStatusKey
);
898 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
902 IEnumOLEVERB IEnumOLEVERB_iface
;
909 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
911 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
914 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
915 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
917 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
918 if (IsEqualIID(riid
, &IID_IUnknown
) ||
919 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
921 IEnumOLEVERB_AddRef(iface
);
925 return E_NOINTERFACE
;
928 static ULONG WINAPI
EnumOLEVERB_AddRef(
931 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
933 return InterlockedIncrement(&This
->ref
);
936 static ULONG WINAPI
EnumOLEVERB_Release(
939 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
940 LONG refs
= InterlockedDecrement(&This
->ref
);
944 RegCloseKey(This
->hkeyVerb
);
945 HeapFree(GetProcessHeap(), 0, This
);
950 static HRESULT WINAPI
EnumOLEVERB_Next(
951 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
954 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
957 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
962 for (; celt
; celt
--, rgelt
++)
967 LPWSTR pwszMenuFlags
;
969 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, ARRAY_SIZE(wszSubKey
));
970 if (res
== ERROR_NO_MORE_ITEMS
)
975 else if (res
!= ERROR_SUCCESS
)
977 ERR("RegEnumKeyW failed with error %d\n", res
);
978 hr
= REGDB_E_READREGDB
;
981 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
982 if (res
!= ERROR_SUCCESS
)
984 ERR("RegQueryValueW failed with error %d\n", res
);
985 hr
= REGDB_E_READREGDB
;
988 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
994 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
995 if (res
!= ERROR_SUCCESS
)
997 ERR("RegQueryValueW failed with error %d\n", res
);
998 hr
= REGDB_E_READREGDB
;
999 CoTaskMemFree(pwszOLEVERB
);
1003 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
1004 pwszMenuFlags
= wcschr(pwszOLEVERB
, ',');
1007 hr
= OLEOBJ_E_INVALIDVERB
;
1008 CoTaskMemFree(pwszOLEVERB
);
1011 /* nul terminate the name string and advance to first character */
1012 *pwszMenuFlags
= '\0';
1014 pwszAttribs
= wcschr(pwszMenuFlags
, ',');
1017 hr
= OLEOBJ_E_INVALIDVERB
;
1018 CoTaskMemFree(pwszOLEVERB
);
1021 /* nul terminate the menu string and advance to first character */
1022 *pwszAttribs
= '\0';
1025 /* fill out structure for this verb */
1026 rgelt
->lVerb
= wcstol(wszSubKey
, NULL
, 10);
1027 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1028 rgelt
->fuFlags
= wcstol(pwszMenuFlags
, NULL
, 10);
1029 rgelt
->grfAttribs
= wcstol(pwszAttribs
, NULL
, 10);
1038 static HRESULT WINAPI
EnumOLEVERB_Skip(
1039 IEnumOLEVERB
*iface
, ULONG celt
)
1041 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1043 TRACE("(%d)\n", celt
);
1045 This
->index
+= celt
;
1049 static HRESULT WINAPI
EnumOLEVERB_Reset(
1050 IEnumOLEVERB
*iface
)
1052 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1060 static HRESULT WINAPI
EnumOLEVERB_Clone(
1061 IEnumOLEVERB
*iface
,
1062 IEnumOLEVERB
**ppenum
)
1064 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1066 TRACE("(%p)\n", ppenum
);
1067 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1068 return HRESULT_FROM_WIN32(GetLastError());
1069 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1072 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1074 EnumOLEVERB_QueryInterface
,
1076 EnumOLEVERB_Release
,
1083 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1085 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1088 RegCloseKey(hkeyVerb
);
1089 return E_OUTOFMEMORY
;
1091 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1093 This
->index
= index
;
1094 This
->hkeyVerb
= hkeyVerb
;
1095 *ppenum
= &This
->IEnumOLEVERB_iface
;
1099 /***********************************************************************
1100 * OleRegEnumVerbs [OLE32.@]
1102 * Enumerates verbs associated with a class stored in the registry.
1105 * clsid [I] Class ID to enumerate the verbs for.
1106 * ppenum [O] Enumerator.
1110 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1111 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1112 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1113 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1115 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1120 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1122 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1124 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1127 if (res
== REGDB_E_CLASSNOTREG
)
1128 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1129 else if (res
== REGDB_E_KEYMISSING
)
1130 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1132 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1133 debugstr_guid(clsid
), res
);
1137 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1138 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1139 if (res
!= ERROR_SUCCESS
)
1141 ERR("failed to get subkey count with error %d\n", GetLastError());
1142 return REGDB_E_READREGDB
;
1147 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1148 RegCloseKey(hkeyVerb
);
1149 return OLEOBJ_E_NOVERBS
;
1152 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1155 /******************************************************************************
1156 * OleSetContainedObject [OLE32.@]
1158 HRESULT WINAPI
OleSetContainedObject(
1162 IRunnableObject
* runnable
= NULL
;
1165 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1167 hres
= IUnknown_QueryInterface(pUnknown
,
1168 &IID_IRunnableObject
,
1171 if (SUCCEEDED(hres
))
1173 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1175 IRunnableObject_Release(runnable
);
1183 /******************************************************************************
1186 * Set the OLE object to the running state.
1189 * pUnknown [I] OLE object to run.
1193 * Failure: Any HRESULT code.
1195 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1197 IRunnableObject
*runable
;
1200 TRACE("(%p)\n", pUnknown
);
1202 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1204 return S_OK
; /* Appears to return no error. */
1206 hres
= IRunnableObject_Run(runable
, NULL
);
1207 IRunnableObject_Release(runable
);
1211 /******************************************************************************
1214 HRESULT WINAPI
OleLoad(
1217 LPOLECLIENTSITE pClientSite
,
1220 IPersistStorage
* persistStorage
= NULL
;
1222 IOleObject
* pOleObject
= NULL
;
1223 STATSTG storageInfo
;
1226 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1231 * TODO, Conversion ... OleDoAutoConvert
1235 * Get the class ID for the object.
1237 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1242 * Now, try and create the handler for the object
1244 hres
= CoCreateInstance(&storageInfo
.clsid
,
1246 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1251 * If that fails, as it will most times, load the default
1256 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1263 * If we couldn't find a handler... this is bad. Abort the whole thing.
1270 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1271 if (SUCCEEDED(hres
))
1274 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1279 * Initialize the object with its IPersistStorage interface.
1281 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1282 if (SUCCEEDED(hres
))
1284 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1286 IPersistStorage_Release(persistStorage
);
1287 persistStorage
= NULL
;
1290 if (SUCCEEDED(hres
) && pClientSite
)
1292 * Inform the new object of its client site.
1294 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1297 * Cleanup interfaces used internally
1300 IOleObject_Release(pOleObject
);
1302 if (SUCCEEDED(hres
))
1306 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1307 if (SUCCEEDED(hres1
))
1309 FIXME("handle OLE link\n");
1310 IOleLink_Release(pOleLink
);
1316 IUnknown_Release(pUnk
);
1325 /***********************************************************************
1328 HRESULT WINAPI
OleSave(
1329 LPPERSISTSTORAGE pPS
,
1336 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1339 * First, we transfer the class ID (if available)
1341 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1343 if (SUCCEEDED(hres
))
1345 WriteClassStg(pStg
, &objectClass
);
1349 * Then, we ask the object to save itself to the
1350 * storage. If it is successful, we commit the storage.
1352 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1354 if (SUCCEEDED(hres
))
1356 IStorage_Commit(pStg
,
1364 /******************************************************************************
1365 * OleLockRunning [OLE32.@]
1367 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1369 IRunnableObject
* runnable
= NULL
;
1372 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1374 hres
= IUnknown_QueryInterface(pUnknown
,
1375 &IID_IRunnableObject
,
1378 if (SUCCEEDED(hres
))
1380 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1382 IRunnableObject_Release(runnable
);
1391 /**************************************************************************
1392 * Internal methods to manage the shared OLE menu in response to the
1393 * OLE***MenuDescriptor API
1397 * OLEMenu_Initialize()
1399 * Initializes the OLEMENU data structures.
1401 static void OLEMenu_Initialize(void)
1406 * OLEMenu_UnInitialize()
1408 * Releases the OLEMENU data structures.
1410 static void OLEMenu_UnInitialize(void)
1414 /*************************************************************************
1415 * OLEMenu_InstallHooks
1416 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1418 * RETURNS: TRUE if message hooks were successfully installed
1421 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1423 OleMenuHookItem
*pHookItem
;
1425 /* Create an entry for the hook table */
1426 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1427 sizeof(OleMenuHookItem
)) ) )
1430 pHookItem
->tid
= tid
;
1431 pHookItem
->hHeap
= GetProcessHeap();
1432 pHookItem
->CallWndProc_hHook
= NULL
;
1434 /* Install a thread scope message hook for WH_GETMESSAGE */
1435 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1436 0, GetCurrentThreadId() );
1437 if ( !pHookItem
->GetMsg_hHook
)
1440 /* Install a thread scope message hook for WH_CALLWNDPROC */
1441 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1442 0, GetCurrentThreadId() );
1443 if ( !pHookItem
->CallWndProc_hHook
)
1446 /* Insert the hook table entry */
1447 pHookItem
->next
= hook_list
;
1448 hook_list
= pHookItem
;
1453 /* Unhook any hooks */
1454 if ( pHookItem
->GetMsg_hHook
)
1455 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1456 if ( pHookItem
->CallWndProc_hHook
)
1457 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1458 /* Release the hook table entry */
1459 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1464 /*************************************************************************
1465 * OLEMenu_UnInstallHooks
1466 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1468 * RETURNS: TRUE if message hooks were successfully installed
1471 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1473 OleMenuHookItem
*pHookItem
= NULL
;
1474 OleMenuHookItem
**ppHook
= &hook_list
;
1478 if ((*ppHook
)->tid
== tid
)
1480 pHookItem
= *ppHook
;
1481 *ppHook
= pHookItem
->next
;
1484 ppHook
= &(*ppHook
)->next
;
1486 if (!pHookItem
) return FALSE
;
1488 /* Uninstall the hooks installed for this thread */
1489 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1491 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1494 /* Release the hook table entry */
1495 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1500 /* Release the hook table entry */
1501 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1506 /*************************************************************************
1507 * OLEMenu_IsHookInstalled
1508 * Tests if OLEMenu hooks have been installed for a thread
1510 * RETURNS: The pointer and index of the hook table entry for the tid
1511 * NULL and -1 for the index if no hooks were installed for this thread
1513 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1515 OleMenuHookItem
*pHookItem
;
1517 /* Do a simple linear search for an entry whose tid matches ours.
1518 * We really need a map but efficiency is not a concern here. */
1519 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1521 if ( tid
== pHookItem
->tid
)
1528 /***********************************************************************
1529 * OLEMenu_FindMainMenuIndex
1531 * Used by OLEMenu API to find the top level group a menu item belongs to.
1532 * On success pnPos contains the index of the item in the top level menu group
1534 * RETURNS: TRUE if the ID was found, FALSE on failure
1536 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1540 nItems
= GetMenuItemCount( hMainMenu
);
1542 for (i
= 0; i
< nItems
; i
++)
1546 /* Is the current item a submenu? */
1547 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1549 /* If the handle is the same we're done */
1550 if ( hsubmenu
== hPopupMenu
)
1556 /* Recursively search without updating pnPos */
1557 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1569 /***********************************************************************
1570 * OLEMenu_SetIsServerMenu
1572 * Checks whether a popup menu belongs to a shared menu group which is
1573 * owned by the server, and sets the menu descriptor state accordingly.
1574 * All menu messages from these groups should be routed to the server.
1576 * RETURNS: TRUE if the popup menu is part of a server owned group
1577 * FALSE if the popup menu is part of a container owned group
1579 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1581 UINT nPos
= 0, nWidth
, i
;
1583 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1585 /* Don't bother searching if the popup is the combined menu itself */
1586 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1589 /* Find the menu item index in the shared OLE menu that this item belongs to */
1590 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1593 /* The group widths array has counts for the number of elements
1594 * in the groups File, Edit, Container, Object, Window, Help.
1595 * The Edit, Object & Help groups belong to the server object
1596 * and the other three belong to the container.
1597 * Loop through the group widths and locate the group we are a member of.
1599 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1601 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1602 if ( nPos
< nWidth
)
1604 /* Odd elements are server menu widths */
1605 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1610 return pOleMenuDescriptor
->bIsServerItem
;
1613 /*************************************************************************
1614 * OLEMenu_CallWndProc
1615 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1616 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1618 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1621 HOLEMENU hOleMenu
= 0;
1622 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1623 OleMenuHookItem
*pHookItem
= NULL
;
1626 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1628 /* Check if we're being asked to process the message */
1629 if ( HC_ACTION
!= code
)
1632 /* Retrieve the current message being dispatched from lParam */
1633 pMsg
= (LPCWPSTRUCT
)lParam
;
1635 /* Check if the message is destined for a window we are interested in:
1636 * If the window has an OLEMenu property we may need to dispatch
1637 * the menu message to its active objects window instead. */
1639 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1643 /* Get the menu descriptor */
1644 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1645 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1648 /* Process menu messages */
1649 switch( pMsg
->message
)
1653 /* Reset the menu descriptor state */
1654 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1656 /* Send this message to the server as well */
1657 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1658 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1662 case WM_INITMENUPOPUP
:
1664 /* Save the state for whether this is a server owned menu */
1665 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1671 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1672 if ( fuFlags
& MF_SYSMENU
)
1675 /* Save the state for whether this is a server owned popup menu */
1676 else if ( fuFlags
& MF_POPUP
)
1677 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1684 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1685 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1686 goto NEXTHOOK
; /* Not a menu message */
1695 /* If the message was for the server dispatch it accordingly */
1696 if ( pOleMenuDescriptor
->bIsServerItem
)
1698 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1699 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1703 if ( pOleMenuDescriptor
)
1704 GlobalUnlock( hOleMenu
);
1706 /* Lookup the hook item for the current thread */
1707 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1709 /* This should never fail!! */
1710 WARN("could not retrieve hHook for current thread!\n" );
1714 /* Pass on the message to the next hooker */
1715 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1718 /*************************************************************************
1719 * OLEMenu_GetMsgProc
1720 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1721 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1723 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1726 HOLEMENU hOleMenu
= 0;
1727 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1728 OleMenuHookItem
*pHookItem
= NULL
;
1731 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1733 /* Check if we're being asked to process a messages */
1734 if ( HC_ACTION
!= code
)
1737 /* Retrieve the current message being dispatched from lParam */
1738 pMsg
= (LPMSG
)lParam
;
1740 /* Check if the message is destined for a window we are interested in:
1741 * If the window has an OLEMenu property we may need to dispatch
1742 * the menu message to its active objects window instead. */
1744 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1748 /* Process menu messages */
1749 switch( pMsg
->message
)
1753 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1755 goto NEXTHOOK
; /* Not a menu message */
1762 /* Get the menu descriptor */
1763 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1764 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1767 /* If the message was for the server dispatch it accordingly */
1768 if ( pOleMenuDescriptor
->bIsServerItem
)
1770 /* Change the hWnd in the message to the active objects hWnd.
1771 * The message loop which reads this message will automatically
1772 * dispatch it to the embedded objects window. */
1773 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1777 if ( pOleMenuDescriptor
)
1778 GlobalUnlock( hOleMenu
);
1780 /* Lookup the hook item for the current thread */
1781 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1783 /* This should never fail!! */
1784 WARN("could not retrieve hHook for current thread!\n" );
1788 /* Pass on the message to the next hooker */
1789 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1792 /***********************************************************************
1793 * OleCreateMenuDescriptor [OLE32.@]
1794 * Creates an OLE menu descriptor for OLE to use when dispatching
1795 * menu messages and commands.
1798 * hmenuCombined - Handle to the objects combined menu
1799 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1802 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1803 HMENU hmenuCombined
,
1804 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1807 OleMenuDescriptor
*pOleMenuDescriptor
;
1810 if ( !hmenuCombined
|| !lpMenuWidths
)
1813 /* Create an OLE menu descriptor */
1814 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1815 sizeof(OleMenuDescriptor
) ) ) )
1818 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1819 if ( !pOleMenuDescriptor
)
1822 /* Initialize menu group widths and hmenu */
1823 for ( i
= 0; i
< 6; i
++ )
1824 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1826 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1827 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1828 GlobalUnlock( hOleMenu
);
1833 /***********************************************************************
1834 * OleDestroyMenuDescriptor [OLE32.@]
1835 * Destroy the shared menu descriptor
1837 HRESULT WINAPI
OleDestroyMenuDescriptor(
1838 HOLEMENU hmenuDescriptor
)
1840 if ( hmenuDescriptor
)
1841 GlobalFree( hmenuDescriptor
);
1845 /***********************************************************************
1846 * OleSetMenuDescriptor [OLE32.@]
1847 * Installs or removes OLE dispatching code for the containers frame window.
1850 * hOleMenu Handle to composite menu descriptor
1851 * hwndFrame Handle to containers frame window
1852 * hwndActiveObject Handle to objects in-place activation window
1853 * lpFrame Pointer to IOleInPlaceFrame on containers window
1854 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1857 * S_OK - menu installed correctly
1858 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1861 * The lpFrame and lpActiveObject parameters are currently ignored
1862 * OLE should install context sensitive help F1 filtering for the app when
1863 * these are non null.
1865 HRESULT WINAPI
OleSetMenuDescriptor(
1868 HWND hwndActiveObject
,
1869 LPOLEINPLACEFRAME lpFrame
,
1870 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1872 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1875 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1876 return E_INVALIDARG
;
1878 if ( lpFrame
|| lpActiveObject
)
1880 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1888 /* Set up a message hook to intercept the containers frame window messages.
1889 * The message filter is responsible for dispatching menu messages from the
1890 * shared menu which are intended for the object.
1893 if ( hOleMenu
) /* Want to install dispatching code */
1895 /* If OLEMenu hooks are already installed for this thread, fail
1896 * Note: This effectively means that OleSetMenuDescriptor cannot
1897 * be called twice in succession on the same frame window
1898 * without first calling it with a null hOleMenu to uninstall
1900 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1903 /* Get the menu descriptor */
1904 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1905 if ( !pOleMenuDescriptor
)
1906 return E_UNEXPECTED
;
1908 /* Update the menu descriptor */
1909 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1910 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1912 GlobalUnlock( hOleMenu
);
1913 pOleMenuDescriptor
= NULL
;
1915 /* Add a menu descriptor windows property to the frame window */
1916 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1918 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1919 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1922 else /* Want to uninstall dispatching code */
1924 /* Uninstall the hooks */
1925 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1928 /* Remove the menu descriptor property from the frame window */
1929 RemovePropW( hwndFrame
, prop_olemenuW
);
1935 /******************************************************************************
1936 * IsAccelerator [OLE32.@]
1937 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1939 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1944 if(!lpMsg
) return FALSE
;
1947 WARN_(accel
)("NULL accel handle\n");
1950 if((lpMsg
->message
!= WM_KEYDOWN
&&
1951 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1952 lpMsg
->message
!= WM_SYSCHAR
&&
1953 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1954 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1955 if (NULL
== lpAccelTbl
)
1959 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1961 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1962 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1966 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1967 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1968 hAccel
, cAccelEntries
,
1969 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1970 for(i
= 0; i
< cAccelEntries
; i
++)
1972 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1975 if(lpMsg
->message
== WM_CHAR
)
1977 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1979 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1985 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1988 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1989 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1990 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1991 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1992 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1993 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1994 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1998 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2000 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2001 { /* ^^ ALT pressed */
2002 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2010 WARN_(accel
)("couldn't translate accelerator key\n");
2011 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2015 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2016 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2020 /***********************************************************************
2021 * ReleaseStgMedium [OLE32.@]
2023 void WINAPI
ReleaseStgMedium(
2026 if (!pmedium
) return;
2028 switch (pmedium
->tymed
)
2032 if ( (pmedium
->pUnkForRelease
==0) &&
2033 (pmedium
->u
.hGlobal
!=0) )
2034 GlobalFree(pmedium
->u
.hGlobal
);
2039 if (pmedium
->u
.lpszFileName
!=0)
2041 if (pmedium
->pUnkForRelease
==0)
2043 DeleteFileW(pmedium
->u
.lpszFileName
);
2046 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2052 if (pmedium
->u
.pstm
!=0)
2054 IStream_Release(pmedium
->u
.pstm
);
2058 case TYMED_ISTORAGE
:
2060 if (pmedium
->u
.pstg
!=0)
2062 IStorage_Release(pmedium
->u
.pstg
);
2068 if ( (pmedium
->pUnkForRelease
==0) &&
2069 (pmedium
->u
.hBitmap
!=0) )
2070 DeleteObject(pmedium
->u
.hBitmap
);
2075 if ( (pmedium
->pUnkForRelease
==0) &&
2076 (pmedium
->u
.hMetaFilePict
!=0) )
2078 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2079 DeleteMetaFile(pMP
->hMF
);
2080 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2081 GlobalFree(pmedium
->u
.hMetaFilePict
);
2087 if ( (pmedium
->pUnkForRelease
==0) &&
2088 (pmedium
->u
.hEnhMetaFile
!=0) )
2090 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2098 pmedium
->tymed
=TYMED_NULL
;
2101 * After cleaning up, the unknown is released
2103 if (pmedium
->pUnkForRelease
!=0)
2105 IUnknown_Release(pmedium
->pUnkForRelease
);
2106 pmedium
->pUnkForRelease
= 0;
2111 * OLEDD_Initialize()
2113 * Initializes the OLE drag and drop data structures.
2115 static void OLEDD_Initialize(void)
2119 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2120 wndClass
.style
= CS_GLOBALCLASS
;
2121 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2122 wndClass
.cbClsExtra
= 0;
2123 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2124 wndClass
.hCursor
= 0;
2125 wndClass
.hbrBackground
= 0;
2126 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2128 RegisterClassW (&wndClass
);
2132 * OLEDD_DragTrackerWindowProc()
2134 * This method is the WindowProcedure of the drag n drop tracking
2135 * window. During a drag n Drop operation, an invisible window is created
2136 * to receive the user input and act upon it. This procedure is in charge
2140 #define DRAG_TIMER_ID 1
2142 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2152 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2154 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2155 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2164 case WM_LBUTTONDOWN
:
2165 case WM_MBUTTONDOWN
:
2166 case WM_RBUTTONDOWN
:
2168 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2169 if (trackerInfo
->trackingDone
) break;
2170 OLEDD_TrackStateChange(trackerInfo
);
2175 KillTimer(hwnd
, DRAG_TIMER_ID
);
2181 * This is a window proc after all. Let's call the default.
2183 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2186 static void drag_enter( TrackerWindowInfo
*info
, HWND new_target
)
2190 info
->curTargetHWND
= new_target
;
2192 while (new_target
&& !is_droptarget( new_target
))
2193 new_target
= GetParent( new_target
);
2195 info
->curDragTarget
= get_droptarget_pointer( new_target
);
2197 if (info
->curDragTarget
)
2199 *info
->pdwEffect
= info
->dwOKEffect
;
2200 hr
= IDropTarget_DragEnter( info
->curDragTarget
, info
->dataObject
,
2201 info
->dwKeyState
, info
->curMousePos
,
2203 *info
->pdwEffect
&= info
->dwOKEffect
;
2205 /* failed DragEnter() means invalid target */
2208 IDropTarget_Release( info
->curDragTarget
);
2209 info
->curDragTarget
= NULL
;
2210 info
->curTargetHWND
= NULL
;
2215 static void drag_end( TrackerWindowInfo
*info
)
2219 info
->trackingDone
= TRUE
;
2222 if (info
->curDragTarget
)
2224 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2225 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2227 *info
->pdwEffect
= info
->dwOKEffect
;
2228 hr
= IDropTarget_Drop( info
->curDragTarget
, info
->dataObject
, info
->dwKeyState
,
2229 info
->curMousePos
, info
->pdwEffect
);
2230 *info
->pdwEffect
&= info
->dwOKEffect
;
2233 info
->returnValue
= hr
;
2237 IDropTarget_DragLeave( info
->curDragTarget
);
2238 *info
->pdwEffect
= DROPEFFECT_NONE
;
2240 IDropTarget_Release( info
->curDragTarget
);
2241 info
->curDragTarget
= NULL
;
2244 *info
->pdwEffect
= DROPEFFECT_NONE
;
2247 static HRESULT
give_feedback( TrackerWindowInfo
*info
)
2253 if (info
->curDragTarget
== NULL
)
2254 *info
->pdwEffect
= DROPEFFECT_NONE
;
2256 hr
= IDropSource_GiveFeedback( info
->dropSource
, *info
->pdwEffect
);
2258 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2260 if (*info
->pdwEffect
& DROPEFFECT_MOVE
)
2262 else if (*info
->pdwEffect
& DROPEFFECT_COPY
)
2264 else if (*info
->pdwEffect
& DROPEFFECT_LINK
)
2267 res
= CURSOR_NODROP
;
2269 cur
= LoadCursorW( hProxyDll
, MAKEINTRESOURCEW( res
) );
2277 * OLEDD_TrackStateChange()
2279 * This method is invoked while a drag and drop operation is in effect.
2282 * trackerInfo - Pointer to the structure identifying the
2283 * drag & drop operation that is currently
2286 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2288 HWND hwndNewTarget
= 0;
2292 * This method may be called from QueryContinueDrag again,
2293 * (i.e. by running message loop) so avoid recursive call chain.
2295 if (trackerInfo
->inTrackCall
) return;
2296 trackerInfo
->inTrackCall
= TRUE
;
2299 * Get the handle of the window under the mouse
2301 pt
.x
= trackerInfo
->curMousePos
.x
;
2302 pt
.y
= trackerInfo
->curMousePos
.y
;
2303 hwndNewTarget
= WindowFromPoint(pt
);
2305 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2306 trackerInfo
->escPressed
,
2307 trackerInfo
->dwKeyState
);
2309 if (trackerInfo
->curTargetHWND
!= hwndNewTarget
&&
2310 (trackerInfo
->returnValue
== S_OK
||
2311 trackerInfo
->returnValue
== DRAGDROP_S_DROP
))
2313 if (trackerInfo
->curDragTarget
)
2315 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2316 IDropTarget_Release(trackerInfo
->curDragTarget
);
2317 trackerInfo
->curDragTarget
= NULL
;
2318 trackerInfo
->curTargetHWND
= NULL
;
2322 drag_enter( trackerInfo
, hwndNewTarget
);
2324 give_feedback( trackerInfo
);
2328 if (trackerInfo
->returnValue
== S_OK
)
2330 if (trackerInfo
->curDragTarget
)
2332 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2333 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2334 trackerInfo
->dwKeyState
,
2335 trackerInfo
->curMousePos
,
2336 trackerInfo
->pdwEffect
);
2337 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2339 give_feedback( trackerInfo
);
2342 drag_end( trackerInfo
);
2344 trackerInfo
->inTrackCall
= FALSE
;
2348 * OLEDD_GetButtonState()
2350 * This method will use the current state of the keyboard to build
2351 * a button state mask equivalent to the one passed in the
2352 * WM_MOUSEMOVE wParam.
2354 static DWORD
OLEDD_GetButtonState(void)
2356 BYTE keyboardState
[256];
2359 GetKeyboardState(keyboardState
);
2361 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2362 keyMask
|= MK_SHIFT
;
2364 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2365 keyMask
|= MK_CONTROL
;
2367 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2370 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2371 keyMask
|= MK_LBUTTON
;
2373 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2374 keyMask
|= MK_RBUTTON
;
2376 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2377 keyMask
|= MK_MBUTTON
;
2383 * OLEDD_GetButtonState()
2385 * This method will read the default value of the registry key in
2386 * parameter and extract a DWORD value from it. The registry key value
2387 * can be in a string key or a DWORD key.
2390 * regKey - Key to read the default value from
2391 * pdwValue - Pointer to the location where the DWORD
2392 * value is returned. This value is not modified
2393 * if the value is not found.
2396 static void OLEUTL_ReadRegistryDWORDValue(
2401 DWORD cbData
= sizeof(buffer
);
2405 lres
= RegQueryValueExW(regKey
,
2412 if (lres
==ERROR_SUCCESS
)
2417 *pdwValue
= *(DWORD
*)buffer
;
2422 *pdwValue
= wcstoul(buffer
, NULL
, 10);
2428 /******************************************************************************
2431 * The operation of this function is documented literally in the WinAPI
2432 * documentation to involve a QueryInterface for the IViewObject interface,
2433 * followed by a call to IViewObject::Draw.
2435 HRESULT WINAPI
OleDraw(
2442 IViewObject
*viewobject
;
2444 if (!pUnk
) return E_INVALIDARG
;
2446 hres
= IUnknown_QueryInterface(pUnk
,
2448 (void**)&viewobject
);
2449 if (SUCCEEDED(hres
))
2451 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2452 IViewObject_Release(viewobject
);
2456 return DV_E_NOIVIEWOBJECT
;
2459 /***********************************************************************
2460 * OleTranslateAccelerator [OLE32.@]
2462 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2463 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2467 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2469 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2470 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2475 /******************************************************************************
2476 * OleCreate [OLE32.@]
2479 HRESULT WINAPI
OleCreate(
2483 LPFORMATETC pFormatEtc
,
2484 LPOLECLIENTSITE pClientSite
,
2489 IUnknown
* pUnk
= NULL
;
2490 IOleObject
*pOleObject
= NULL
;
2492 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2493 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2495 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2497 if (SUCCEEDED(hres
))
2498 hres
= IStorage_SetClass(pStg
, rclsid
);
2500 if (pClientSite
&& SUCCEEDED(hres
))
2502 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2503 if (SUCCEEDED(hres
))
2506 IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2510 if (SUCCEEDED(hres
))
2512 IPersistStorage
* pPS
;
2513 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2515 TRACE("trying to set stg %p\n", pStg
);
2516 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2517 TRACE("-- result 0x%08x\n", hres
);
2518 IPersistStorage_Release(pPS
);
2522 if (pClientSite
&& SUCCEEDED(hres
))
2524 TRACE("trying to set clientsite %p\n", pClientSite
);
2525 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2526 TRACE("-- result 0x%08x\n", hres
);
2530 IOleObject_Release(pOleObject
);
2532 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2535 hres
= OleRun(pUnk
);
2536 if (SUCCEEDED(hres
))
2538 IOleCache
*pOleCache
;
2540 if (SUCCEEDED(IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
)))
2543 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2547 pfe
.dwAspect
= DVASPECT_CONTENT
;
2549 pfe
.tymed
= TYMED_NULL
;
2550 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2553 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2554 IOleCache_Release(pOleCache
);
2559 if (FAILED(hres
) && pUnk
)
2561 IUnknown_Release(pUnk
);
2567 TRACE("-- %p\n", pUnk
);
2571 /******************************************************************************
2572 * OleGetAutoConvert [OLE32.@]
2574 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2576 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2578 WCHAR buf
[CHARS_IN_GUID
];
2582 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2587 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2589 res
= REGDB_E_KEYMISSING
;
2592 res
= CLSIDFromString(buf
, pClsidNew
);
2594 if (hkey
) RegCloseKey(hkey
);
2598 /******************************************************************************
2599 * OleSetAutoConvert [OLE32.@]
2601 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2603 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2605 WCHAR szClsidNew
[CHARS_IN_GUID
];
2608 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2610 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2613 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2614 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (lstrlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2616 res
= REGDB_E_WRITEREGDB
;
2621 if (hkey
) RegCloseKey(hkey
);
2625 /******************************************************************************
2626 * OleDoAutoConvert [OLE32.@]
2628 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2630 WCHAR
*user_type_old
, *user_type_new
;
2636 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2638 *pClsidNew
= CLSID_NULL
;
2640 return E_INVALIDARG
;
2641 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2645 *pClsidNew
= stat
.clsid
;
2646 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2650 hr
= IStorage_SetClass(pStg
, &clsid
);
2654 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2657 user_type_new
= NULL
;
2660 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2662 user_type_new
= NULL
;
2664 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2665 CoTaskMemFree(user_type_new
);
2668 CoTaskMemFree(user_type_old
);
2669 IStorage_SetClass(pStg
, &stat
.clsid
);
2673 hr
= SetConvertStg(pStg
, TRUE
);
2676 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2677 IStorage_SetClass(pStg
, &stat
.clsid
);
2681 CoTaskMemFree(user_type_old
);
2685 /******************************************************************************
2686 * OleIsRunning [OLE32.@]
2688 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2690 IRunnableObject
*pRunnable
;
2694 TRACE("(%p)\n", object
);
2696 if (!object
) return FALSE
;
2698 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2701 running
= IRunnableObject_IsRunning(pRunnable
);
2702 IRunnableObject_Release(pRunnable
);
2706 /***********************************************************************
2707 * OleNoteObjectVisible [OLE32.@]
2709 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2711 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2712 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2715 /***********************************************************************
2716 * PropSysAllocString [OLE32.@]
2718 * Forward to oleaut32.
2720 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2722 return SysAllocString(str
);
2725 /***********************************************************************
2726 * PropSysFreeString [OLE32.@]
2728 * Forward to oleaut32.
2730 void WINAPI
PropSysFreeString(LPOLESTR str
)