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
35 #define NONAMELESSUNION
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
50 #include "wine/list.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
55 WINE_DECLARE_DEBUG_CHANNEL(accel
);
57 /******************************************************************************
58 * These are static/global variables and internal data structures that the
59 * OLE module uses to maintain its state.
61 typedef struct tagTrackerWindowInfo
63 IDataObject
* dataObject
;
64 IDropSource
* dropSource
;
71 HWND curTargetHWND
; /* window the mouse is hovering over */
72 IDropTarget
* curDragTarget
;
73 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
74 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
77 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
79 HWND hwndFrame
; /* The containers frame window */
80 HWND hwndActiveObject
; /* The active objects window */
81 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
82 HMENU hmenuCombined
; /* The combined menu */
83 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
86 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
88 DWORD tid
; /* Thread Id */
89 HANDLE hHeap
; /* Heap this is allocated from */
90 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
91 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
92 struct tagOleMenuHookItem
*next
;
95 static OleMenuHookItem
*hook_list
;
98 * This is the lock count on the OLE library. It is controlled by the
99 * OLEInitialize/OLEUninitialize methods.
101 static LONG OLE_moduleLockCount
= 0;
104 * Name of our registered window class.
106 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
107 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
110 * Name of menu descriptor property.
112 static const WCHAR prop_olemenuW
[] =
113 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
115 /* property to store IDropTarget pointer */
116 static const WCHAR prop_oledroptarget
[] =
117 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
119 /* property to store Marshalled IDropTarget pointer */
120 static const WCHAR prop_marshalleddroptarget
[] =
121 {'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};
123 static const WCHAR emptyW
[] = { 0 };
125 /******************************************************************************
126 * These are the prototypes of miscellaneous utility methods
128 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
130 /******************************************************************************
131 * These are the prototypes of the utility methods used to manage a shared menu
133 static void OLEMenu_Initialize(void);
134 static void OLEMenu_UnInitialize(void);
135 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
136 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
137 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
138 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
139 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
140 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
141 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
143 /******************************************************************************
144 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
146 extern void OLEClipbrd_UnInitialize(void);
147 extern void OLEClipbrd_Initialize(void);
149 /******************************************************************************
150 * These are the prototypes of the utility methods used for OLE Drag n Drop
152 static void OLEDD_Initialize(void);
153 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
154 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
155 static DWORD
OLEDD_GetButtonState(void);
157 /******************************************************************************
158 * OleBuildVersion [OLE32.@]
160 DWORD WINAPI
OleBuildVersion(void)
162 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
163 return (rmm
<<16)+rup
;
166 /***********************************************************************
167 * OleInitialize (OLE32.@)
169 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
173 TRACE("(%p)\n", reserved
);
176 * The first duty of the OleInitialize is to initialize the COM libraries.
178 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
181 * If the CoInitializeEx call failed, the OLE libraries can't be
187 if (!COM_CurrentInfo()->ole_inits
)
193 * Then, it has to initialize the OLE specific modules.
197 * Object linking and Embedding
198 * In-place activation
200 if (!COM_CurrentInfo()->ole_inits
++ &&
201 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
204 * Initialize the libraries.
206 TRACE("() - Initializing the OLE libraries\n");
211 OLEClipbrd_Initialize();
221 OLEMenu_Initialize();
227 /******************************************************************************
228 * OleUninitialize [OLE32.@]
230 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
234 if (COM_CurrentInfo()->ole_inits
== 0)
236 WARN("ole_inits is already 0\n");
240 * If we hit the bottom of the lock stack, free the libraries.
242 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
245 * Actually free the libraries.
247 TRACE("() - Freeing the last reference count\n");
252 OLEClipbrd_UnInitialize();
257 OLEMenu_UnInitialize();
261 * Then, uninitialize the COM libraries.
266 /******************************************************************************
267 * OleInitializeWOW [OLE32.@]
269 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
270 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
274 /*************************************************************
275 * get_droptarget_handle
277 * Retrieve a handle to the map containing the marshalled IDropTarget.
278 * This handle belongs to the process that called RegisterDragDrop.
279 * See get_droptarget_local_handle().
281 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
283 return GetPropW(hwnd
, prop_marshalleddroptarget
);
286 /*************************************************************
289 * Is the window a droptarget.
291 static inline BOOL
is_droptarget(HWND hwnd
)
293 return get_droptarget_handle(hwnd
) != 0;
296 /*************************************************************
297 * get_droptarget_local_handle
299 * Retrieve a handle to the map containing the marshalled IDropTarget.
300 * The handle should be closed when finished with.
302 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
304 HANDLE handle
, local_handle
= 0;
306 handle
= get_droptarget_handle(hwnd
);
313 GetWindowThreadProcessId(hwnd
, &pid
);
314 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
317 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
318 CloseHandle(process
);
324 /***********************************************************************
325 * create_map_from_stream
327 * Helper for RegisterDragDrop. Creates a file mapping object
328 * with the contents of the provided stream. The stream must
329 * be a global memory backed stream.
331 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
338 hr
= GetHGlobalFromStream(stream
, &hmem
);
339 if(FAILED(hr
)) return hr
;
341 size
= GlobalSize(hmem
);
342 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
343 if(!*map
) return E_OUTOFMEMORY
;
345 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
346 memcpy(data
, GlobalLock(hmem
), size
);
348 UnmapViewOfFile(data
);
352 /***********************************************************************
353 * create_stream_from_map
355 * Creates a stream from the provided map.
357 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
359 HRESULT hr
= E_OUTOFMEMORY
;
362 MEMORY_BASIC_INFORMATION info
;
364 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
367 VirtualQuery(data
, &info
, sizeof(info
));
368 TRACE("size %d\n", (int)info
.RegionSize
);
370 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
373 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
375 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
377 UnmapViewOfFile(data
);
381 /* This is to work around apps which break COM rules by not implementing
382 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
383 * doesn't call CoMarshallInterface() in RegisterDragDrop().
384 * The wrapper is only used internally, and only exists for the life of
385 * the marshal. We don't want to hold a ref on the app provided target
386 * as some apps destroy this prior to CoUninitialize without calling
387 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
389 IDropTarget IDropTarget_iface
;
394 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
396 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
399 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
403 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
404 if (IsEqualIID(riid
, &IID_IUnknown
) ||
405 IsEqualIID(riid
, &IID_IDropTarget
))
407 IDropTarget_AddRef(&This
->IDropTarget_iface
);
408 *ppvObject
= &This
->IDropTarget_iface
;
412 return E_NOINTERFACE
;
415 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
417 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
418 return InterlockedIncrement(&This
->refs
);
421 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
423 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
424 ULONG refs
= InterlockedDecrement(&This
->refs
);
425 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
429 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
431 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
432 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
433 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
434 IDropTarget_AddRef( *target
);
438 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
439 IDataObject
* pDataObj
,
445 HRESULT r
= get_target_from_wrapper( iface
, &target
);
449 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
450 IDropTarget_Release( target
);
455 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
461 HRESULT r
= get_target_from_wrapper( iface
, &target
);
465 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
466 IDropTarget_Release( target
);
471 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
474 HRESULT r
= get_target_from_wrapper( iface
, &target
);
478 r
= IDropTarget_DragLeave( target
);
479 IDropTarget_Release( target
);
484 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
485 IDataObject
* pDataObj
,
491 HRESULT r
= get_target_from_wrapper( iface
, &target
);
495 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
496 IDropTarget_Release( target
);
501 static const IDropTargetVtbl DropTargetWrapperVTbl
=
503 DropTargetWrapper_QueryInterface
,
504 DropTargetWrapper_AddRef
,
505 DropTargetWrapper_Release
,
506 DropTargetWrapper_DragEnter
,
507 DropTargetWrapper_DragOver
,
508 DropTargetWrapper_DragLeave
,
509 DropTargetWrapper_Drop
512 static IDropTarget
* WrapDropTarget( HWND hwnd
)
514 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
518 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
522 return &This
->IDropTarget_iface
;
525 /***********************************************************************
526 * get_droptarget_pointer
528 * Retrieves the marshalled IDropTarget from the window.
530 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
532 IDropTarget
*droptarget
= NULL
;
536 map
= get_droptarget_local_handle(hwnd
);
537 if(!map
) return NULL
;
539 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
541 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
542 IStream_Release(stream
);
548 /***********************************************************************
549 * RegisterDragDrop (OLE32.@)
551 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
557 IDropTarget
*wrapper
;
559 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
561 if (!COM_CurrentApt())
563 ERR("COM not initialized\n");
564 return E_OUTOFMEMORY
;
572 ERR("invalid hwnd %p\n", hwnd
);
573 return DRAGDROP_E_INVALIDHWND
;
576 /* block register for other processes windows */
577 GetWindowThreadProcessId(hwnd
, &pid
);
578 if (pid
!= GetCurrentProcessId())
580 FIXME("register for another process windows is disabled\n");
581 return DRAGDROP_E_INVALIDHWND
;
584 /* check if the window is already registered */
585 if (is_droptarget(hwnd
))
586 return DRAGDROP_E_ALREADYREGISTERED
;
589 * Marshal the drop target pointer into a shared memory map and
590 * store the map's handle in a Wine specific window prop. We also
591 * store the drop target pointer itself in the
592 * "OleDropTargetInterface" prop for compatibility with Windows.
595 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
596 if(FAILED(hr
)) return hr
;
598 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
599 wrapper
= WrapDropTarget( hwnd
);
602 IStream_Release(stream
);
603 return E_OUTOFMEMORY
;
605 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
606 IDropTarget_Release(wrapper
);
610 hr
= create_map_from_stream(stream
, &map
);
613 IDropTarget_AddRef(pDropTarget
);
614 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
615 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
621 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
622 CoReleaseMarshalData(stream
);
625 IStream_Release(stream
);
630 /***********************************************************************
631 * RevokeDragDrop (OLE32.@)
633 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
637 IDropTarget
*drop_target
;
640 TRACE("(%p)\n", hwnd
);
644 ERR("invalid hwnd %p\n", hwnd
);
645 return DRAGDROP_E_INVALIDHWND
;
648 /* no registration data */
649 if (!(map
= get_droptarget_handle(hwnd
)))
650 return DRAGDROP_E_NOTREGISTERED
;
652 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
653 if(drop_target
) IDropTarget_Release(drop_target
);
655 RemovePropW(hwnd
, prop_oledroptarget
);
656 RemovePropW(hwnd
, prop_marshalleddroptarget
);
658 hr
= create_stream_from_map(map
, &stream
);
661 CoReleaseMarshalData(stream
);
662 IStream_Release(stream
);
669 /***********************************************************************
670 * OleRegGetUserType (OLE32.@)
672 HRESULT WINAPI
OleRegGetUserType(REFCLSID clsid
, DWORD form
, LPOLESTR
*usertype
)
674 static const WCHAR auxusertypeW
[] = {'A','u','x','U','s','e','r','T','y','p','e','\\','%','d',0};
675 DWORD valuetype
, valuelen
;
676 WCHAR auxkeynameW
[16];
681 TRACE("(%s, %u, %p)\n", debugstr_guid(clsid
), form
, usertype
);
688 /* Return immediately if it's not registered. */
689 hres
= COM_OpenKeyForCLSID(clsid
, NULL
, KEY_READ
, &usertypekey
);
695 /* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
696 if (form
!= USERCLASSTYPE_FULL
)
700 sprintfW(auxkeynameW
, auxusertypeW
, form
);
701 if (COM_OpenKeyForCLSID(clsid
, auxkeynameW
, KEY_READ
, &auxkey
) == S_OK
)
703 if (!RegQueryValueExW(auxkey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
) && valuelen
)
705 RegCloseKey(usertypekey
);
706 usertypekey
= auxkey
;
714 if (RegQueryValueExW(usertypekey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
))
716 RegCloseKey(usertypekey
);
717 return REGDB_E_READREGDB
;
720 *usertype
= CoTaskMemAlloc(valuelen
);
723 RegCloseKey(usertypekey
);
724 return E_OUTOFMEMORY
;
727 ret
= RegQueryValueExW(usertypekey
,
733 RegCloseKey(usertypekey
);
734 if (ret
!= ERROR_SUCCESS
)
736 CoTaskMemFree(*usertype
);
738 return REGDB_E_READREGDB
;
744 /***********************************************************************
745 * DoDragDrop [OLE32.@]
747 HRESULT WINAPI
DoDragDrop (
748 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
749 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
750 DWORD dwOKEffect
, /* [in] effects allowed by the source */
751 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
753 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
754 TrackerWindowInfo trackerInfo
;
755 HWND hwndTrackWindow
;
758 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
760 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
764 * Setup the drag n drop tracking window.
767 trackerInfo
.dataObject
= pDataObject
;
768 trackerInfo
.dropSource
= pDropSource
;
769 trackerInfo
.dwOKEffect
= dwOKEffect
;
770 trackerInfo
.pdwEffect
= pdwEffect
;
771 trackerInfo
.trackingDone
= FALSE
;
772 trackerInfo
.escPressed
= FALSE
;
773 trackerInfo
.curTargetHWND
= 0;
774 trackerInfo
.curDragTarget
= 0;
776 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
777 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
778 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
784 * Capture the mouse input
786 SetCapture(hwndTrackWindow
);
791 * Pump messages. All mouse input should go to the capture window.
793 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
795 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
796 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
797 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
799 if ( (msg
.message
>= WM_KEYFIRST
) &&
800 (msg
.message
<= WM_KEYLAST
) )
803 * When keyboard messages are sent to windows on this thread, we
804 * want to ignore notify the drop source that the state changed.
805 * in the case of the Escape key, we also notify the drop source
806 * we give it a special meaning.
808 if ( (msg
.message
==WM_KEYDOWN
) &&
809 (msg
.wParam
==VK_ESCAPE
) )
811 trackerInfo
.escPressed
= TRUE
;
815 * Notify the drop source.
817 OLEDD_TrackStateChange(&trackerInfo
);
822 * Dispatch the messages only when it's not a keyboard message.
824 DispatchMessageW(&msg
);
828 /* re-post the quit message to outer message loop */
829 if (msg
.message
== WM_QUIT
)
830 PostQuitMessage(msg
.wParam
);
832 * Destroy the temporary window.
834 DestroyWindow(hwndTrackWindow
);
836 return trackerInfo
.returnValue
;
842 /***********************************************************************
843 * OleQueryLinkFromData [OLE32.@]
845 HRESULT WINAPI
OleQueryLinkFromData(
846 IDataObject
* pSrcDataObject
)
848 FIXME("(%p),stub!\n", pSrcDataObject
);
852 /***********************************************************************
853 * OleRegGetMiscStatus [OLE32.@]
855 HRESULT WINAPI
OleRegGetMiscStatus(
860 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
861 static const WCHAR dfmtW
[] = {'%','d',0};
868 TRACE("(%s, %d, %p)\n", debugstr_guid(clsid
), dwAspect
, pdwStatus
);
870 if (!pdwStatus
) return E_INVALIDARG
;
874 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
876 hr
= COM_OpenKeyForCLSID(clsid
, miscstatusW
, KEY_READ
, &miscStatusKey
);
878 /* missing key is not a failure */
879 return hr
== REGDB_E_KEYMISSING
? S_OK
: hr
;
881 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
884 * Open the key specific to the requested aspect.
886 sprintfW(keyName
, dfmtW
, dwAspect
);
888 result
= open_classes_key(miscStatusKey
, keyName
, KEY_READ
, &aspectKey
);
889 if (result
== ERROR_SUCCESS
)
891 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
892 RegCloseKey(aspectKey
);
895 RegCloseKey(miscStatusKey
);
899 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
903 IEnumOLEVERB IEnumOLEVERB_iface
;
910 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
912 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
915 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
916 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
918 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
919 if (IsEqualIID(riid
, &IID_IUnknown
) ||
920 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
922 IEnumOLEVERB_AddRef(iface
);
926 return E_NOINTERFACE
;
929 static ULONG WINAPI
EnumOLEVERB_AddRef(
932 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
934 return InterlockedIncrement(&This
->ref
);
937 static ULONG WINAPI
EnumOLEVERB_Release(
940 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
941 LONG refs
= InterlockedDecrement(&This
->ref
);
945 RegCloseKey(This
->hkeyVerb
);
946 HeapFree(GetProcessHeap(), 0, This
);
951 static HRESULT WINAPI
EnumOLEVERB_Next(
952 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
955 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
958 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
963 for (; celt
; celt
--, rgelt
++)
968 LPWSTR pwszMenuFlags
;
970 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
971 if (res
== ERROR_NO_MORE_ITEMS
)
976 else if (res
!= ERROR_SUCCESS
)
978 ERR("RegEnumKeyW failed with error %d\n", res
);
979 hr
= REGDB_E_READREGDB
;
982 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
983 if (res
!= ERROR_SUCCESS
)
985 ERR("RegQueryValueW failed with error %d\n", res
);
986 hr
= REGDB_E_READREGDB
;
989 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
995 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
996 if (res
!= ERROR_SUCCESS
)
998 ERR("RegQueryValueW failed with error %d\n", res
);
999 hr
= REGDB_E_READREGDB
;
1000 CoTaskMemFree(pwszOLEVERB
);
1004 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
1005 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
1008 hr
= OLEOBJ_E_INVALIDVERB
;
1009 CoTaskMemFree(pwszOLEVERB
);
1012 /* nul terminate the name string and advance to first character */
1013 *pwszMenuFlags
= '\0';
1015 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
1018 hr
= OLEOBJ_E_INVALIDVERB
;
1019 CoTaskMemFree(pwszOLEVERB
);
1022 /* nul terminate the menu string and advance to first character */
1023 *pwszAttribs
= '\0';
1026 /* fill out structure for this verb */
1027 rgelt
->lVerb
= atolW(wszSubKey
);
1028 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1029 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
1030 rgelt
->grfAttribs
= atolW(pwszAttribs
);
1039 static HRESULT WINAPI
EnumOLEVERB_Skip(
1040 IEnumOLEVERB
*iface
, ULONG celt
)
1042 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1044 TRACE("(%d)\n", celt
);
1046 This
->index
+= celt
;
1050 static HRESULT WINAPI
EnumOLEVERB_Reset(
1051 IEnumOLEVERB
*iface
)
1053 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1061 static HRESULT WINAPI
EnumOLEVERB_Clone(
1062 IEnumOLEVERB
*iface
,
1063 IEnumOLEVERB
**ppenum
)
1065 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1067 TRACE("(%p)\n", ppenum
);
1068 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1069 return HRESULT_FROM_WIN32(GetLastError());
1070 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1073 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1075 EnumOLEVERB_QueryInterface
,
1077 EnumOLEVERB_Release
,
1084 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1086 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1089 RegCloseKey(hkeyVerb
);
1090 return E_OUTOFMEMORY
;
1092 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1094 This
->index
= index
;
1095 This
->hkeyVerb
= hkeyVerb
;
1096 *ppenum
= &This
->IEnumOLEVERB_iface
;
1100 /***********************************************************************
1101 * OleRegEnumVerbs [OLE32.@]
1103 * Enumerates verbs associated with a class stored in the registry.
1106 * clsid [I] Class ID to enumerate the verbs for.
1107 * ppenum [O] Enumerator.
1111 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1112 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1113 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1114 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1116 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1121 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1123 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1125 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1128 if (res
== REGDB_E_CLASSNOTREG
)
1129 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1130 else if (res
== REGDB_E_KEYMISSING
)
1131 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1133 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1134 debugstr_guid(clsid
), res
);
1138 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1139 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1140 if (res
!= ERROR_SUCCESS
)
1142 ERR("failed to get subkey count with error %d\n", GetLastError());
1143 return REGDB_E_READREGDB
;
1148 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1149 RegCloseKey(hkeyVerb
);
1150 return OLEOBJ_E_NOVERBS
;
1153 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1156 /******************************************************************************
1157 * OleSetContainedObject [OLE32.@]
1159 HRESULT WINAPI
OleSetContainedObject(
1163 IRunnableObject
* runnable
= NULL
;
1166 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1168 hres
= IUnknown_QueryInterface(pUnknown
,
1169 &IID_IRunnableObject
,
1172 if (SUCCEEDED(hres
))
1174 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1176 IRunnableObject_Release(runnable
);
1184 /******************************************************************************
1187 * Set the OLE object to the running state.
1190 * pUnknown [I] OLE object to run.
1194 * Failure: Any HRESULT code.
1196 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1198 IRunnableObject
*runable
;
1201 TRACE("(%p)\n", pUnknown
);
1203 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1205 return S_OK
; /* Appears to return no error. */
1207 hres
= IRunnableObject_Run(runable
, NULL
);
1208 IRunnableObject_Release(runable
);
1212 /******************************************************************************
1215 HRESULT WINAPI
OleLoad(
1218 LPOLECLIENTSITE pClientSite
,
1221 IPersistStorage
* persistStorage
= NULL
;
1223 IOleObject
* pOleObject
= NULL
;
1224 STATSTG storageInfo
;
1227 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1232 * TODO, Conversion ... OleDoAutoConvert
1236 * Get the class ID for the object.
1238 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1243 * Now, try and create the handler for the object
1245 hres
= CoCreateInstance(&storageInfo
.clsid
,
1247 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1252 * If that fails, as it will most times, load the default
1257 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1264 * If we couldn't find a handler... this is bad. Abort the whole thing.
1271 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1272 if (SUCCEEDED(hres
))
1275 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1280 * Initialize the object with its IPersistStorage interface.
1282 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1283 if (SUCCEEDED(hres
))
1285 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1287 IPersistStorage_Release(persistStorage
);
1288 persistStorage
= NULL
;
1291 if (SUCCEEDED(hres
) && pClientSite
)
1293 * Inform the new object of its client site.
1295 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1298 * Cleanup interfaces used internally
1301 IOleObject_Release(pOleObject
);
1303 if (SUCCEEDED(hres
))
1307 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1308 if (SUCCEEDED(hres1
))
1310 FIXME("handle OLE link\n");
1311 IOleLink_Release(pOleLink
);
1317 IUnknown_Release(pUnk
);
1326 /***********************************************************************
1329 HRESULT WINAPI
OleSave(
1330 LPPERSISTSTORAGE pPS
,
1337 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1340 * First, we transfer the class ID (if available)
1342 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1344 if (SUCCEEDED(hres
))
1346 WriteClassStg(pStg
, &objectClass
);
1350 * Then, we ask the object to save itself to the
1351 * storage. If it is successful, we commit the storage.
1353 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1355 if (SUCCEEDED(hres
))
1357 IStorage_Commit(pStg
,
1365 /******************************************************************************
1366 * OleLockRunning [OLE32.@]
1368 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1370 IRunnableObject
* runnable
= NULL
;
1373 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1375 hres
= IUnknown_QueryInterface(pUnknown
,
1376 &IID_IRunnableObject
,
1379 if (SUCCEEDED(hres
))
1381 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1383 IRunnableObject_Release(runnable
);
1392 /**************************************************************************
1393 * Internal methods to manage the shared OLE menu in response to the
1394 * OLE***MenuDescriptor API
1398 * OLEMenu_Initialize()
1400 * Initializes the OLEMENU data structures.
1402 static void OLEMenu_Initialize(void)
1407 * OLEMenu_UnInitialize()
1409 * Releases the OLEMENU data structures.
1411 static void OLEMenu_UnInitialize(void)
1415 /*************************************************************************
1416 * OLEMenu_InstallHooks
1417 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1419 * RETURNS: TRUE if message hooks were successfully installed
1422 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1424 OleMenuHookItem
*pHookItem
;
1426 /* Create an entry for the hook table */
1427 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1428 sizeof(OleMenuHookItem
)) ) )
1431 pHookItem
->tid
= tid
;
1432 pHookItem
->hHeap
= GetProcessHeap();
1433 pHookItem
->CallWndProc_hHook
= NULL
;
1435 /* Install a thread scope message hook for WH_GETMESSAGE */
1436 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1437 0, GetCurrentThreadId() );
1438 if ( !pHookItem
->GetMsg_hHook
)
1441 /* Install a thread scope message hook for WH_CALLWNDPROC */
1442 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1443 0, GetCurrentThreadId() );
1444 if ( !pHookItem
->CallWndProc_hHook
)
1447 /* Insert the hook table entry */
1448 pHookItem
->next
= hook_list
;
1449 hook_list
= pHookItem
;
1454 /* Unhook any hooks */
1455 if ( pHookItem
->GetMsg_hHook
)
1456 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1457 if ( pHookItem
->CallWndProc_hHook
)
1458 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1459 /* Release the hook table entry */
1460 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1465 /*************************************************************************
1466 * OLEMenu_UnInstallHooks
1467 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1469 * RETURNS: TRUE if message hooks were successfully installed
1472 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1474 OleMenuHookItem
*pHookItem
= NULL
;
1475 OleMenuHookItem
**ppHook
= &hook_list
;
1479 if ((*ppHook
)->tid
== tid
)
1481 pHookItem
= *ppHook
;
1482 *ppHook
= pHookItem
->next
;
1485 ppHook
= &(*ppHook
)->next
;
1487 if (!pHookItem
) return FALSE
;
1489 /* Uninstall the hooks installed for this thread */
1490 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1492 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1495 /* Release the hook table entry */
1496 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1501 /* Release the hook table entry */
1502 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1507 /*************************************************************************
1508 * OLEMenu_IsHookInstalled
1509 * Tests if OLEMenu hooks have been installed for a thread
1511 * RETURNS: The pointer and index of the hook table entry for the tid
1512 * NULL and -1 for the index if no hooks were installed for this thread
1514 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1516 OleMenuHookItem
*pHookItem
;
1518 /* Do a simple linear search for an entry whose tid matches ours.
1519 * We really need a map but efficiency is not a concern here. */
1520 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1522 if ( tid
== pHookItem
->tid
)
1529 /***********************************************************************
1530 * OLEMenu_FindMainMenuIndex
1532 * Used by OLEMenu API to find the top level group a menu item belongs to.
1533 * On success pnPos contains the index of the item in the top level menu group
1535 * RETURNS: TRUE if the ID was found, FALSE on failure
1537 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1541 nItems
= GetMenuItemCount( hMainMenu
);
1543 for (i
= 0; i
< nItems
; i
++)
1547 /* Is the current item a submenu? */
1548 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1550 /* If the handle is the same we're done */
1551 if ( hsubmenu
== hPopupMenu
)
1557 /* Recursively search without updating pnPos */
1558 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1570 /***********************************************************************
1571 * OLEMenu_SetIsServerMenu
1573 * Checks whether a popup menu belongs to a shared menu group which is
1574 * owned by the server, and sets the menu descriptor state accordingly.
1575 * All menu messages from these groups should be routed to the server.
1577 * RETURNS: TRUE if the popup menu is part of a server owned group
1578 * FALSE if the popup menu is part of a container owned group
1580 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1582 UINT nPos
= 0, nWidth
, i
;
1584 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1586 /* Don't bother searching if the popup is the combined menu itself */
1587 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1590 /* Find the menu item index in the shared OLE menu that this item belongs to */
1591 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1594 /* The group widths array has counts for the number of elements
1595 * in the groups File, Edit, Container, Object, Window, Help.
1596 * The Edit, Object & Help groups belong to the server object
1597 * and the other three belong to the container.
1598 * Loop through the group widths and locate the group we are a member of.
1600 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1602 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1603 if ( nPos
< nWidth
)
1605 /* Odd elements are server menu widths */
1606 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1611 return pOleMenuDescriptor
->bIsServerItem
;
1614 /*************************************************************************
1615 * OLEMenu_CallWndProc
1616 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1617 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1619 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1622 HOLEMENU hOleMenu
= 0;
1623 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1624 OleMenuHookItem
*pHookItem
= NULL
;
1627 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1629 /* Check if we're being asked to process the message */
1630 if ( HC_ACTION
!= code
)
1633 /* Retrieve the current message being dispatched from lParam */
1634 pMsg
= (LPCWPSTRUCT
)lParam
;
1636 /* Check if the message is destined for a window we are interested in:
1637 * If the window has an OLEMenu property we may need to dispatch
1638 * the menu message to its active objects window instead. */
1640 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1644 /* Get the menu descriptor */
1645 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1646 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1649 /* Process menu messages */
1650 switch( pMsg
->message
)
1654 /* Reset the menu descriptor state */
1655 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1657 /* Send this message to the server as well */
1658 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1659 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1663 case WM_INITMENUPOPUP
:
1665 /* Save the state for whether this is a server owned menu */
1666 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1672 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1673 if ( fuFlags
& MF_SYSMENU
)
1676 /* Save the state for whether this is a server owned popup menu */
1677 else if ( fuFlags
& MF_POPUP
)
1678 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1685 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1686 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1687 goto NEXTHOOK
; /* Not a menu message */
1696 /* If the message was for the server dispatch it accordingly */
1697 if ( pOleMenuDescriptor
->bIsServerItem
)
1699 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1700 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1704 if ( pOleMenuDescriptor
)
1705 GlobalUnlock( hOleMenu
);
1707 /* Lookup the hook item for the current thread */
1708 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1710 /* This should never fail!! */
1711 WARN("could not retrieve hHook for current thread!\n" );
1715 /* Pass on the message to the next hooker */
1716 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1719 /*************************************************************************
1720 * OLEMenu_GetMsgProc
1721 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1722 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1724 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1727 HOLEMENU hOleMenu
= 0;
1728 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1729 OleMenuHookItem
*pHookItem
= NULL
;
1732 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1734 /* Check if we're being asked to process a messages */
1735 if ( HC_ACTION
!= code
)
1738 /* Retrieve the current message being dispatched from lParam */
1739 pMsg
= (LPMSG
)lParam
;
1741 /* Check if the message is destined for a window we are interested in:
1742 * If the window has an OLEMenu property we may need to dispatch
1743 * the menu message to its active objects window instead. */
1745 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1749 /* Process menu messages */
1750 switch( pMsg
->message
)
1754 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1756 goto NEXTHOOK
; /* Not a menu message */
1763 /* Get the menu descriptor */
1764 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1765 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1768 /* If the message was for the server dispatch it accordingly */
1769 if ( pOleMenuDescriptor
->bIsServerItem
)
1771 /* Change the hWnd in the message to the active objects hWnd.
1772 * The message loop which reads this message will automatically
1773 * dispatch it to the embedded objects window. */
1774 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1778 if ( pOleMenuDescriptor
)
1779 GlobalUnlock( hOleMenu
);
1781 /* Lookup the hook item for the current thread */
1782 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1784 /* This should never fail!! */
1785 WARN("could not retrieve hHook for current thread!\n" );
1789 /* Pass on the message to the next hooker */
1790 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1793 /***********************************************************************
1794 * OleCreateMenuDescriptor [OLE32.@]
1795 * Creates an OLE menu descriptor for OLE to use when dispatching
1796 * menu messages and commands.
1799 * hmenuCombined - Handle to the objects combined menu
1800 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1803 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1804 HMENU hmenuCombined
,
1805 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1808 OleMenuDescriptor
*pOleMenuDescriptor
;
1811 if ( !hmenuCombined
|| !lpMenuWidths
)
1814 /* Create an OLE menu descriptor */
1815 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1816 sizeof(OleMenuDescriptor
) ) ) )
1819 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1820 if ( !pOleMenuDescriptor
)
1823 /* Initialize menu group widths and hmenu */
1824 for ( i
= 0; i
< 6; i
++ )
1825 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1827 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1828 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1829 GlobalUnlock( hOleMenu
);
1834 /***********************************************************************
1835 * OleDestroyMenuDescriptor [OLE32.@]
1836 * Destroy the shared menu descriptor
1838 HRESULT WINAPI
OleDestroyMenuDescriptor(
1839 HOLEMENU hmenuDescriptor
)
1841 if ( hmenuDescriptor
)
1842 GlobalFree( hmenuDescriptor
);
1846 /***********************************************************************
1847 * OleSetMenuDescriptor [OLE32.@]
1848 * Installs or removes OLE dispatching code for the containers frame window.
1851 * hOleMenu Handle to composite menu descriptor
1852 * hwndFrame Handle to containers frame window
1853 * hwndActiveObject Handle to objects in-place activation window
1854 * lpFrame Pointer to IOleInPlaceFrame on containers window
1855 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1858 * S_OK - menu installed correctly
1859 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1862 * The lpFrame and lpActiveObject parameters are currently ignored
1863 * OLE should install context sensitive help F1 filtering for the app when
1864 * these are non null.
1866 HRESULT WINAPI
OleSetMenuDescriptor(
1869 HWND hwndActiveObject
,
1870 LPOLEINPLACEFRAME lpFrame
,
1871 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1873 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1876 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1877 return E_INVALIDARG
;
1879 if ( lpFrame
|| lpActiveObject
)
1881 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1889 /* Set up a message hook to intercept the containers frame window messages.
1890 * The message filter is responsible for dispatching menu messages from the
1891 * shared menu which are intended for the object.
1894 if ( hOleMenu
) /* Want to install dispatching code */
1896 /* If OLEMenu hooks are already installed for this thread, fail
1897 * Note: This effectively means that OleSetMenuDescriptor cannot
1898 * be called twice in succession on the same frame window
1899 * without first calling it with a null hOleMenu to uninstall
1901 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1904 /* Get the menu descriptor */
1905 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1906 if ( !pOleMenuDescriptor
)
1907 return E_UNEXPECTED
;
1909 /* Update the menu descriptor */
1910 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1911 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1913 GlobalUnlock( hOleMenu
);
1914 pOleMenuDescriptor
= NULL
;
1916 /* Add a menu descriptor windows property to the frame window */
1917 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1919 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1920 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1923 else /* Want to uninstall dispatching code */
1925 /* Uninstall the hooks */
1926 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1929 /* Remove the menu descriptor property from the frame window */
1930 RemovePropW( hwndFrame
, prop_olemenuW
);
1936 /******************************************************************************
1937 * IsAccelerator [OLE32.@]
1938 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1940 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1945 if(!lpMsg
) return FALSE
;
1948 WARN_(accel
)("NULL accel handle\n");
1951 if((lpMsg
->message
!= WM_KEYDOWN
&&
1952 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1953 lpMsg
->message
!= WM_SYSCHAR
&&
1954 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1955 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1956 if (NULL
== lpAccelTbl
)
1960 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1962 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1963 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1967 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1968 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1969 hAccel
, cAccelEntries
,
1970 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1971 for(i
= 0; i
< cAccelEntries
; i
++)
1973 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1976 if(lpMsg
->message
== WM_CHAR
)
1978 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1980 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1986 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1989 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1990 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1991 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1992 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1993 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1994 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1995 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1999 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2001 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2002 { /* ^^ ALT pressed */
2003 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2011 WARN_(accel
)("couldn't translate accelerator key\n");
2012 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2016 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2017 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2021 /***********************************************************************
2022 * ReleaseStgMedium [OLE32.@]
2024 void WINAPI
ReleaseStgMedium(
2027 switch (pmedium
->tymed
)
2031 if ( (pmedium
->pUnkForRelease
==0) &&
2032 (pmedium
->u
.hGlobal
!=0) )
2033 GlobalFree(pmedium
->u
.hGlobal
);
2038 if (pmedium
->u
.lpszFileName
!=0)
2040 if (pmedium
->pUnkForRelease
==0)
2042 DeleteFileW(pmedium
->u
.lpszFileName
);
2045 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2051 if (pmedium
->u
.pstm
!=0)
2053 IStream_Release(pmedium
->u
.pstm
);
2057 case TYMED_ISTORAGE
:
2059 if (pmedium
->u
.pstg
!=0)
2061 IStorage_Release(pmedium
->u
.pstg
);
2067 if ( (pmedium
->pUnkForRelease
==0) &&
2068 (pmedium
->u
.hBitmap
!=0) )
2069 DeleteObject(pmedium
->u
.hBitmap
);
2074 if ( (pmedium
->pUnkForRelease
==0) &&
2075 (pmedium
->u
.hMetaFilePict
!=0) )
2077 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2078 DeleteMetaFile(pMP
->hMF
);
2079 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2080 GlobalFree(pmedium
->u
.hMetaFilePict
);
2086 if ( (pmedium
->pUnkForRelease
==0) &&
2087 (pmedium
->u
.hEnhMetaFile
!=0) )
2089 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2097 pmedium
->tymed
=TYMED_NULL
;
2100 * After cleaning up, the unknown is released
2102 if (pmedium
->pUnkForRelease
!=0)
2104 IUnknown_Release(pmedium
->pUnkForRelease
);
2105 pmedium
->pUnkForRelease
= 0;
2110 * OLEDD_Initialize()
2112 * Initializes the OLE drag and drop data structures.
2114 static void OLEDD_Initialize(void)
2118 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2119 wndClass
.style
= CS_GLOBALCLASS
;
2120 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2121 wndClass
.cbClsExtra
= 0;
2122 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2123 wndClass
.hCursor
= 0;
2124 wndClass
.hbrBackground
= 0;
2125 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2127 RegisterClassW (&wndClass
);
2131 * OLEDD_DragTrackerWindowProc()
2133 * This method is the WindowProcedure of the drag n drop tracking
2134 * window. During a drag n Drop operation, an invisible window is created
2135 * to receive the user input and act upon it. This procedure is in charge
2139 #define DRAG_TIMER_ID 1
2141 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2151 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2153 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2154 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2163 case WM_LBUTTONDOWN
:
2164 case WM_MBUTTONDOWN
:
2165 case WM_RBUTTONDOWN
:
2167 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2168 if (trackerInfo
->trackingDone
) break;
2169 OLEDD_TrackStateChange(trackerInfo
);
2174 KillTimer(hwnd
, DRAG_TIMER_ID
);
2180 * This is a window proc after all. Let's call the default.
2182 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2185 static void drag_enter( TrackerWindowInfo
*info
, HWND new_target
)
2189 info
->curTargetHWND
= new_target
;
2191 while (new_target
&& !is_droptarget( new_target
))
2192 new_target
= GetParent( new_target
);
2194 info
->curDragTarget
= get_droptarget_pointer( new_target
);
2196 if (info
->curDragTarget
)
2198 *info
->pdwEffect
= info
->dwOKEffect
;
2199 hr
= IDropTarget_DragEnter( info
->curDragTarget
, info
->dataObject
,
2200 info
->dwKeyState
, info
->curMousePos
,
2202 *info
->pdwEffect
&= info
->dwOKEffect
;
2204 /* failed DragEnter() means invalid target */
2207 IDropTarget_Release( info
->curDragTarget
);
2208 info
->curDragTarget
= NULL
;
2209 info
->curTargetHWND
= NULL
;
2214 static void drag_end( TrackerWindowInfo
*info
)
2218 info
->trackingDone
= TRUE
;
2221 if (info
->curDragTarget
)
2223 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2224 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2226 *info
->pdwEffect
= info
->dwOKEffect
;
2227 hr
= IDropTarget_Drop( info
->curDragTarget
, info
->dataObject
, info
->dwKeyState
,
2228 info
->curMousePos
, info
->pdwEffect
);
2229 *info
->pdwEffect
&= info
->dwOKEffect
;
2232 info
->returnValue
= hr
;
2236 IDropTarget_DragLeave( info
->curDragTarget
);
2237 *info
->pdwEffect
= DROPEFFECT_NONE
;
2239 IDropTarget_Release( info
->curDragTarget
);
2240 info
->curDragTarget
= NULL
;
2243 *info
->pdwEffect
= DROPEFFECT_NONE
;
2246 static HRESULT
give_feedback( TrackerWindowInfo
*info
)
2252 if (info
->curDragTarget
== NULL
)
2253 *info
->pdwEffect
= DROPEFFECT_NONE
;
2255 hr
= IDropSource_GiveFeedback( info
->dropSource
, *info
->pdwEffect
);
2257 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2259 if (*info
->pdwEffect
& DROPEFFECT_MOVE
)
2261 else if (*info
->pdwEffect
& DROPEFFECT_COPY
)
2263 else if (*info
->pdwEffect
& DROPEFFECT_LINK
)
2266 res
= CURSOR_NODROP
;
2268 cur
= LoadCursorW( hProxyDll
, MAKEINTRESOURCEW( res
) );
2276 * OLEDD_TrackStateChange()
2278 * This method is invoked while a drag and drop operation is in effect.
2281 * trackerInfo - Pointer to the structure identifying the
2282 * drag & drop operation that is currently
2285 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2287 HWND hwndNewTarget
= 0;
2291 * Get the handle of the window under the mouse
2293 pt
.x
= trackerInfo
->curMousePos
.x
;
2294 pt
.y
= trackerInfo
->curMousePos
.y
;
2295 hwndNewTarget
= WindowFromPoint(pt
);
2297 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2298 trackerInfo
->escPressed
,
2299 trackerInfo
->dwKeyState
);
2301 if (trackerInfo
->curTargetHWND
!= hwndNewTarget
&&
2302 (trackerInfo
->returnValue
== S_OK
||
2303 trackerInfo
->returnValue
== DRAGDROP_S_DROP
))
2305 if (trackerInfo
->curDragTarget
)
2307 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2308 IDropTarget_Release(trackerInfo
->curDragTarget
);
2309 trackerInfo
->curDragTarget
= NULL
;
2310 trackerInfo
->curTargetHWND
= NULL
;
2314 drag_enter( trackerInfo
, hwndNewTarget
);
2316 give_feedback( trackerInfo
);
2320 if (trackerInfo
->returnValue
== S_OK
)
2322 if (trackerInfo
->curDragTarget
)
2324 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2325 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2326 trackerInfo
->dwKeyState
,
2327 trackerInfo
->curMousePos
,
2328 trackerInfo
->pdwEffect
);
2329 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2331 give_feedback( trackerInfo
);
2334 drag_end( trackerInfo
);
2338 * OLEDD_GetButtonState()
2340 * This method will use the current state of the keyboard to build
2341 * a button state mask equivalent to the one passed in the
2342 * WM_MOUSEMOVE wParam.
2344 static DWORD
OLEDD_GetButtonState(void)
2346 BYTE keyboardState
[256];
2349 GetKeyboardState(keyboardState
);
2351 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2352 keyMask
|= MK_SHIFT
;
2354 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2355 keyMask
|= MK_CONTROL
;
2357 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2360 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2361 keyMask
|= MK_LBUTTON
;
2363 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2364 keyMask
|= MK_RBUTTON
;
2366 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2367 keyMask
|= MK_MBUTTON
;
2373 * OLEDD_GetButtonState()
2375 * This method will read the default value of the registry key in
2376 * parameter and extract a DWORD value from it. The registry key value
2377 * can be in a string key or a DWORD key.
2380 * regKey - Key to read the default value from
2381 * pdwValue - Pointer to the location where the DWORD
2382 * value is returned. This value is not modified
2383 * if the value is not found.
2386 static void OLEUTL_ReadRegistryDWORDValue(
2391 DWORD cbData
= sizeof(buffer
);
2395 lres
= RegQueryValueExW(regKey
,
2402 if (lres
==ERROR_SUCCESS
)
2407 *pdwValue
= *(DWORD
*)buffer
;
2412 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2418 /******************************************************************************
2421 * The operation of this function is documented literally in the WinAPI
2422 * documentation to involve a QueryInterface for the IViewObject interface,
2423 * followed by a call to IViewObject::Draw.
2425 HRESULT WINAPI
OleDraw(
2432 IViewObject
*viewobject
;
2434 if (!pUnk
) return E_INVALIDARG
;
2436 hres
= IUnknown_QueryInterface(pUnk
,
2438 (void**)&viewobject
);
2439 if (SUCCEEDED(hres
))
2441 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2442 IViewObject_Release(viewobject
);
2446 return DV_E_NOIVIEWOBJECT
;
2449 /***********************************************************************
2450 * OleTranslateAccelerator [OLE32.@]
2452 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2453 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2457 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2459 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2460 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2465 /******************************************************************************
2466 * OleCreate [OLE32.@]
2469 HRESULT WINAPI
OleCreate(
2473 LPFORMATETC pFormatEtc
,
2474 LPOLECLIENTSITE pClientSite
,
2479 IUnknown
* pUnk
= NULL
;
2480 IOleObject
*pOleObject
= NULL
;
2482 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2483 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2485 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2487 if (SUCCEEDED(hres
))
2488 hres
= IStorage_SetClass(pStg
, rclsid
);
2490 if (pClientSite
&& SUCCEEDED(hres
))
2492 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2493 if (SUCCEEDED(hres
))
2496 IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2500 if (SUCCEEDED(hres
))
2502 IPersistStorage
* pPS
;
2503 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2505 TRACE("trying to set stg %p\n", pStg
);
2506 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2507 TRACE("-- result 0x%08x\n", hres
);
2508 IPersistStorage_Release(pPS
);
2512 if (pClientSite
&& SUCCEEDED(hres
))
2514 TRACE("trying to set clientsite %p\n", pClientSite
);
2515 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2516 TRACE("-- result 0x%08x\n", hres
);
2520 IOleObject_Release(pOleObject
);
2522 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2525 hres
= OleRun(pUnk
);
2526 if (SUCCEEDED(hres
))
2528 IOleCache
*pOleCache
;
2530 if (SUCCEEDED(IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
)))
2533 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2537 pfe
.dwAspect
= DVASPECT_CONTENT
;
2539 pfe
.tymed
= TYMED_NULL
;
2540 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2543 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2544 IOleCache_Release(pOleCache
);
2549 if (FAILED(hres
) && pUnk
)
2551 IUnknown_Release(pUnk
);
2557 TRACE("-- %p\n", pUnk
);
2561 /******************************************************************************
2562 * OleGetAutoConvert [OLE32.@]
2564 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2566 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2568 WCHAR buf
[CHARS_IN_GUID
];
2572 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2577 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2579 res
= REGDB_E_KEYMISSING
;
2582 res
= CLSIDFromString(buf
, pClsidNew
);
2584 if (hkey
) RegCloseKey(hkey
);
2588 /******************************************************************************
2589 * OleSetAutoConvert [OLE32.@]
2591 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2593 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2595 WCHAR szClsidNew
[CHARS_IN_GUID
];
2598 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2600 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2603 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2604 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2606 res
= REGDB_E_WRITEREGDB
;
2611 if (hkey
) RegCloseKey(hkey
);
2615 /******************************************************************************
2616 * OleDoAutoConvert [OLE32.@]
2618 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2620 WCHAR
*user_type_old
, *user_type_new
;
2626 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2628 *pClsidNew
= CLSID_NULL
;
2630 return E_INVALIDARG
;
2631 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2635 *pClsidNew
= stat
.clsid
;
2636 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2640 hr
= IStorage_SetClass(pStg
, &clsid
);
2644 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2647 user_type_new
= NULL
;
2650 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2652 user_type_new
= NULL
;
2654 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2655 CoTaskMemFree(user_type_new
);
2658 CoTaskMemFree(user_type_old
);
2659 IStorage_SetClass(pStg
, &stat
.clsid
);
2663 hr
= SetConvertStg(pStg
, TRUE
);
2666 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2667 IStorage_SetClass(pStg
, &stat
.clsid
);
2671 CoTaskMemFree(user_type_old
);
2675 /******************************************************************************
2676 * OleIsRunning [OLE32.@]
2678 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2680 IRunnableObject
*pRunnable
;
2684 TRACE("(%p)\n", object
);
2686 if (!object
) return FALSE
;
2688 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2691 running
= IRunnableObject_IsRunning(pRunnable
);
2692 IRunnableObject_Release(pRunnable
);
2696 /***********************************************************************
2697 * OleNoteObjectVisible [OLE32.@]
2699 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2701 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2702 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2706 /***********************************************************************
2707 * OLE_FreeClipDataArray [internal]
2710 * frees the data associated with an array of CLIPDATAs
2712 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2715 for (i
= 0; i
< count
; i
++)
2716 if (pClipDataArray
[i
].pClipData
)
2717 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2720 /***********************************************************************
2721 * PropSysAllocString [OLE32.@]
2723 * Forward to oleaut32.
2725 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2727 return SysAllocString(str
);
2730 /***********************************************************************
2731 * PropSysFreeString [OLE32.@]
2733 * Forward to oleaut32.
2735 void WINAPI
PropSysFreeString(LPOLESTR str
)
2740 /******************************************************************************
2741 * Check if a PROPVARIANT's type is valid.
2743 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2775 case VT_STREAMED_OBJECT
:
2776 case VT_STORED_OBJECT
:
2777 case VT_BLOB_OBJECT
:
2780 case VT_I1
|VT_VECTOR
:
2781 case VT_I2
|VT_VECTOR
:
2782 case VT_I4
|VT_VECTOR
:
2783 case VT_I8
|VT_VECTOR
:
2784 case VT_R4
|VT_VECTOR
:
2785 case VT_R8
|VT_VECTOR
:
2786 case VT_CY
|VT_VECTOR
:
2787 case VT_DATE
|VT_VECTOR
:
2788 case VT_BSTR
|VT_VECTOR
:
2789 case VT_ERROR
|VT_VECTOR
:
2790 case VT_BOOL
|VT_VECTOR
:
2791 case VT_VARIANT
|VT_VECTOR
:
2792 case VT_UI1
|VT_VECTOR
:
2793 case VT_UI2
|VT_VECTOR
:
2794 case VT_UI4
|VT_VECTOR
:
2795 case VT_UI8
|VT_VECTOR
:
2796 case VT_LPSTR
|VT_VECTOR
:
2797 case VT_LPWSTR
|VT_VECTOR
:
2798 case VT_FILETIME
|VT_VECTOR
:
2799 case VT_CF
|VT_VECTOR
:
2800 case VT_CLSID
|VT_VECTOR
:
2803 WARN("Bad type %d\n", vt
);
2804 return STG_E_INVALIDPARAMETER
;
2807 /***********************************************************************
2808 * PropVariantClear [OLE32.@]
2810 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2814 TRACE("(%p)\n", pvar
);
2819 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2822 memset(pvar
, 0, sizeof(*pvar
));
2852 case VT_STREAMED_OBJECT
:
2854 case VT_STORED_OBJECT
:
2855 if (pvar
->u
.pStream
)
2856 IStream_Release(pvar
->u
.pStream
);
2861 /* pick an arbitrary typed pointer - we don't care about the type
2862 * as we are just freeing it */
2863 CoTaskMemFree(pvar
->u
.puuid
);
2866 case VT_BLOB_OBJECT
:
2867 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2870 PropSysFreeString(pvar
->u
.bstrVal
);
2873 if (pvar
->u
.pclipdata
)
2875 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2876 CoTaskMemFree(pvar
->u
.pclipdata
);
2880 if (pvar
->vt
& VT_VECTOR
)
2884 switch (pvar
->vt
& ~VT_VECTOR
)
2887 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2890 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2893 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2894 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2897 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2898 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2901 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2902 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2905 if (pvar
->vt
& ~VT_VECTOR
)
2907 /* pick an arbitrary VT_VECTOR structure - they all have the same
2909 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2914 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2915 hr
= STG_E_INVALIDPARAMETER
;
2919 memset(pvar
, 0, sizeof(*pvar
));
2923 /***********************************************************************
2924 * PropVariantCopy [OLE32.@]
2926 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2927 const PROPVARIANT
*pvarSrc
) /* [in] */
2932 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
2934 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2936 return DISP_E_BADVARTYPE
;
2938 /* this will deal with most cases */
2939 *pvarDest
= *pvarSrc
;
2967 case VT_STREAMED_OBJECT
:
2969 case VT_STORED_OBJECT
:
2970 if (pvarDest
->u
.pStream
)
2971 IStream_AddRef(pvarDest
->u
.pStream
);
2974 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2975 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
2978 if (pvarSrc
->u
.pszVal
)
2980 len
= strlen(pvarSrc
->u
.pszVal
);
2981 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2982 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2986 if (pvarSrc
->u
.pwszVal
)
2988 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2989 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2990 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2994 case VT_BLOB_OBJECT
:
2995 if (pvarSrc
->u
.blob
.pBlobData
)
2997 len
= pvarSrc
->u
.blob
.cbSize
;
2998 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2999 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
3003 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
3006 if (pvarSrc
->u
.pclipdata
)
3008 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
3009 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
3010 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
3011 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
3012 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
3013 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
3017 if (pvarSrc
->vt
& VT_VECTOR
)
3022 switch(pvarSrc
->vt
& ~VT_VECTOR
)
3024 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3025 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3026 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3027 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3028 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3029 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3030 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3031 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3032 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3033 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3034 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3035 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3036 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3037 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3038 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3039 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3040 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3041 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3042 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3043 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3044 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3047 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3048 return E_INVALIDARG
;
3050 len
= pvarSrc
->u
.capropvar
.cElems
;
3051 pvarDest
->u
.capropvar
.pElems
= len
? CoTaskMemAlloc(len
* elemSize
) : NULL
;
3052 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3054 for (i
= 0; i
< len
; i
++)
3055 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3057 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3059 FIXME("Copy clipformats\n");
3061 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3063 for (i
= 0; i
< len
; i
++)
3064 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3066 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3069 for (i
= 0; i
< len
; i
++)
3071 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3072 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3073 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3074 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3077 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3080 for (i
= 0; i
< len
; i
++)
3082 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3084 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3085 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3086 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3090 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3093 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3099 /***********************************************************************
3100 * FreePropVariantArray [OLE32.@]
3102 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3103 PROPVARIANT
*rgvars
) /* [in/out] */
3107 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3110 return E_INVALIDARG
;
3112 for(i
= 0; i
< cVariants
; i
++)
3113 PropVariantClear(&rgvars
[i
]);
3118 /******************************************************************************
3119 * DllDebugObjectRPCHook (OLE32.@)
3120 * turns on and off internal debugging, pointer is only used on macintosh
3123 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)