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
30 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
31 WINE_DECLARE_DEBUG_CHANNEL(accel
);
33 /******************************************************************************
34 * These are static/global variables and internal data structures that the
35 * OLE module uses to maintain its state.
37 typedef struct tagTrackerWindowInfo
39 IDataObject
* dataObject
;
40 IDropSource
* dropSource
;
47 HWND curTargetHWND
; /* window the mouse is hovering over */
48 IDropTarget
* curDragTarget
;
49 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
50 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
53 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
55 HWND hwndFrame
; /* The containers frame window */
56 HWND hwndActiveObject
; /* The active objects window */
57 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
58 HMENU hmenuCombined
; /* The combined menu */
59 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
62 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
64 DWORD tid
; /* Thread Id */
65 HANDLE hHeap
; /* Heap this is allocated from */
66 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
67 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
68 struct tagOleMenuHookItem
*next
;
71 static OleMenuHookItem
*hook_list
;
74 * This is the lock count on the OLE library. It is controlled by the
75 * OLEInitialize/OLEUninitialize methods.
77 static LONG OLE_moduleLockCount
= 0;
80 * Name of our registered window class.
82 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
83 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
86 * Name of menu descriptor property.
88 static const WCHAR prop_olemenuW
[] =
89 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
91 /* property to store IDropTarget pointer */
92 static const WCHAR prop_oledroptarget
[] =
93 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
95 /* property to store Marshalled IDropTarget pointer */
96 static const WCHAR prop_marshalleddroptarget
[] =
97 {'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};
99 static const WCHAR emptyW
[] = { 0 };
101 /******************************************************************************
102 * These are the prototypes of miscellaneous utility methods
104 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
106 /******************************************************************************
107 * These are the prototypes of the utility methods used to manage a shared menu
109 static void OLEMenu_Initialize(void);
110 static void OLEMenu_UnInitialize(void);
111 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
112 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
113 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
114 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
115 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
116 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
117 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
119 /******************************************************************************
120 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
122 extern void OLEClipbrd_UnInitialize(void);
123 extern void OLEClipbrd_Initialize(void);
125 /******************************************************************************
126 * These are the prototypes of the utility methods used for OLE Drag n Drop
128 static void OLEDD_Initialize(void);
129 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
130 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
131 static DWORD
OLEDD_GetButtonState(void);
133 /******************************************************************************
134 * OleBuildVersion [OLE32.@]
136 DWORD WINAPI
OleBuildVersion(void)
138 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
139 return (rmm
<<16)+rup
;
142 /***********************************************************************
143 * OleInitialize (OLE32.@)
145 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
149 TRACE("(%p)\n", reserved
);
152 * The first duty of the OleInitialize is to initialize the COM libraries.
154 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
157 * If the CoInitializeEx call failed, the OLE libraries can't be
163 if (!COM_CurrentInfo()->ole_inits
)
169 * Then, it has to initialize the OLE specific modules.
173 * Object linking and Embedding
174 * In-place activation
176 if (!COM_CurrentInfo()->ole_inits
++ &&
177 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
180 * Initialize the libraries.
182 TRACE("() - Initializing the OLE libraries\n");
187 OLEClipbrd_Initialize();
197 OLEMenu_Initialize();
203 /******************************************************************************
204 * OleUninitialize [OLE32.@]
206 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
210 if (COM_CurrentInfo()->ole_inits
== 0)
212 WARN("ole_inits is already 0\n");
216 * If we hit the bottom of the lock stack, free the libraries.
218 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
221 * Actually free the libraries.
223 TRACE("() - Freeing the last reference count\n");
228 OLEClipbrd_UnInitialize();
233 OLEMenu_UnInitialize();
237 * Then, uninitialize the COM libraries.
242 /******************************************************************************
243 * OleInitializeWOW [OLE32.@]
245 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
246 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
250 /*************************************************************
251 * get_droptarget_handle
253 * Retrieve a handle to the map containing the marshalled IDropTarget.
254 * This handle belongs to the process that called RegisterDragDrop.
255 * See get_droptarget_local_handle().
257 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
259 return GetPropW(hwnd
, prop_marshalleddroptarget
);
262 /*************************************************************
265 * Is the window a droptarget.
267 static inline BOOL
is_droptarget(HWND hwnd
)
269 return get_droptarget_handle(hwnd
) != 0;
272 /*************************************************************
273 * get_droptarget_local_handle
275 * Retrieve a handle to the map containing the marshalled IDropTarget.
276 * The handle should be closed when finished with.
278 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
280 HANDLE handle
, local_handle
= 0;
282 handle
= get_droptarget_handle(hwnd
);
289 GetWindowThreadProcessId(hwnd
, &pid
);
290 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
293 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
294 CloseHandle(process
);
300 /***********************************************************************
301 * create_map_from_stream
303 * Helper for RegisterDragDrop. Creates a file mapping object
304 * with the contents of the provided stream. The stream must
305 * be a global memory backed stream.
307 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
314 hr
= GetHGlobalFromStream(stream
, &hmem
);
315 if(FAILED(hr
)) return hr
;
317 size
= GlobalSize(hmem
);
318 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
319 if(!*map
) return E_OUTOFMEMORY
;
321 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
322 memcpy(data
, GlobalLock(hmem
), size
);
324 UnmapViewOfFile(data
);
328 /***********************************************************************
329 * create_stream_from_map
331 * Creates a stream from the provided map.
333 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
335 HRESULT hr
= E_OUTOFMEMORY
;
338 MEMORY_BASIC_INFORMATION info
;
340 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
343 VirtualQuery(data
, &info
, sizeof(info
));
344 TRACE("size %d\n", (int)info
.RegionSize
);
346 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
349 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
351 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
353 UnmapViewOfFile(data
);
357 /* This is to work around apps which break COM rules by not implementing
358 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
359 * doesn't call CoMarshallInterface() in RegisterDragDrop().
360 * The wrapper is only used internally, and only exists for the life of
361 * the marshal. We don't want to hold a ref on the app provided target
362 * as some apps destroy this prior to CoUninitialize without calling
363 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
365 IDropTarget IDropTarget_iface
;
370 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
372 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
375 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
379 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
380 if (IsEqualIID(riid
, &IID_IUnknown
) ||
381 IsEqualIID(riid
, &IID_IDropTarget
))
383 IDropTarget_AddRef(&This
->IDropTarget_iface
);
384 *ppvObject
= &This
->IDropTarget_iface
;
388 return E_NOINTERFACE
;
391 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
393 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
394 return InterlockedIncrement(&This
->refs
);
397 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
399 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
400 ULONG refs
= InterlockedDecrement(&This
->refs
);
401 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
405 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
407 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
408 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
409 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
410 IDropTarget_AddRef( *target
);
414 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
415 IDataObject
* pDataObj
,
421 HRESULT r
= get_target_from_wrapper( iface
, &target
);
425 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
426 IDropTarget_Release( target
);
431 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
437 HRESULT r
= get_target_from_wrapper( iface
, &target
);
441 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
442 IDropTarget_Release( target
);
447 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
450 HRESULT r
= get_target_from_wrapper( iface
, &target
);
454 r
= IDropTarget_DragLeave( target
);
455 IDropTarget_Release( target
);
460 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
461 IDataObject
* pDataObj
,
467 HRESULT r
= get_target_from_wrapper( iface
, &target
);
471 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
472 IDropTarget_Release( target
);
477 static const IDropTargetVtbl DropTargetWrapperVTbl
=
479 DropTargetWrapper_QueryInterface
,
480 DropTargetWrapper_AddRef
,
481 DropTargetWrapper_Release
,
482 DropTargetWrapper_DragEnter
,
483 DropTargetWrapper_DragOver
,
484 DropTargetWrapper_DragLeave
,
485 DropTargetWrapper_Drop
488 static IDropTarget
* WrapDropTarget( HWND hwnd
)
490 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
494 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
498 return &This
->IDropTarget_iface
;
501 /***********************************************************************
502 * get_droptarget_pointer
504 * Retrieves the marshalled IDropTarget from the window.
506 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
508 IDropTarget
*droptarget
= NULL
;
512 map
= get_droptarget_local_handle(hwnd
);
513 if(!map
) return NULL
;
515 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
517 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
518 IStream_Release(stream
);
524 /***********************************************************************
525 * RegisterDragDrop (OLE32.@)
527 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
533 IDropTarget
*wrapper
;
535 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
537 if (!COM_CurrentApt())
539 ERR("COM not initialized\n");
540 return E_OUTOFMEMORY
;
548 ERR("invalid hwnd %p\n", hwnd
);
549 return DRAGDROP_E_INVALIDHWND
;
552 /* block register for other processes windows */
553 GetWindowThreadProcessId(hwnd
, &pid
);
554 if (pid
!= GetCurrentProcessId())
556 FIXME("register for another process windows is disabled\n");
557 return DRAGDROP_E_INVALIDHWND
;
560 /* check if the window is already registered */
561 if (is_droptarget(hwnd
))
562 return DRAGDROP_E_ALREADYREGISTERED
;
565 * Marshal the drop target pointer into a shared memory map and
566 * store the map's handle in a Wine specific window prop. We also
567 * store the drop target pointer itself in the
568 * "OleDropTargetInterface" prop for compatibility with Windows.
571 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
572 if(FAILED(hr
)) return hr
;
574 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
575 wrapper
= WrapDropTarget( hwnd
);
578 IStream_Release(stream
);
579 return E_OUTOFMEMORY
;
581 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
582 IDropTarget_Release(wrapper
);
586 hr
= create_map_from_stream(stream
, &map
);
589 IDropTarget_AddRef(pDropTarget
);
590 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
591 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
597 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
598 CoReleaseMarshalData(stream
);
601 IStream_Release(stream
);
606 /***********************************************************************
607 * RevokeDragDrop (OLE32.@)
609 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
613 IDropTarget
*drop_target
;
616 TRACE("(%p)\n", hwnd
);
620 ERR("invalid hwnd %p\n", hwnd
);
621 return DRAGDROP_E_INVALIDHWND
;
624 /* no registration data */
625 if (!(map
= get_droptarget_handle(hwnd
)))
626 return DRAGDROP_E_NOTREGISTERED
;
628 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
629 if(drop_target
) IDropTarget_Release(drop_target
);
631 RemovePropW(hwnd
, prop_oledroptarget
);
632 RemovePropW(hwnd
, prop_marshalleddroptarget
);
634 hr
= create_stream_from_map(map
, &stream
);
637 CoReleaseMarshalData(stream
);
638 IStream_Release(stream
);
645 /***********************************************************************
646 * OleRegGetUserType (OLE32.@)
648 HRESULT WINAPI
OleRegGetUserType(REFCLSID clsid
, DWORD form
, LPOLESTR
*usertype
)
650 static const WCHAR auxusertypeW
[] = {'A','u','x','U','s','e','r','T','y','p','e','\\','%','d',0};
651 DWORD valuetype
, valuelen
;
652 WCHAR auxkeynameW
[16];
657 TRACE("(%s, %u, %p)\n", debugstr_guid(clsid
), form
, usertype
);
664 /* Return immediately if it's not registered. */
665 hres
= COM_OpenKeyForCLSID(clsid
, NULL
, KEY_READ
, &usertypekey
);
671 /* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
672 if (form
!= USERCLASSTYPE_FULL
)
676 sprintfW(auxkeynameW
, auxusertypeW
, form
);
677 if (COM_OpenKeyForCLSID(clsid
, auxkeynameW
, KEY_READ
, &auxkey
) == S_OK
)
679 if (!RegQueryValueExW(auxkey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
) && valuelen
)
681 RegCloseKey(usertypekey
);
682 usertypekey
= auxkey
;
690 if (RegQueryValueExW(usertypekey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
))
692 RegCloseKey(usertypekey
);
693 return REGDB_E_READREGDB
;
696 *usertype
= CoTaskMemAlloc(valuelen
);
699 RegCloseKey(usertypekey
);
700 return E_OUTOFMEMORY
;
703 ret
= RegQueryValueExW(usertypekey
,
709 RegCloseKey(usertypekey
);
710 if (ret
!= ERROR_SUCCESS
)
712 CoTaskMemFree(*usertype
);
714 return REGDB_E_READREGDB
;
720 /***********************************************************************
721 * DoDragDrop [OLE32.@]
723 HRESULT WINAPI
DoDragDrop (
724 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
725 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
726 DWORD dwOKEffect
, /* [in] effects allowed by the source */
727 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
729 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
730 TrackerWindowInfo trackerInfo
;
731 HWND hwndTrackWindow
;
734 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
736 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
740 * Setup the drag n drop tracking window.
743 trackerInfo
.dataObject
= pDataObject
;
744 trackerInfo
.dropSource
= pDropSource
;
745 trackerInfo
.dwOKEffect
= dwOKEffect
;
746 trackerInfo
.pdwEffect
= pdwEffect
;
747 trackerInfo
.trackingDone
= FALSE
;
748 trackerInfo
.escPressed
= FALSE
;
749 trackerInfo
.curTargetHWND
= 0;
750 trackerInfo
.curDragTarget
= 0;
752 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
753 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
754 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
760 * Capture the mouse input
762 SetCapture(hwndTrackWindow
);
767 * Pump messages. All mouse input should go to the capture window.
769 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
771 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
772 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
773 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
775 if ( (msg
.message
>= WM_KEYFIRST
) &&
776 (msg
.message
<= WM_KEYLAST
) )
779 * When keyboard messages are sent to windows on this thread, we
780 * want to ignore notify the drop source that the state changed.
781 * in the case of the Escape key, we also notify the drop source
782 * we give it a special meaning.
784 if ( (msg
.message
==WM_KEYDOWN
) &&
785 (msg
.wParam
==VK_ESCAPE
) )
787 trackerInfo
.escPressed
= TRUE
;
791 * Notify the drop source.
793 OLEDD_TrackStateChange(&trackerInfo
);
798 * Dispatch the messages only when it's not a keyboard message.
800 DispatchMessageW(&msg
);
804 /* re-post the quit message to outer message loop */
805 if (msg
.message
== WM_QUIT
)
806 PostQuitMessage(msg
.wParam
);
808 * Destroy the temporary window.
810 DestroyWindow(hwndTrackWindow
);
812 return trackerInfo
.returnValue
;
818 /***********************************************************************
819 * OleQueryLinkFromData [OLE32.@]
821 HRESULT WINAPI
OleQueryLinkFromData(
822 IDataObject
* pSrcDataObject
)
824 FIXME("(%p),stub!\n", pSrcDataObject
);
828 /***********************************************************************
829 * OleRegGetMiscStatus [OLE32.@]
831 HRESULT WINAPI
OleRegGetMiscStatus(
836 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
837 static const WCHAR dfmtW
[] = {'%','d',0};
844 TRACE("(%s, %d, %p)\n", debugstr_guid(clsid
), dwAspect
, pdwStatus
);
846 if (!pdwStatus
) return E_INVALIDARG
;
850 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
852 hr
= COM_OpenKeyForCLSID(clsid
, miscstatusW
, KEY_READ
, &miscStatusKey
);
854 /* missing key is not a failure */
855 return hr
== REGDB_E_KEYMISSING
? S_OK
: hr
;
857 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
860 * Open the key specific to the requested aspect.
862 sprintfW(keyName
, dfmtW
, dwAspect
);
864 result
= open_classes_key(miscStatusKey
, keyName
, KEY_READ
, &aspectKey
);
865 if (result
== ERROR_SUCCESS
)
867 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
868 RegCloseKey(aspectKey
);
871 RegCloseKey(miscStatusKey
);
875 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
879 IEnumOLEVERB IEnumOLEVERB_iface
;
886 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
888 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
891 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
892 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
894 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
895 if (IsEqualIID(riid
, &IID_IUnknown
) ||
896 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
898 IEnumOLEVERB_AddRef(iface
);
902 return E_NOINTERFACE
;
905 static ULONG WINAPI
EnumOLEVERB_AddRef(
908 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
910 return InterlockedIncrement(&This
->ref
);
913 static ULONG WINAPI
EnumOLEVERB_Release(
916 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
917 LONG refs
= InterlockedDecrement(&This
->ref
);
921 RegCloseKey(This
->hkeyVerb
);
922 HeapFree(GetProcessHeap(), 0, This
);
927 static HRESULT WINAPI
EnumOLEVERB_Next(
928 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
931 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
934 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
939 for (; celt
; celt
--, rgelt
++)
944 LPWSTR pwszMenuFlags
;
946 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
947 if (res
== ERROR_NO_MORE_ITEMS
)
952 else if (res
!= ERROR_SUCCESS
)
954 ERR("RegEnumKeyW failed with error %d\n", res
);
955 hr
= REGDB_E_READREGDB
;
958 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
959 if (res
!= ERROR_SUCCESS
)
961 ERR("RegQueryValueW failed with error %d\n", res
);
962 hr
= REGDB_E_READREGDB
;
965 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
971 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
972 if (res
!= ERROR_SUCCESS
)
974 ERR("RegQueryValueW failed with error %d\n", res
);
975 hr
= REGDB_E_READREGDB
;
976 CoTaskMemFree(pwszOLEVERB
);
980 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
981 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
984 hr
= OLEOBJ_E_INVALIDVERB
;
985 CoTaskMemFree(pwszOLEVERB
);
988 /* nul terminate the name string and advance to first character */
989 *pwszMenuFlags
= '\0';
991 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
994 hr
= OLEOBJ_E_INVALIDVERB
;
995 CoTaskMemFree(pwszOLEVERB
);
998 /* nul terminate the menu string and advance to first character */
1002 /* fill out structure for this verb */
1003 rgelt
->lVerb
= atolW(wszSubKey
);
1004 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1005 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
1006 rgelt
->grfAttribs
= atolW(pwszAttribs
);
1015 static HRESULT WINAPI
EnumOLEVERB_Skip(
1016 IEnumOLEVERB
*iface
, ULONG celt
)
1018 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1020 TRACE("(%d)\n", celt
);
1022 This
->index
+= celt
;
1026 static HRESULT WINAPI
EnumOLEVERB_Reset(
1027 IEnumOLEVERB
*iface
)
1029 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1037 static HRESULT WINAPI
EnumOLEVERB_Clone(
1038 IEnumOLEVERB
*iface
,
1039 IEnumOLEVERB
**ppenum
)
1041 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1043 TRACE("(%p)\n", ppenum
);
1044 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1045 return HRESULT_FROM_WIN32(GetLastError());
1046 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1049 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1051 EnumOLEVERB_QueryInterface
,
1053 EnumOLEVERB_Release
,
1060 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1062 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1065 RegCloseKey(hkeyVerb
);
1066 return E_OUTOFMEMORY
;
1068 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1070 This
->index
= index
;
1071 This
->hkeyVerb
= hkeyVerb
;
1072 *ppenum
= &This
->IEnumOLEVERB_iface
;
1076 /***********************************************************************
1077 * OleRegEnumVerbs [OLE32.@]
1079 * Enumerates verbs associated with a class stored in the registry.
1082 * clsid [I] Class ID to enumerate the verbs for.
1083 * ppenum [O] Enumerator.
1087 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1088 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1089 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1090 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1092 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1097 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1099 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1101 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1104 if (res
== REGDB_E_CLASSNOTREG
)
1105 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1106 else if (res
== REGDB_E_KEYMISSING
)
1107 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1109 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1110 debugstr_guid(clsid
), res
);
1114 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1115 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1116 if (res
!= ERROR_SUCCESS
)
1118 ERR("failed to get subkey count with error %d\n", GetLastError());
1119 return REGDB_E_READREGDB
;
1124 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1125 RegCloseKey(hkeyVerb
);
1126 return OLEOBJ_E_NOVERBS
;
1129 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1132 /******************************************************************************
1133 * OleSetContainedObject [OLE32.@]
1135 HRESULT WINAPI
OleSetContainedObject(
1139 IRunnableObject
* runnable
= NULL
;
1142 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1144 hres
= IUnknown_QueryInterface(pUnknown
,
1145 &IID_IRunnableObject
,
1148 if (SUCCEEDED(hres
))
1150 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1152 IRunnableObject_Release(runnable
);
1160 /******************************************************************************
1163 * Set the OLE object to the running state.
1166 * pUnknown [I] OLE object to run.
1170 * Failure: Any HRESULT code.
1172 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1174 IRunnableObject
*runable
;
1177 TRACE("(%p)\n", pUnknown
);
1179 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1181 return S_OK
; /* Appears to return no error. */
1183 hres
= IRunnableObject_Run(runable
, NULL
);
1184 IRunnableObject_Release(runable
);
1188 /******************************************************************************
1191 HRESULT WINAPI
OleLoad(
1194 LPOLECLIENTSITE pClientSite
,
1197 IPersistStorage
* persistStorage
= NULL
;
1199 IOleObject
* pOleObject
= NULL
;
1200 STATSTG storageInfo
;
1203 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1208 * TODO, Conversion ... OleDoAutoConvert
1212 * Get the class ID for the object.
1214 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1219 * Now, try and create the handler for the object
1221 hres
= CoCreateInstance(&storageInfo
.clsid
,
1223 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1228 * If that fails, as it will most times, load the default
1233 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1240 * If we couldn't find a handler... this is bad. Abort the whole thing.
1247 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1248 if (SUCCEEDED(hres
))
1251 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1256 * Initialize the object with its IPersistStorage interface.
1258 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1259 if (SUCCEEDED(hres
))
1261 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1263 IPersistStorage_Release(persistStorage
);
1264 persistStorage
= NULL
;
1267 if (SUCCEEDED(hres
) && pClientSite
)
1269 * Inform the new object of its client site.
1271 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1274 * Cleanup interfaces used internally
1277 IOleObject_Release(pOleObject
);
1279 if (SUCCEEDED(hres
))
1283 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1284 if (SUCCEEDED(hres1
))
1286 FIXME("handle OLE link\n");
1287 IOleLink_Release(pOleLink
);
1293 IUnknown_Release(pUnk
);
1302 /***********************************************************************
1305 HRESULT WINAPI
OleSave(
1306 LPPERSISTSTORAGE pPS
,
1313 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1316 * First, we transfer the class ID (if available)
1318 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1320 if (SUCCEEDED(hres
))
1322 WriteClassStg(pStg
, &objectClass
);
1326 * Then, we ask the object to save itself to the
1327 * storage. If it is successful, we commit the storage.
1329 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1331 if (SUCCEEDED(hres
))
1333 IStorage_Commit(pStg
,
1341 /******************************************************************************
1342 * OleLockRunning [OLE32.@]
1344 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1346 IRunnableObject
* runnable
= NULL
;
1349 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1351 hres
= IUnknown_QueryInterface(pUnknown
,
1352 &IID_IRunnableObject
,
1355 if (SUCCEEDED(hres
))
1357 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1359 IRunnableObject_Release(runnable
);
1368 /**************************************************************************
1369 * Internal methods to manage the shared OLE menu in response to the
1370 * OLE***MenuDescriptor API
1374 * OLEMenu_Initialize()
1376 * Initializes the OLEMENU data structures.
1378 static void OLEMenu_Initialize(void)
1383 * OLEMenu_UnInitialize()
1385 * Releases the OLEMENU data structures.
1387 static void OLEMenu_UnInitialize(void)
1391 /*************************************************************************
1392 * OLEMenu_InstallHooks
1393 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1395 * RETURNS: TRUE if message hooks were successfully installed
1398 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1400 OleMenuHookItem
*pHookItem
;
1402 /* Create an entry for the hook table */
1403 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1404 sizeof(OleMenuHookItem
)) ) )
1407 pHookItem
->tid
= tid
;
1408 pHookItem
->hHeap
= GetProcessHeap();
1409 pHookItem
->CallWndProc_hHook
= NULL
;
1411 /* Install a thread scope message hook for WH_GETMESSAGE */
1412 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1413 0, GetCurrentThreadId() );
1414 if ( !pHookItem
->GetMsg_hHook
)
1417 /* Install a thread scope message hook for WH_CALLWNDPROC */
1418 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1419 0, GetCurrentThreadId() );
1420 if ( !pHookItem
->CallWndProc_hHook
)
1423 /* Insert the hook table entry */
1424 pHookItem
->next
= hook_list
;
1425 hook_list
= pHookItem
;
1430 /* Unhook any hooks */
1431 if ( pHookItem
->GetMsg_hHook
)
1432 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1433 if ( pHookItem
->CallWndProc_hHook
)
1434 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1435 /* Release the hook table entry */
1436 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1441 /*************************************************************************
1442 * OLEMenu_UnInstallHooks
1443 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1445 * RETURNS: TRUE if message hooks were successfully installed
1448 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1450 OleMenuHookItem
*pHookItem
= NULL
;
1451 OleMenuHookItem
**ppHook
= &hook_list
;
1455 if ((*ppHook
)->tid
== tid
)
1457 pHookItem
= *ppHook
;
1458 *ppHook
= pHookItem
->next
;
1461 ppHook
= &(*ppHook
)->next
;
1463 if (!pHookItem
) return FALSE
;
1465 /* Uninstall the hooks installed for this thread */
1466 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1468 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1471 /* Release the hook table entry */
1472 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1477 /* Release the hook table entry */
1478 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1483 /*************************************************************************
1484 * OLEMenu_IsHookInstalled
1485 * Tests if OLEMenu hooks have been installed for a thread
1487 * RETURNS: The pointer and index of the hook table entry for the tid
1488 * NULL and -1 for the index if no hooks were installed for this thread
1490 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1492 OleMenuHookItem
*pHookItem
;
1494 /* Do a simple linear search for an entry whose tid matches ours.
1495 * We really need a map but efficiency is not a concern here. */
1496 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1498 if ( tid
== pHookItem
->tid
)
1505 /***********************************************************************
1506 * OLEMenu_FindMainMenuIndex
1508 * Used by OLEMenu API to find the top level group a menu item belongs to.
1509 * On success pnPos contains the index of the item in the top level menu group
1511 * RETURNS: TRUE if the ID was found, FALSE on failure
1513 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1517 nItems
= GetMenuItemCount( hMainMenu
);
1519 for (i
= 0; i
< nItems
; i
++)
1523 /* Is the current item a submenu? */
1524 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1526 /* If the handle is the same we're done */
1527 if ( hsubmenu
== hPopupMenu
)
1533 /* Recursively search without updating pnPos */
1534 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1546 /***********************************************************************
1547 * OLEMenu_SetIsServerMenu
1549 * Checks whether a popup menu belongs to a shared menu group which is
1550 * owned by the server, and sets the menu descriptor state accordingly.
1551 * All menu messages from these groups should be routed to the server.
1553 * RETURNS: TRUE if the popup menu is part of a server owned group
1554 * FALSE if the popup menu is part of a container owned group
1556 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1558 UINT nPos
= 0, nWidth
, i
;
1560 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1562 /* Don't bother searching if the popup is the combined menu itself */
1563 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1566 /* Find the menu item index in the shared OLE menu that this item belongs to */
1567 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1570 /* The group widths array has counts for the number of elements
1571 * in the groups File, Edit, Container, Object, Window, Help.
1572 * The Edit, Object & Help groups belong to the server object
1573 * and the other three belong to the container.
1574 * Loop through the group widths and locate the group we are a member of.
1576 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1578 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1579 if ( nPos
< nWidth
)
1581 /* Odd elements are server menu widths */
1582 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1587 return pOleMenuDescriptor
->bIsServerItem
;
1590 /*************************************************************************
1591 * OLEMenu_CallWndProc
1592 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1593 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1595 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1598 HOLEMENU hOleMenu
= 0;
1599 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1600 OleMenuHookItem
*pHookItem
= NULL
;
1603 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1605 /* Check if we're being asked to process the message */
1606 if ( HC_ACTION
!= code
)
1609 /* Retrieve the current message being dispatched from lParam */
1610 pMsg
= (LPCWPSTRUCT
)lParam
;
1612 /* Check if the message is destined for a window we are interested in:
1613 * If the window has an OLEMenu property we may need to dispatch
1614 * the menu message to its active objects window instead. */
1616 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1620 /* Get the menu descriptor */
1621 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1622 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1625 /* Process menu messages */
1626 switch( pMsg
->message
)
1630 /* Reset the menu descriptor state */
1631 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1633 /* Send this message to the server as well */
1634 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1635 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1639 case WM_INITMENUPOPUP
:
1641 /* Save the state for whether this is a server owned menu */
1642 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1648 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1649 if ( fuFlags
& MF_SYSMENU
)
1652 /* Save the state for whether this is a server owned popup menu */
1653 else if ( fuFlags
& MF_POPUP
)
1654 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1661 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1662 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1663 goto NEXTHOOK
; /* Not a menu message */
1672 /* If the message was for the server dispatch it accordingly */
1673 if ( pOleMenuDescriptor
->bIsServerItem
)
1675 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1676 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1680 if ( pOleMenuDescriptor
)
1681 GlobalUnlock( hOleMenu
);
1683 /* Lookup the hook item for the current thread */
1684 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1686 /* This should never fail!! */
1687 WARN("could not retrieve hHook for current thread!\n" );
1691 /* Pass on the message to the next hooker */
1692 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1695 /*************************************************************************
1696 * OLEMenu_GetMsgProc
1697 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1698 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1700 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1703 HOLEMENU hOleMenu
= 0;
1704 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1705 OleMenuHookItem
*pHookItem
= NULL
;
1708 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1710 /* Check if we're being asked to process a messages */
1711 if ( HC_ACTION
!= code
)
1714 /* Retrieve the current message being dispatched from lParam */
1715 pMsg
= (LPMSG
)lParam
;
1717 /* Check if the message is destined for a window we are interested in:
1718 * If the window has an OLEMenu property we may need to dispatch
1719 * the menu message to its active objects window instead. */
1721 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1725 /* Process menu messages */
1726 switch( pMsg
->message
)
1730 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1732 goto NEXTHOOK
; /* Not a menu message */
1739 /* Get the menu descriptor */
1740 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1741 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1744 /* If the message was for the server dispatch it accordingly */
1745 if ( pOleMenuDescriptor
->bIsServerItem
)
1747 /* Change the hWnd in the message to the active objects hWnd.
1748 * The message loop which reads this message will automatically
1749 * dispatch it to the embedded objects window. */
1750 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1754 if ( pOleMenuDescriptor
)
1755 GlobalUnlock( hOleMenu
);
1757 /* Lookup the hook item for the current thread */
1758 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1760 /* This should never fail!! */
1761 WARN("could not retrieve hHook for current thread!\n" );
1765 /* Pass on the message to the next hooker */
1766 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1769 /***********************************************************************
1770 * OleCreateMenuDescriptor [OLE32.@]
1771 * Creates an OLE menu descriptor for OLE to use when dispatching
1772 * menu messages and commands.
1775 * hmenuCombined - Handle to the objects combined menu
1776 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1779 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1780 HMENU hmenuCombined
,
1781 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1784 OleMenuDescriptor
*pOleMenuDescriptor
;
1787 if ( !hmenuCombined
|| !lpMenuWidths
)
1790 /* Create an OLE menu descriptor */
1791 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1792 sizeof(OleMenuDescriptor
) ) ) )
1795 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1796 if ( !pOleMenuDescriptor
)
1799 /* Initialize menu group widths and hmenu */
1800 for ( i
= 0; i
< 6; i
++ )
1801 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1803 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1804 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1805 GlobalUnlock( hOleMenu
);
1810 /***********************************************************************
1811 * OleDestroyMenuDescriptor [OLE32.@]
1812 * Destroy the shared menu descriptor
1814 HRESULT WINAPI
OleDestroyMenuDescriptor(
1815 HOLEMENU hmenuDescriptor
)
1817 if ( hmenuDescriptor
)
1818 GlobalFree( hmenuDescriptor
);
1822 /***********************************************************************
1823 * OleSetMenuDescriptor [OLE32.@]
1824 * Installs or removes OLE dispatching code for the containers frame window.
1827 * hOleMenu Handle to composite menu descriptor
1828 * hwndFrame Handle to containers frame window
1829 * hwndActiveObject Handle to objects in-place activation window
1830 * lpFrame Pointer to IOleInPlaceFrame on containers window
1831 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1834 * S_OK - menu installed correctly
1835 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1838 * The lpFrame and lpActiveObject parameters are currently ignored
1839 * OLE should install context sensitive help F1 filtering for the app when
1840 * these are non null.
1842 HRESULT WINAPI
OleSetMenuDescriptor(
1845 HWND hwndActiveObject
,
1846 LPOLEINPLACEFRAME lpFrame
,
1847 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1849 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1852 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1853 return E_INVALIDARG
;
1855 if ( lpFrame
|| lpActiveObject
)
1857 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1865 /* Set up a message hook to intercept the containers frame window messages.
1866 * The message filter is responsible for dispatching menu messages from the
1867 * shared menu which are intended for the object.
1870 if ( hOleMenu
) /* Want to install dispatching code */
1872 /* If OLEMenu hooks are already installed for this thread, fail
1873 * Note: This effectively means that OleSetMenuDescriptor cannot
1874 * be called twice in succession on the same frame window
1875 * without first calling it with a null hOleMenu to uninstall
1877 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1880 /* Get the menu descriptor */
1881 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1882 if ( !pOleMenuDescriptor
)
1883 return E_UNEXPECTED
;
1885 /* Update the menu descriptor */
1886 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1887 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1889 GlobalUnlock( hOleMenu
);
1890 pOleMenuDescriptor
= NULL
;
1892 /* Add a menu descriptor windows property to the frame window */
1893 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1895 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1896 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1899 else /* Want to uninstall dispatching code */
1901 /* Uninstall the hooks */
1902 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1905 /* Remove the menu descriptor property from the frame window */
1906 RemovePropW( hwndFrame
, prop_olemenuW
);
1912 /******************************************************************************
1913 * IsAccelerator [OLE32.@]
1914 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1916 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1921 if(!lpMsg
) return FALSE
;
1924 WARN_(accel
)("NULL accel handle\n");
1927 if((lpMsg
->message
!= WM_KEYDOWN
&&
1928 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1929 lpMsg
->message
!= WM_SYSCHAR
&&
1930 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1931 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1932 if (NULL
== lpAccelTbl
)
1936 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1938 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1939 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1943 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1944 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1945 hAccel
, cAccelEntries
,
1946 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1947 for(i
= 0; i
< cAccelEntries
; i
++)
1949 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1952 if(lpMsg
->message
== WM_CHAR
)
1954 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1956 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1962 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1965 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1966 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1967 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1968 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1969 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1970 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1971 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1975 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1977 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1978 { /* ^^ ALT pressed */
1979 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
1987 WARN_(accel
)("couldn't translate accelerator key\n");
1988 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1992 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1993 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1997 /***********************************************************************
1998 * ReleaseStgMedium [OLE32.@]
2000 void WINAPI
ReleaseStgMedium(
2003 switch (pmedium
->tymed
)
2007 if ( (pmedium
->pUnkForRelease
==0) &&
2008 (pmedium
->u
.hGlobal
!=0) )
2009 GlobalFree(pmedium
->u
.hGlobal
);
2014 if (pmedium
->u
.lpszFileName
!=0)
2016 if (pmedium
->pUnkForRelease
==0)
2018 DeleteFileW(pmedium
->u
.lpszFileName
);
2021 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2027 if (pmedium
->u
.pstm
!=0)
2029 IStream_Release(pmedium
->u
.pstm
);
2033 case TYMED_ISTORAGE
:
2035 if (pmedium
->u
.pstg
!=0)
2037 IStorage_Release(pmedium
->u
.pstg
);
2043 if ( (pmedium
->pUnkForRelease
==0) &&
2044 (pmedium
->u
.hBitmap
!=0) )
2045 DeleteObject(pmedium
->u
.hBitmap
);
2050 if ( (pmedium
->pUnkForRelease
==0) &&
2051 (pmedium
->u
.hMetaFilePict
!=0) )
2053 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2054 DeleteMetaFile(pMP
->hMF
);
2055 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2056 GlobalFree(pmedium
->u
.hMetaFilePict
);
2062 if ( (pmedium
->pUnkForRelease
==0) &&
2063 (pmedium
->u
.hEnhMetaFile
!=0) )
2065 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2073 pmedium
->tymed
=TYMED_NULL
;
2076 * After cleaning up, the unknown is released
2078 if (pmedium
->pUnkForRelease
!=0)
2080 IUnknown_Release(pmedium
->pUnkForRelease
);
2081 pmedium
->pUnkForRelease
= 0;
2086 * OLEDD_Initialize()
2088 * Initializes the OLE drag and drop data structures.
2090 static void OLEDD_Initialize(void)
2094 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2095 wndClass
.style
= CS_GLOBALCLASS
;
2096 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2097 wndClass
.cbClsExtra
= 0;
2098 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2099 wndClass
.hCursor
= 0;
2100 wndClass
.hbrBackground
= 0;
2101 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2103 RegisterClassW (&wndClass
);
2107 * OLEDD_DragTrackerWindowProc()
2109 * This method is the WindowProcedure of the drag n drop tracking
2110 * window. During a drag n Drop operation, an invisible window is created
2111 * to receive the user input and act upon it. This procedure is in charge
2115 #define DRAG_TIMER_ID 1
2117 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2127 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2129 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2130 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2139 case WM_LBUTTONDOWN
:
2140 case WM_MBUTTONDOWN
:
2141 case WM_RBUTTONDOWN
:
2143 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2144 if (trackerInfo
->trackingDone
) break;
2145 OLEDD_TrackStateChange(trackerInfo
);
2150 KillTimer(hwnd
, DRAG_TIMER_ID
);
2156 * This is a window proc after all. Let's call the default.
2158 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2161 static void drag_enter( TrackerWindowInfo
*info
, HWND new_target
)
2165 info
->curTargetHWND
= new_target
;
2167 while (new_target
&& !is_droptarget( new_target
))
2168 new_target
= GetParent( new_target
);
2170 info
->curDragTarget
= get_droptarget_pointer( new_target
);
2172 if (info
->curDragTarget
)
2174 *info
->pdwEffect
= info
->dwOKEffect
;
2175 hr
= IDropTarget_DragEnter( info
->curDragTarget
, info
->dataObject
,
2176 info
->dwKeyState
, info
->curMousePos
,
2178 *info
->pdwEffect
&= info
->dwOKEffect
;
2180 /* failed DragEnter() means invalid target */
2183 IDropTarget_Release( info
->curDragTarget
);
2184 info
->curDragTarget
= NULL
;
2185 info
->curTargetHWND
= NULL
;
2190 static void drag_end( TrackerWindowInfo
*info
)
2194 info
->trackingDone
= TRUE
;
2197 if (info
->curDragTarget
)
2199 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2200 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2202 *info
->pdwEffect
= info
->dwOKEffect
;
2203 hr
= IDropTarget_Drop( info
->curDragTarget
, info
->dataObject
, info
->dwKeyState
,
2204 info
->curMousePos
, info
->pdwEffect
);
2205 *info
->pdwEffect
&= info
->dwOKEffect
;
2208 info
->returnValue
= hr
;
2212 IDropTarget_DragLeave( info
->curDragTarget
);
2213 *info
->pdwEffect
= DROPEFFECT_NONE
;
2215 IDropTarget_Release( info
->curDragTarget
);
2216 info
->curDragTarget
= NULL
;
2219 *info
->pdwEffect
= DROPEFFECT_NONE
;
2222 static HRESULT
give_feedback( TrackerWindowInfo
*info
)
2228 if (info
->curDragTarget
== NULL
)
2229 *info
->pdwEffect
= DROPEFFECT_NONE
;
2231 hr
= IDropSource_GiveFeedback( info
->dropSource
, *info
->pdwEffect
);
2233 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2235 if (*info
->pdwEffect
& DROPEFFECT_MOVE
)
2237 else if (*info
->pdwEffect
& DROPEFFECT_COPY
)
2239 else if (*info
->pdwEffect
& DROPEFFECT_LINK
)
2242 res
= CURSOR_NODROP
;
2244 cur
= LoadCursorW( hProxyDll
, MAKEINTRESOURCEW( res
) );
2252 * OLEDD_TrackStateChange()
2254 * This method is invoked while a drag and drop operation is in effect.
2257 * trackerInfo - Pointer to the structure identifying the
2258 * drag & drop operation that is currently
2261 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2263 HWND hwndNewTarget
= 0;
2267 * Get the handle of the window under the mouse
2269 pt
.x
= trackerInfo
->curMousePos
.x
;
2270 pt
.y
= trackerInfo
->curMousePos
.y
;
2271 hwndNewTarget
= WindowFromPoint(pt
);
2273 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2274 trackerInfo
->escPressed
,
2275 trackerInfo
->dwKeyState
);
2277 if (trackerInfo
->curTargetHWND
!= hwndNewTarget
&&
2278 (trackerInfo
->returnValue
== S_OK
||
2279 trackerInfo
->returnValue
== DRAGDROP_S_DROP
))
2281 if (trackerInfo
->curDragTarget
)
2283 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2284 IDropTarget_Release(trackerInfo
->curDragTarget
);
2285 trackerInfo
->curDragTarget
= NULL
;
2286 trackerInfo
->curTargetHWND
= NULL
;
2290 drag_enter( trackerInfo
, hwndNewTarget
);
2292 give_feedback( trackerInfo
);
2296 if (trackerInfo
->returnValue
== S_OK
)
2298 if (trackerInfo
->curDragTarget
)
2300 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2301 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2302 trackerInfo
->dwKeyState
,
2303 trackerInfo
->curMousePos
,
2304 trackerInfo
->pdwEffect
);
2305 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2307 give_feedback( trackerInfo
);
2310 drag_end( trackerInfo
);
2314 * OLEDD_GetButtonState()
2316 * This method will use the current state of the keyboard to build
2317 * a button state mask equivalent to the one passed in the
2318 * WM_MOUSEMOVE wParam.
2320 static DWORD
OLEDD_GetButtonState(void)
2322 BYTE keyboardState
[256];
2325 GetKeyboardState(keyboardState
);
2327 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2328 keyMask
|= MK_SHIFT
;
2330 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2331 keyMask
|= MK_CONTROL
;
2333 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2336 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2337 keyMask
|= MK_LBUTTON
;
2339 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2340 keyMask
|= MK_RBUTTON
;
2342 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2343 keyMask
|= MK_MBUTTON
;
2349 * OLEDD_GetButtonState()
2351 * This method will read the default value of the registry key in
2352 * parameter and extract a DWORD value from it. The registry key value
2353 * can be in a string key or a DWORD key.
2356 * regKey - Key to read the default value from
2357 * pdwValue - Pointer to the location where the DWORD
2358 * value is returned. This value is not modified
2359 * if the value is not found.
2362 static void OLEUTL_ReadRegistryDWORDValue(
2367 DWORD cbData
= sizeof(buffer
);
2371 lres
= RegQueryValueExW(regKey
,
2378 if (lres
==ERROR_SUCCESS
)
2383 *pdwValue
= *(DWORD
*)buffer
;
2388 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2394 /******************************************************************************
2397 * The operation of this function is documented literally in the WinAPI
2398 * documentation to involve a QueryInterface for the IViewObject interface,
2399 * followed by a call to IViewObject::Draw.
2401 HRESULT WINAPI
OleDraw(
2408 IViewObject
*viewobject
;
2410 if (!pUnk
) return E_INVALIDARG
;
2412 hres
= IUnknown_QueryInterface(pUnk
,
2414 (void**)&viewobject
);
2415 if (SUCCEEDED(hres
))
2417 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2418 IViewObject_Release(viewobject
);
2422 return DV_E_NOIVIEWOBJECT
;
2425 /***********************************************************************
2426 * OleTranslateAccelerator [OLE32.@]
2428 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2429 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2433 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2435 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2436 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2441 /******************************************************************************
2442 * OleCreate [OLE32.@]
2445 HRESULT WINAPI
OleCreate(
2449 LPFORMATETC pFormatEtc
,
2450 LPOLECLIENTSITE pClientSite
,
2455 IUnknown
* pUnk
= NULL
;
2456 IOleObject
*pOleObject
= NULL
;
2458 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2459 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2461 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2463 if (SUCCEEDED(hres
))
2464 hres
= IStorage_SetClass(pStg
, rclsid
);
2466 if (pClientSite
&& SUCCEEDED(hres
))
2468 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2469 if (SUCCEEDED(hres
))
2472 IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2476 if (SUCCEEDED(hres
))
2478 IPersistStorage
* pPS
;
2479 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2481 TRACE("trying to set stg %p\n", pStg
);
2482 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2483 TRACE("-- result 0x%08x\n", hres
);
2484 IPersistStorage_Release(pPS
);
2488 if (pClientSite
&& SUCCEEDED(hres
))
2490 TRACE("trying to set clientsite %p\n", pClientSite
);
2491 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2492 TRACE("-- result 0x%08x\n", hres
);
2496 IOleObject_Release(pOleObject
);
2498 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2501 hres
= OleRun(pUnk
);
2502 if (SUCCEEDED(hres
))
2504 IOleCache
*pOleCache
;
2506 if (SUCCEEDED(IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
)))
2509 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2513 pfe
.dwAspect
= DVASPECT_CONTENT
;
2515 pfe
.tymed
= TYMED_NULL
;
2516 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2519 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2520 IOleCache_Release(pOleCache
);
2525 if (FAILED(hres
) && pUnk
)
2527 IUnknown_Release(pUnk
);
2533 TRACE("-- %p\n", pUnk
);
2537 /******************************************************************************
2538 * OleGetAutoConvert [OLE32.@]
2540 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2542 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2544 WCHAR buf
[CHARS_IN_GUID
];
2548 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2553 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2555 res
= REGDB_E_KEYMISSING
;
2558 res
= CLSIDFromString(buf
, pClsidNew
);
2560 if (hkey
) RegCloseKey(hkey
);
2564 /******************************************************************************
2565 * OleSetAutoConvert [OLE32.@]
2567 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2569 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2571 WCHAR szClsidNew
[CHARS_IN_GUID
];
2574 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2576 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2579 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2580 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2582 res
= REGDB_E_WRITEREGDB
;
2587 if (hkey
) RegCloseKey(hkey
);
2591 /******************************************************************************
2592 * OleDoAutoConvert [OLE32.@]
2594 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2596 WCHAR
*user_type_old
, *user_type_new
;
2602 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2604 *pClsidNew
= CLSID_NULL
;
2606 return E_INVALIDARG
;
2607 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2611 *pClsidNew
= stat
.clsid
;
2612 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2616 hr
= IStorage_SetClass(pStg
, &clsid
);
2620 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2623 user_type_new
= NULL
;
2626 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2628 user_type_new
= NULL
;
2630 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2631 CoTaskMemFree(user_type_new
);
2634 CoTaskMemFree(user_type_old
);
2635 IStorage_SetClass(pStg
, &stat
.clsid
);
2639 hr
= SetConvertStg(pStg
, TRUE
);
2642 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2643 IStorage_SetClass(pStg
, &stat
.clsid
);
2647 CoTaskMemFree(user_type_old
);
2651 /******************************************************************************
2652 * OleIsRunning [OLE32.@]
2654 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2656 IRunnableObject
*pRunnable
;
2660 TRACE("(%p)\n", object
);
2662 if (!object
) return FALSE
;
2664 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2667 running
= IRunnableObject_IsRunning(pRunnable
);
2668 IRunnableObject_Release(pRunnable
);
2672 /***********************************************************************
2673 * OleNoteObjectVisible [OLE32.@]
2675 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2677 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2678 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2682 /***********************************************************************
2683 * OLE_FreeClipDataArray [internal]
2686 * frees the data associated with an array of CLIPDATAs
2688 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2691 for (i
= 0; i
< count
; i
++)
2692 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2695 /***********************************************************************
2696 * PropSysAllocString [OLE32.@]
2698 * Forward to oleaut32.
2700 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2702 return SysAllocString(str
);
2705 /***********************************************************************
2706 * PropSysFreeString [OLE32.@]
2708 * Forward to oleaut32.
2710 void WINAPI
PropSysFreeString(LPOLESTR str
)
2715 /******************************************************************************
2716 * Check if a PROPVARIANT's type is valid.
2718 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2750 case VT_STREAMED_OBJECT
:
2751 case VT_STORED_OBJECT
:
2752 case VT_BLOB_OBJECT
:
2755 case VT_I1
|VT_VECTOR
:
2756 case VT_I2
|VT_VECTOR
:
2757 case VT_I4
|VT_VECTOR
:
2758 case VT_I8
|VT_VECTOR
:
2759 case VT_R4
|VT_VECTOR
:
2760 case VT_R8
|VT_VECTOR
:
2761 case VT_CY
|VT_VECTOR
:
2762 case VT_DATE
|VT_VECTOR
:
2763 case VT_BSTR
|VT_VECTOR
:
2764 case VT_ERROR
|VT_VECTOR
:
2765 case VT_BOOL
|VT_VECTOR
:
2766 case VT_VARIANT
|VT_VECTOR
:
2767 case VT_UI1
|VT_VECTOR
:
2768 case VT_UI2
|VT_VECTOR
:
2769 case VT_UI4
|VT_VECTOR
:
2770 case VT_UI8
|VT_VECTOR
:
2771 case VT_LPSTR
|VT_VECTOR
:
2772 case VT_LPWSTR
|VT_VECTOR
:
2773 case VT_FILETIME
|VT_VECTOR
:
2774 case VT_CF
|VT_VECTOR
:
2775 case VT_CLSID
|VT_VECTOR
:
2778 WARN("Bad type %d\n", vt
);
2779 return STG_E_INVALIDPARAMETER
;
2782 /***********************************************************************
2783 * PropVariantClear [OLE32.@]
2785 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2789 TRACE("(%p)\n", pvar
);
2794 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2797 memset(pvar
, 0, sizeof(*pvar
));
2827 case VT_STREAMED_OBJECT
:
2829 case VT_STORED_OBJECT
:
2830 if (pvar
->u
.pStream
)
2831 IStream_Release(pvar
->u
.pStream
);
2836 /* pick an arbitrary typed pointer - we don't care about the type
2837 * as we are just freeing it */
2838 CoTaskMemFree(pvar
->u
.puuid
);
2841 case VT_BLOB_OBJECT
:
2842 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2845 PropSysFreeString(pvar
->u
.bstrVal
);
2848 if (pvar
->u
.pclipdata
)
2850 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2851 CoTaskMemFree(pvar
->u
.pclipdata
);
2855 if (pvar
->vt
& VT_VECTOR
)
2859 switch (pvar
->vt
& ~VT_VECTOR
)
2862 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2865 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2868 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2869 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2872 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2873 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2876 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2877 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2880 if (pvar
->vt
& ~VT_VECTOR
)
2882 /* pick an arbitrary VT_VECTOR structure - they all have the same
2884 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2889 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2890 hr
= STG_E_INVALIDPARAMETER
;
2894 memset(pvar
, 0, sizeof(*pvar
));
2898 /***********************************************************************
2899 * PropVariantCopy [OLE32.@]
2901 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2902 const PROPVARIANT
*pvarSrc
) /* [in] */
2907 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
2909 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2911 return DISP_E_BADVARTYPE
;
2913 /* this will deal with most cases */
2914 *pvarDest
= *pvarSrc
;
2942 case VT_STREAMED_OBJECT
:
2944 case VT_STORED_OBJECT
:
2945 if (pvarDest
->u
.pStream
)
2946 IStream_AddRef(pvarDest
->u
.pStream
);
2949 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2950 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
2953 if (pvarSrc
->u
.pszVal
)
2955 len
= strlen(pvarSrc
->u
.pszVal
);
2956 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2957 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2961 if (pvarSrc
->u
.pwszVal
)
2963 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2964 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2965 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2969 case VT_BLOB_OBJECT
:
2970 if (pvarSrc
->u
.blob
.pBlobData
)
2972 len
= pvarSrc
->u
.blob
.cbSize
;
2973 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2974 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2978 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2981 if (pvarSrc
->u
.pclipdata
)
2983 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2984 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
2985 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
2986 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
2987 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2988 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2992 if (pvarSrc
->vt
& VT_VECTOR
)
2997 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2999 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3000 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3001 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3002 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3003 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3004 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3005 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3006 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3007 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3008 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3009 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3010 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3011 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3012 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3013 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3014 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3015 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3016 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3017 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3018 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3019 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3022 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3023 return E_INVALIDARG
;
3025 len
= pvarSrc
->u
.capropvar
.cElems
;
3026 pvarDest
->u
.capropvar
.pElems
= len
? CoTaskMemAlloc(len
* elemSize
) : NULL
;
3027 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3029 for (i
= 0; i
< len
; i
++)
3030 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3032 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3034 FIXME("Copy clipformats\n");
3036 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3038 for (i
= 0; i
< len
; i
++)
3039 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3041 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3044 for (i
= 0; i
< len
; i
++)
3046 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3047 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3048 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3049 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3052 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3055 for (i
= 0; i
< len
; i
++)
3057 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3059 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3060 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3061 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3065 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3068 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3074 /***********************************************************************
3075 * FreePropVariantArray [OLE32.@]
3077 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3078 PROPVARIANT
*rgvars
) /* [in/out] */
3082 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3085 return E_INVALIDARG
;
3087 for(i
= 0; i
< cVariants
; i
++)
3088 PropVariantClear(&rgvars
[i
]);
3093 /******************************************************************************
3094 * DllDebugObjectRPCHook (OLE32.@)
3095 * turns on and off internal debugging, pointer is only used on macintosh
3098 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)