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
;
76 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
77 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
80 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
82 HWND hwndFrame
; /* The containers frame window */
83 HWND hwndActiveObject
; /* The active objects window */
84 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
85 HMENU hmenuCombined
; /* The combined menu */
86 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
89 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
91 DWORD tid
; /* Thread Id */
92 HANDLE hHeap
; /* Heap this is allocated from */
93 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
94 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
95 struct tagOleMenuHookItem
*next
;
98 static OleMenuHookItem
*hook_list
;
101 * This is the lock count on the OLE library. It is controlled by the
102 * OLEInitialize/OLEUninitialize methods.
104 static LONG OLE_moduleLockCount
= 0;
107 * Name of our registered window class.
109 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
110 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
113 * Name of menu descriptor property.
115 static const WCHAR prop_olemenuW
[] =
116 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
118 /* property to store IDropTarget pointer */
119 static const WCHAR prop_oledroptarget
[] =
120 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
122 /* property to store Marshalled IDropTarget pointer */
123 static const WCHAR prop_marshalleddroptarget
[] =
124 {'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};
126 static const WCHAR emptyW
[] = { 0 };
128 /******************************************************************************
129 * These are the prototypes of miscellaneous utility methods
131 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
133 /******************************************************************************
134 * These are the prototypes of the utility methods used to manage a shared menu
136 static void OLEMenu_Initialize(void);
137 static void OLEMenu_UnInitialize(void);
138 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
139 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
140 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
141 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
142 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
143 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
144 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
146 /******************************************************************************
147 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
149 extern void OLEClipbrd_UnInitialize(void);
150 extern void OLEClipbrd_Initialize(void);
152 /******************************************************************************
153 * These are the prototypes of the utility methods used for OLE Drag n Drop
155 static void OLEDD_Initialize(void);
156 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
157 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
158 static DWORD
OLEDD_GetButtonState(void);
160 /******************************************************************************
161 * OleBuildVersion [OLE32.@]
163 DWORD WINAPI
OleBuildVersion(void)
165 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
166 return (rmm
<<16)+rup
;
169 /***********************************************************************
170 * OleInitialize (OLE32.@)
172 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
176 TRACE("(%p)\n", reserved
);
179 * The first duty of the OleInitialize is to initialize the COM libraries.
181 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
184 * If the CoInitializeEx call failed, the OLE libraries can't be
190 if (!COM_CurrentInfo()->ole_inits
)
196 * Then, it has to initialize the OLE specific modules.
200 * Object linking and Embedding
201 * In-place activation
203 if (!COM_CurrentInfo()->ole_inits
++ &&
204 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
207 * Initialize the libraries.
209 TRACE("() - Initializing the OLE libraries\n");
214 OLEClipbrd_Initialize();
224 OLEMenu_Initialize();
230 /******************************************************************************
231 * OleUninitialize [OLE32.@]
233 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
237 if (COM_CurrentInfo()->ole_inits
== 0)
239 WARN("ole_inits is already 0\n");
243 * If we hit the bottom of the lock stack, free the libraries.
245 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
248 * Actually free the libraries.
250 TRACE("() - Freeing the last reference count\n");
255 OLEClipbrd_UnInitialize();
260 OLEMenu_UnInitialize();
264 * Then, uninitialize the COM libraries.
269 /******************************************************************************
270 * OleInitializeWOW [OLE32.@]
272 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
273 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
277 /*************************************************************
278 * get_droptarget_handle
280 * Retrieve a handle to the map containing the marshalled IDropTarget.
281 * This handle belongs to the process that called RegisterDragDrop.
282 * See get_droptarget_local_handle().
284 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
286 return GetPropW(hwnd
, prop_marshalleddroptarget
);
289 /*************************************************************
292 * Is the window a droptarget.
294 static inline BOOL
is_droptarget(HWND hwnd
)
296 return get_droptarget_handle(hwnd
) != 0;
300 static inline BOOL
is_acceptfiles(HWND hwnd
)
302 return !!(GetWindowLong(hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
);
305 /*************************************************************
306 * get_droptarget_local_handle
308 * Retrieve a handle to the map containing the marshalled IDropTarget.
309 * The handle should be closed when finished with.
311 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
313 HANDLE handle
, local_handle
= 0;
315 handle
= get_droptarget_handle(hwnd
);
322 GetWindowThreadProcessId(hwnd
, &pid
);
323 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
326 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
327 CloseHandle(process
);
333 /***********************************************************************
334 * create_map_from_stream
336 * Helper for RegisterDragDrop. Creates a file mapping object
337 * with the contents of the provided stream. The stream must
338 * be a global memory backed stream.
340 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
347 hr
= GetHGlobalFromStream(stream
, &hmem
);
348 if(FAILED(hr
)) return hr
;
350 size
= GlobalSize(hmem
);
351 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
352 if(!*map
) return E_OUTOFMEMORY
;
354 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
355 memcpy(data
, GlobalLock(hmem
), size
);
357 UnmapViewOfFile(data
);
361 /***********************************************************************
362 * create_stream_from_map
364 * Creates a stream from the provided map.
366 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
368 HRESULT hr
= E_OUTOFMEMORY
;
371 MEMORY_BASIC_INFORMATION info
;
373 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
376 VirtualQuery(data
, &info
, sizeof(info
));
377 TRACE("size %d\n", (int)info
.RegionSize
);
379 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
382 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
384 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
386 UnmapViewOfFile(data
);
390 /* This is to work around apps which break COM rules by not implementing
391 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
392 * doesn't call CoMarshallInterface() in RegisterDragDrop().
393 * The wrapper is only used internally, and only exists for the life of
394 * the marshal. We don't want to hold a ref on the app provided target
395 * as some apps destroy this prior to CoUninitialize without calling
396 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
398 IDropTarget IDropTarget_iface
;
403 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
405 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
408 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
412 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
413 if (IsEqualIID(riid
, &IID_IUnknown
) ||
414 IsEqualIID(riid
, &IID_IDropTarget
))
416 IDropTarget_AddRef(&This
->IDropTarget_iface
);
417 *ppvObject
= &This
->IDropTarget_iface
;
421 return E_NOINTERFACE
;
424 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
426 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
427 return InterlockedIncrement(&This
->refs
);
430 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
432 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
433 ULONG refs
= InterlockedDecrement(&This
->refs
);
434 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
438 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
440 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
441 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
442 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
443 IDropTarget_AddRef( *target
);
447 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
448 IDataObject
* pDataObj
,
454 HRESULT r
= get_target_from_wrapper( iface
, &target
);
458 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
459 IDropTarget_Release( target
);
464 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
470 HRESULT r
= get_target_from_wrapper( iface
, &target
);
474 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
475 IDropTarget_Release( target
);
480 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
483 HRESULT r
= get_target_from_wrapper( iface
, &target
);
487 r
= IDropTarget_DragLeave( target
);
488 IDropTarget_Release( target
);
493 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
494 IDataObject
* pDataObj
,
500 HRESULT r
= get_target_from_wrapper( iface
, &target
);
504 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
505 IDropTarget_Release( target
);
510 static const IDropTargetVtbl DropTargetWrapperVTbl
=
512 DropTargetWrapper_QueryInterface
,
513 DropTargetWrapper_AddRef
,
514 DropTargetWrapper_Release
,
515 DropTargetWrapper_DragEnter
,
516 DropTargetWrapper_DragOver
,
517 DropTargetWrapper_DragLeave
,
518 DropTargetWrapper_Drop
521 static IDropTarget
* WrapDropTarget( HWND hwnd
)
523 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
527 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
531 return &This
->IDropTarget_iface
;
534 /***********************************************************************
535 * get_droptarget_pointer
537 * Retrieves the marshalled IDropTarget from the window.
539 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
541 IDropTarget
*droptarget
= NULL
;
545 map
= get_droptarget_local_handle(hwnd
);
546 if(!map
) return NULL
;
548 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
550 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
551 IStream_Release(stream
);
557 /***********************************************************************
558 * RegisterDragDrop (OLE32.@)
560 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
566 IDropTarget
*wrapper
;
568 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
570 if (!COM_CurrentApt())
572 ERR("COM not initialized\n");
573 return E_OUTOFMEMORY
;
581 ERR("invalid hwnd %p\n", hwnd
);
582 return DRAGDROP_E_INVALIDHWND
;
585 /* block register for other processes windows */
586 GetWindowThreadProcessId(hwnd
, &pid
);
587 if (pid
!= GetCurrentProcessId())
589 FIXME("register for another process windows is disabled\n");
590 return DRAGDROP_E_INVALIDHWND
;
593 /* check if the window is already registered */
594 if (is_droptarget(hwnd
))
595 return DRAGDROP_E_ALREADYREGISTERED
;
598 * Marshal the drop target pointer into a shared memory map and
599 * store the map's handle in a Wine specific window prop. We also
600 * store the drop target pointer itself in the
601 * "OleDropTargetInterface" prop for compatibility with Windows.
604 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
605 if(FAILED(hr
)) return hr
;
607 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
608 wrapper
= WrapDropTarget( hwnd
);
611 IStream_Release(stream
);
612 return E_OUTOFMEMORY
;
614 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
615 IDropTarget_Release(wrapper
);
619 hr
= create_map_from_stream(stream
, &map
);
622 IDropTarget_AddRef(pDropTarget
);
623 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
624 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
630 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
631 CoReleaseMarshalData(stream
);
634 IStream_Release(stream
);
639 /***********************************************************************
640 * RevokeDragDrop (OLE32.@)
642 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
646 IDropTarget
*drop_target
;
649 TRACE("(%p)\n", hwnd
);
653 ERR("invalid hwnd %p\n", hwnd
);
654 return DRAGDROP_E_INVALIDHWND
;
657 /* no registration data */
658 if (!(map
= get_droptarget_handle(hwnd
)))
659 return DRAGDROP_E_NOTREGISTERED
;
661 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
662 if(drop_target
) IDropTarget_Release(drop_target
);
664 RemovePropW(hwnd
, prop_oledroptarget
);
665 RemovePropW(hwnd
, prop_marshalleddroptarget
);
667 hr
= create_stream_from_map(map
, &stream
);
670 CoReleaseMarshalData(stream
);
671 IStream_Release(stream
);
678 /***********************************************************************
679 * OleRegGetUserType (OLE32.@)
681 HRESULT WINAPI
OleRegGetUserType(REFCLSID clsid
, DWORD form
, LPOLESTR
*usertype
)
683 static const WCHAR auxusertypeW
[] = {'A','u','x','U','s','e','r','T','y','p','e','\\','%','d',0};
684 DWORD valuetype
, valuelen
;
685 WCHAR auxkeynameW
[16];
690 TRACE("(%s, %u, %p)\n", debugstr_guid(clsid
), form
, usertype
);
697 /* Return immediately if it's not registered. */
698 hres
= COM_OpenKeyForCLSID(clsid
, NULL
, KEY_READ
, &usertypekey
);
704 /* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
705 if (form
!= USERCLASSTYPE_FULL
)
709 sprintfW(auxkeynameW
, auxusertypeW
, form
);
710 if (COM_OpenKeyForCLSID(clsid
, auxkeynameW
, KEY_READ
, &auxkey
) == S_OK
)
712 if (!RegQueryValueExW(auxkey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
) && valuelen
)
714 RegCloseKey(usertypekey
);
715 usertypekey
= auxkey
;
723 if (RegQueryValueExW(usertypekey
, emptyW
, NULL
, &valuetype
, NULL
, &valuelen
))
725 RegCloseKey(usertypekey
);
726 return REGDB_E_READREGDB
;
729 *usertype
= CoTaskMemAlloc(valuelen
);
732 RegCloseKey(usertypekey
);
733 return E_OUTOFMEMORY
;
736 ret
= RegQueryValueExW(usertypekey
,
742 RegCloseKey(usertypekey
);
743 if (ret
!= ERROR_SUCCESS
)
745 CoTaskMemFree(*usertype
);
747 return REGDB_E_READREGDB
;
753 /***********************************************************************
754 * DoDragDrop [OLE32.@]
756 HRESULT WINAPI
DoDragDrop (
757 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
758 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
759 DWORD dwOKEffect
, /* [in] effects allowed by the source */
760 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
762 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
763 TrackerWindowInfo trackerInfo
;
764 HWND hwndTrackWindow
;
767 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
769 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
773 * Setup the drag n drop tracking window.
776 trackerInfo
.dataObject
= pDataObject
;
777 trackerInfo
.dropSource
= pDropSource
;
778 trackerInfo
.dwOKEffect
= dwOKEffect
;
779 trackerInfo
.pdwEffect
= pdwEffect
;
780 trackerInfo
.trackingDone
= FALSE
;
781 trackerInfo
.escPressed
= FALSE
;
782 trackerInfo
.curTargetHWND
= 0;
783 trackerInfo
.curDragTarget
= 0;
785 trackerInfo
.accepterHWND
= NULL
;
788 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
789 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
790 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
796 * Capture the mouse input
798 SetCapture(hwndTrackWindow
);
803 * Pump messages. All mouse input should go to the capture window.
805 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
807 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
808 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
809 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
811 if ( (msg
.message
>= WM_KEYFIRST
) &&
812 (msg
.message
<= WM_KEYLAST
) )
815 * When keyboard messages are sent to windows on this thread, we
816 * want to ignore notify the drop source that the state changed.
817 * in the case of the Escape key, we also notify the drop source
818 * we give it a special meaning.
820 if ( (msg
.message
==WM_KEYDOWN
) &&
821 (msg
.wParam
==VK_ESCAPE
) )
823 trackerInfo
.escPressed
= TRUE
;
827 * Notify the drop source.
829 OLEDD_TrackStateChange(&trackerInfo
);
834 * Dispatch the messages only when it's not a keyboard message.
836 DispatchMessageW(&msg
);
840 /* re-post the quit message to outer message loop */
841 if (msg
.message
== WM_QUIT
)
842 PostQuitMessage(msg
.wParam
);
844 * Destroy the temporary window.
846 DestroyWindow(hwndTrackWindow
);
848 return trackerInfo
.returnValue
;
854 /***********************************************************************
855 * OleQueryLinkFromData [OLE32.@]
857 HRESULT WINAPI
OleQueryLinkFromData(
858 IDataObject
* pSrcDataObject
)
860 FIXME("(%p),stub!\n", pSrcDataObject
);
864 /***********************************************************************
865 * OleRegGetMiscStatus [OLE32.@]
867 HRESULT WINAPI
OleRegGetMiscStatus(
872 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
873 static const WCHAR dfmtW
[] = {'%','d',0};
880 TRACE("(%s, %d, %p)\n", debugstr_guid(clsid
), dwAspect
, pdwStatus
);
882 if (!pdwStatus
) return E_INVALIDARG
;
886 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
888 hr
= COM_OpenKeyForCLSID(clsid
, miscstatusW
, KEY_READ
, &miscStatusKey
);
890 /* missing key is not a failure */
891 return hr
== REGDB_E_KEYMISSING
? S_OK
: hr
;
893 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
896 * Open the key specific to the requested aspect.
898 sprintfW(keyName
, dfmtW
, dwAspect
);
900 result
= open_classes_key(miscStatusKey
, keyName
, KEY_READ
, &aspectKey
);
901 if (result
== ERROR_SUCCESS
)
903 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
904 RegCloseKey(aspectKey
);
907 RegCloseKey(miscStatusKey
);
911 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
915 IEnumOLEVERB IEnumOLEVERB_iface
;
922 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
924 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
927 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
928 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
930 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
931 if (IsEqualIID(riid
, &IID_IUnknown
) ||
932 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
934 IEnumOLEVERB_AddRef(iface
);
938 return E_NOINTERFACE
;
941 static ULONG WINAPI
EnumOLEVERB_AddRef(
944 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
946 return InterlockedIncrement(&This
->ref
);
949 static ULONG WINAPI
EnumOLEVERB_Release(
952 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
953 LONG refs
= InterlockedDecrement(&This
->ref
);
957 RegCloseKey(This
->hkeyVerb
);
958 HeapFree(GetProcessHeap(), 0, This
);
963 static HRESULT WINAPI
EnumOLEVERB_Next(
964 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
967 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
970 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
975 for (; celt
; celt
--, rgelt
++)
980 LPWSTR pwszMenuFlags
;
982 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, ARRAY_SIZE(wszSubKey
));
983 if (res
== ERROR_NO_MORE_ITEMS
)
988 else if (res
!= ERROR_SUCCESS
)
990 ERR("RegEnumKeyW failed with error %d\n", res
);
991 hr
= REGDB_E_READREGDB
;
994 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
995 if (res
!= ERROR_SUCCESS
)
997 ERR("RegQueryValueW failed with error %d\n", res
);
998 hr
= REGDB_E_READREGDB
;
1001 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
1007 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
1008 if (res
!= ERROR_SUCCESS
)
1010 ERR("RegQueryValueW failed with error %d\n", res
);
1011 hr
= REGDB_E_READREGDB
;
1012 CoTaskMemFree(pwszOLEVERB
);
1016 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
1017 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
1020 hr
= OLEOBJ_E_INVALIDVERB
;
1021 CoTaskMemFree(pwszOLEVERB
);
1024 /* nul terminate the name string and advance to first character */
1025 *pwszMenuFlags
= '\0';
1027 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
1030 hr
= OLEOBJ_E_INVALIDVERB
;
1031 CoTaskMemFree(pwszOLEVERB
);
1034 /* nul terminate the menu string and advance to first character */
1035 *pwszAttribs
= '\0';
1038 /* fill out structure for this verb */
1039 rgelt
->lVerb
= atolW(wszSubKey
);
1040 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1041 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
1042 rgelt
->grfAttribs
= atolW(pwszAttribs
);
1051 static HRESULT WINAPI
EnumOLEVERB_Skip(
1052 IEnumOLEVERB
*iface
, ULONG celt
)
1054 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1056 TRACE("(%d)\n", celt
);
1058 This
->index
+= celt
;
1062 static HRESULT WINAPI
EnumOLEVERB_Reset(
1063 IEnumOLEVERB
*iface
)
1065 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1073 static HRESULT WINAPI
EnumOLEVERB_Clone(
1074 IEnumOLEVERB
*iface
,
1075 IEnumOLEVERB
**ppenum
)
1077 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1079 TRACE("(%p)\n", ppenum
);
1080 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1081 return HRESULT_FROM_WIN32(GetLastError());
1082 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1085 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1087 EnumOLEVERB_QueryInterface
,
1089 EnumOLEVERB_Release
,
1096 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1098 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1101 RegCloseKey(hkeyVerb
);
1102 return E_OUTOFMEMORY
;
1104 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1106 This
->index
= index
;
1107 This
->hkeyVerb
= hkeyVerb
;
1108 *ppenum
= &This
->IEnumOLEVERB_iface
;
1112 /***********************************************************************
1113 * OleRegEnumVerbs [OLE32.@]
1115 * Enumerates verbs associated with a class stored in the registry.
1118 * clsid [I] Class ID to enumerate the verbs for.
1119 * ppenum [O] Enumerator.
1123 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1124 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1125 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1126 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1128 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1133 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1135 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1137 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1140 if (res
== REGDB_E_CLASSNOTREG
)
1141 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1142 else if (res
== REGDB_E_KEYMISSING
)
1143 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1145 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1146 debugstr_guid(clsid
), res
);
1150 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1151 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1152 if (res
!= ERROR_SUCCESS
)
1154 ERR("failed to get subkey count with error %d\n", GetLastError());
1155 return REGDB_E_READREGDB
;
1160 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1161 RegCloseKey(hkeyVerb
);
1162 return OLEOBJ_E_NOVERBS
;
1165 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1168 /******************************************************************************
1169 * OleSetContainedObject [OLE32.@]
1171 HRESULT WINAPI
OleSetContainedObject(
1175 IRunnableObject
* runnable
= NULL
;
1178 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1180 hres
= IUnknown_QueryInterface(pUnknown
,
1181 &IID_IRunnableObject
,
1184 if (SUCCEEDED(hres
))
1186 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1188 IRunnableObject_Release(runnable
);
1196 /******************************************************************************
1199 * Set the OLE object to the running state.
1202 * pUnknown [I] OLE object to run.
1206 * Failure: Any HRESULT code.
1208 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1210 IRunnableObject
*runable
;
1213 TRACE("(%p)\n", pUnknown
);
1215 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1217 return S_OK
; /* Appears to return no error. */
1219 hres
= IRunnableObject_Run(runable
, NULL
);
1220 IRunnableObject_Release(runable
);
1224 /******************************************************************************
1227 HRESULT WINAPI
OleLoad(
1230 LPOLECLIENTSITE pClientSite
,
1233 IPersistStorage
* persistStorage
= NULL
;
1235 IOleObject
* pOleObject
= NULL
;
1236 STATSTG storageInfo
;
1239 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1244 * TODO, Conversion ... OleDoAutoConvert
1248 * Get the class ID for the object.
1250 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1255 * Now, try and create the handler for the object
1257 hres
= CoCreateInstance(&storageInfo
.clsid
,
1259 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1264 * If that fails, as it will most times, load the default
1269 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1276 * If we couldn't find a handler... this is bad. Abort the whole thing.
1283 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1284 if (SUCCEEDED(hres
))
1287 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1292 * Initialize the object with its IPersistStorage interface.
1294 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1295 if (SUCCEEDED(hres
))
1297 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1299 IPersistStorage_Release(persistStorage
);
1300 persistStorage
= NULL
;
1303 if (SUCCEEDED(hres
) && pClientSite
)
1305 * Inform the new object of its client site.
1307 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1310 * Cleanup interfaces used internally
1313 IOleObject_Release(pOleObject
);
1315 if (SUCCEEDED(hres
))
1319 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1320 if (SUCCEEDED(hres1
))
1322 FIXME("handle OLE link\n");
1323 IOleLink_Release(pOleLink
);
1329 IUnknown_Release(pUnk
);
1338 /***********************************************************************
1341 HRESULT WINAPI
OleSave(
1342 LPPERSISTSTORAGE pPS
,
1349 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1352 * First, we transfer the class ID (if available)
1354 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1356 if (SUCCEEDED(hres
))
1358 WriteClassStg(pStg
, &objectClass
);
1362 * Then, we ask the object to save itself to the
1363 * storage. If it is successful, we commit the storage.
1365 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1367 if (SUCCEEDED(hres
))
1369 IStorage_Commit(pStg
,
1377 /******************************************************************************
1378 * OleLockRunning [OLE32.@]
1380 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1382 IRunnableObject
* runnable
= NULL
;
1385 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1387 hres
= IUnknown_QueryInterface(pUnknown
,
1388 &IID_IRunnableObject
,
1391 if (SUCCEEDED(hres
))
1393 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1395 IRunnableObject_Release(runnable
);
1404 /**************************************************************************
1405 * Internal methods to manage the shared OLE menu in response to the
1406 * OLE***MenuDescriptor API
1410 * OLEMenu_Initialize()
1412 * Initializes the OLEMENU data structures.
1414 static void OLEMenu_Initialize(void)
1419 * OLEMenu_UnInitialize()
1421 * Releases the OLEMENU data structures.
1423 static void OLEMenu_UnInitialize(void)
1427 /*************************************************************************
1428 * OLEMenu_InstallHooks
1429 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1431 * RETURNS: TRUE if message hooks were successfully installed
1434 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1436 OleMenuHookItem
*pHookItem
;
1438 /* Create an entry for the hook table */
1439 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1440 sizeof(OleMenuHookItem
)) ) )
1443 pHookItem
->tid
= tid
;
1444 pHookItem
->hHeap
= GetProcessHeap();
1445 pHookItem
->CallWndProc_hHook
= NULL
;
1447 /* Install a thread scope message hook for WH_GETMESSAGE */
1448 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1449 0, GetCurrentThreadId() );
1450 if ( !pHookItem
->GetMsg_hHook
)
1453 /* Install a thread scope message hook for WH_CALLWNDPROC */
1454 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1455 0, GetCurrentThreadId() );
1456 if ( !pHookItem
->CallWndProc_hHook
)
1459 /* Insert the hook table entry */
1460 pHookItem
->next
= hook_list
;
1461 hook_list
= pHookItem
;
1466 /* Unhook any hooks */
1467 if ( pHookItem
->GetMsg_hHook
)
1468 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1469 if ( pHookItem
->CallWndProc_hHook
)
1470 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1471 /* Release the hook table entry */
1472 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1477 /*************************************************************************
1478 * OLEMenu_UnInstallHooks
1479 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1481 * RETURNS: TRUE if message hooks were successfully installed
1484 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1486 OleMenuHookItem
*pHookItem
= NULL
;
1487 OleMenuHookItem
**ppHook
= &hook_list
;
1491 if ((*ppHook
)->tid
== tid
)
1493 pHookItem
= *ppHook
;
1494 *ppHook
= pHookItem
->next
;
1497 ppHook
= &(*ppHook
)->next
;
1499 if (!pHookItem
) return FALSE
;
1501 /* Uninstall the hooks installed for this thread */
1502 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1504 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1507 /* Release the hook table entry */
1508 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1513 /* Release the hook table entry */
1514 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1519 /*************************************************************************
1520 * OLEMenu_IsHookInstalled
1521 * Tests if OLEMenu hooks have been installed for a thread
1523 * RETURNS: The pointer and index of the hook table entry for the tid
1524 * NULL and -1 for the index if no hooks were installed for this thread
1526 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1528 OleMenuHookItem
*pHookItem
;
1530 /* Do a simple linear search for an entry whose tid matches ours.
1531 * We really need a map but efficiency is not a concern here. */
1532 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1534 if ( tid
== pHookItem
->tid
)
1541 /***********************************************************************
1542 * OLEMenu_FindMainMenuIndex
1544 * Used by OLEMenu API to find the top level group a menu item belongs to.
1545 * On success pnPos contains the index of the item in the top level menu group
1547 * RETURNS: TRUE if the ID was found, FALSE on failure
1549 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1553 nItems
= GetMenuItemCount( hMainMenu
);
1555 for (i
= 0; i
< nItems
; i
++)
1559 /* Is the current item a submenu? */
1560 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1562 /* If the handle is the same we're done */
1563 if ( hsubmenu
== hPopupMenu
)
1569 /* Recursively search without updating pnPos */
1570 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1582 /***********************************************************************
1583 * OLEMenu_SetIsServerMenu
1585 * Checks whether a popup menu belongs to a shared menu group which is
1586 * owned by the server, and sets the menu descriptor state accordingly.
1587 * All menu messages from these groups should be routed to the server.
1589 * RETURNS: TRUE if the popup menu is part of a server owned group
1590 * FALSE if the popup menu is part of a container owned group
1592 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1594 UINT nPos
= 0, nWidth
, i
;
1596 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1598 /* Don't bother searching if the popup is the combined menu itself */
1599 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1602 /* Find the menu item index in the shared OLE menu that this item belongs to */
1603 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1606 /* The group widths array has counts for the number of elements
1607 * in the groups File, Edit, Container, Object, Window, Help.
1608 * The Edit, Object & Help groups belong to the server object
1609 * and the other three belong to the container.
1610 * Loop through the group widths and locate the group we are a member of.
1612 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1614 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1615 if ( nPos
< nWidth
)
1617 /* Odd elements are server menu widths */
1618 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1623 return pOleMenuDescriptor
->bIsServerItem
;
1626 /*************************************************************************
1627 * OLEMenu_CallWndProc
1628 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1629 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1631 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1634 HOLEMENU hOleMenu
= 0;
1635 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1636 OleMenuHookItem
*pHookItem
= NULL
;
1639 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1641 /* Check if we're being asked to process the message */
1642 if ( HC_ACTION
!= code
)
1645 /* Retrieve the current message being dispatched from lParam */
1646 pMsg
= (LPCWPSTRUCT
)lParam
;
1648 /* Check if the message is destined for a window we are interested in:
1649 * If the window has an OLEMenu property we may need to dispatch
1650 * the menu message to its active objects window instead. */
1652 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1656 /* Get the menu descriptor */
1657 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1658 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1661 /* Process menu messages */
1662 switch( pMsg
->message
)
1666 /* Reset the menu descriptor state */
1667 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1669 /* Send this message to the server as well */
1670 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1671 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1675 case WM_INITMENUPOPUP
:
1677 /* Save the state for whether this is a server owned menu */
1678 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1684 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1685 if ( fuFlags
& MF_SYSMENU
)
1688 /* Save the state for whether this is a server owned popup menu */
1689 else if ( fuFlags
& MF_POPUP
)
1690 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1697 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1698 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1699 goto NEXTHOOK
; /* Not a menu message */
1708 /* If the message was for the server dispatch it accordingly */
1709 if ( pOleMenuDescriptor
->bIsServerItem
)
1711 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1712 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1716 if ( pOleMenuDescriptor
)
1717 GlobalUnlock( hOleMenu
);
1719 /* Lookup the hook item for the current thread */
1720 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1722 /* This should never fail!! */
1723 WARN("could not retrieve hHook for current thread!\n" );
1727 /* Pass on the message to the next hooker */
1728 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1731 /*************************************************************************
1732 * OLEMenu_GetMsgProc
1733 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1734 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1736 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1739 HOLEMENU hOleMenu
= 0;
1740 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1741 OleMenuHookItem
*pHookItem
= NULL
;
1744 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1746 /* Check if we're being asked to process a messages */
1747 if ( HC_ACTION
!= code
)
1750 /* Retrieve the current message being dispatched from lParam */
1751 pMsg
= (LPMSG
)lParam
;
1753 /* Check if the message is destined for a window we are interested in:
1754 * If the window has an OLEMenu property we may need to dispatch
1755 * the menu message to its active objects window instead. */
1757 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1761 /* Process menu messages */
1762 switch( pMsg
->message
)
1766 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1768 goto NEXTHOOK
; /* Not a menu message */
1775 /* Get the menu descriptor */
1776 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1777 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1780 /* If the message was for the server dispatch it accordingly */
1781 if ( pOleMenuDescriptor
->bIsServerItem
)
1783 /* Change the hWnd in the message to the active objects hWnd.
1784 * The message loop which reads this message will automatically
1785 * dispatch it to the embedded objects window. */
1786 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1790 if ( pOleMenuDescriptor
)
1791 GlobalUnlock( hOleMenu
);
1793 /* Lookup the hook item for the current thread */
1794 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1796 /* This should never fail!! */
1797 WARN("could not retrieve hHook for current thread!\n" );
1801 /* Pass on the message to the next hooker */
1802 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1805 /***********************************************************************
1806 * OleCreateMenuDescriptor [OLE32.@]
1807 * Creates an OLE menu descriptor for OLE to use when dispatching
1808 * menu messages and commands.
1811 * hmenuCombined - Handle to the objects combined menu
1812 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1815 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1816 HMENU hmenuCombined
,
1817 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1820 OleMenuDescriptor
*pOleMenuDescriptor
;
1823 if ( !hmenuCombined
|| !lpMenuWidths
)
1826 /* Create an OLE menu descriptor */
1827 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1828 sizeof(OleMenuDescriptor
) ) ) )
1831 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1832 if ( !pOleMenuDescriptor
)
1835 /* Initialize menu group widths and hmenu */
1836 for ( i
= 0; i
< 6; i
++ )
1837 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1839 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1840 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1841 GlobalUnlock( hOleMenu
);
1846 /***********************************************************************
1847 * OleDestroyMenuDescriptor [OLE32.@]
1848 * Destroy the shared menu descriptor
1850 HRESULT WINAPI
OleDestroyMenuDescriptor(
1851 HOLEMENU hmenuDescriptor
)
1853 if ( hmenuDescriptor
)
1854 GlobalFree( hmenuDescriptor
);
1858 /***********************************************************************
1859 * OleSetMenuDescriptor [OLE32.@]
1860 * Installs or removes OLE dispatching code for the containers frame window.
1863 * hOleMenu Handle to composite menu descriptor
1864 * hwndFrame Handle to containers frame window
1865 * hwndActiveObject Handle to objects in-place activation window
1866 * lpFrame Pointer to IOleInPlaceFrame on containers window
1867 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1870 * S_OK - menu installed correctly
1871 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1874 * The lpFrame and lpActiveObject parameters are currently ignored
1875 * OLE should install context sensitive help F1 filtering for the app when
1876 * these are non null.
1878 HRESULT WINAPI
OleSetMenuDescriptor(
1881 HWND hwndActiveObject
,
1882 LPOLEINPLACEFRAME lpFrame
,
1883 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1885 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1888 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1889 return E_INVALIDARG
;
1891 if ( lpFrame
|| lpActiveObject
)
1893 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1901 /* Set up a message hook to intercept the containers frame window messages.
1902 * The message filter is responsible for dispatching menu messages from the
1903 * shared menu which are intended for the object.
1906 if ( hOleMenu
) /* Want to install dispatching code */
1908 /* If OLEMenu hooks are already installed for this thread, fail
1909 * Note: This effectively means that OleSetMenuDescriptor cannot
1910 * be called twice in succession on the same frame window
1911 * without first calling it with a null hOleMenu to uninstall
1913 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1916 /* Get the menu descriptor */
1917 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1918 if ( !pOleMenuDescriptor
)
1919 return E_UNEXPECTED
;
1921 /* Update the menu descriptor */
1922 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1923 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1925 GlobalUnlock( hOleMenu
);
1926 pOleMenuDescriptor
= NULL
;
1928 /* Add a menu descriptor windows property to the frame window */
1929 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1931 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1932 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1935 else /* Want to uninstall dispatching code */
1937 /* Uninstall the hooks */
1938 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1941 /* Remove the menu descriptor property from the frame window */
1942 RemovePropW( hwndFrame
, prop_olemenuW
);
1948 /******************************************************************************
1949 * IsAccelerator [OLE32.@]
1950 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1952 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1957 if(!lpMsg
) return FALSE
;
1960 WARN_(accel
)("NULL accel handle\n");
1963 if((lpMsg
->message
!= WM_KEYDOWN
&&
1964 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1965 lpMsg
->message
!= WM_SYSCHAR
&&
1966 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1967 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1968 if (NULL
== lpAccelTbl
)
1972 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1974 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1975 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1979 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1980 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1981 hAccel
, cAccelEntries
,
1982 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1983 for(i
= 0; i
< cAccelEntries
; i
++)
1985 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1988 if(lpMsg
->message
== WM_CHAR
)
1990 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1992 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1998 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
2001 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
2002 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
2003 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
2004 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
2005 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
2006 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
2007 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
2011 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2013 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2014 { /* ^^ ALT pressed */
2015 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2023 WARN_(accel
)("couldn't translate accelerator key\n");
2024 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2028 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2029 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2033 /***********************************************************************
2034 * ReleaseStgMedium [OLE32.@]
2036 void WINAPI
ReleaseStgMedium(
2039 switch (pmedium
->tymed
)
2043 if ( (pmedium
->pUnkForRelease
==0) &&
2044 (pmedium
->u
.hGlobal
!=0) )
2045 GlobalFree(pmedium
->u
.hGlobal
);
2050 if (pmedium
->u
.lpszFileName
!=0)
2052 if (pmedium
->pUnkForRelease
==0)
2054 DeleteFileW(pmedium
->u
.lpszFileName
);
2057 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2063 if (pmedium
->u
.pstm
!=0)
2065 IStream_Release(pmedium
->u
.pstm
);
2069 case TYMED_ISTORAGE
:
2071 if (pmedium
->u
.pstg
!=0)
2073 IStorage_Release(pmedium
->u
.pstg
);
2079 if ( (pmedium
->pUnkForRelease
==0) &&
2080 (pmedium
->u
.hBitmap
!=0) )
2081 DeleteObject(pmedium
->u
.hBitmap
);
2086 if ( (pmedium
->pUnkForRelease
==0) &&
2087 (pmedium
->u
.hMetaFilePict
!=0) )
2089 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2090 DeleteMetaFile(pMP
->hMF
);
2091 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2092 GlobalFree(pmedium
->u
.hMetaFilePict
);
2098 if ( (pmedium
->pUnkForRelease
==0) &&
2099 (pmedium
->u
.hEnhMetaFile
!=0) )
2101 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2109 pmedium
->tymed
=TYMED_NULL
;
2112 * After cleaning up, the unknown is released
2114 if (pmedium
->pUnkForRelease
!=0)
2116 IUnknown_Release(pmedium
->pUnkForRelease
);
2117 pmedium
->pUnkForRelease
= 0;
2122 * OLEDD_Initialize()
2124 * Initializes the OLE drag and drop data structures.
2126 static void OLEDD_Initialize(void)
2130 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2131 wndClass
.style
= CS_GLOBALCLASS
;
2132 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2133 wndClass
.cbClsExtra
= 0;
2134 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2135 wndClass
.hCursor
= 0;
2136 wndClass
.hbrBackground
= 0;
2137 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2139 RegisterClassW (&wndClass
);
2143 * OLEDD_DragTrackerWindowProc()
2145 * This method is the WindowProcedure of the drag n drop tracking
2146 * window. During a drag n Drop operation, an invisible window is created
2147 * to receive the user input and act upon it. This procedure is in charge
2151 #define DRAG_TIMER_ID 1
2153 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2163 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2165 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2166 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2175 case WM_LBUTTONDOWN
:
2176 case WM_MBUTTONDOWN
:
2177 case WM_RBUTTONDOWN
:
2179 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2180 if (trackerInfo
->trackingDone
) break;
2181 OLEDD_TrackStateChange(trackerInfo
);
2186 KillTimer(hwnd
, DRAG_TIMER_ID
);
2192 * This is a window proc after all. Let's call the default.
2194 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2198 static HRESULT WINAPI
DefaultDragEnter(HWND hwndTarget
,
2199 IDataObject
* pDataObj
,
2207 ZeroMemory(&fme
, sizeof(fme
));
2208 fme
.cfFormat
= CF_HDROP
;
2210 fme
.dwAspect
= DVASPECT_CONTENT
;
2212 fme
.tymed
= TYMED_HGLOBAL
;
2213 hr
= pDataObj
->lpVtbl
->QueryGetData(pDataObj
, &fme
);
2215 *pdwEffect
= SUCCEEDED(hr
) ? DROPEFFECT_COPY
: DROPEFFECT_NONE
;
2217 if (*pdwEffect
== DROPEFFECT_NONE
)
2218 return DRAGDROP_S_CANCEL
;
2223 static HRESULT WINAPI
DefaultDrop(HWND hwndAccepter
,
2224 IDataObject
* pDataObj
,
2232 HGLOBAL hGlobal
= NULL
;
2234 ZeroMemory(&fme
, sizeof(fme
));
2235 fme
.cfFormat
= CF_HDROP
;
2237 fme
.dwAspect
= DVASPECT_CONTENT
;
2239 fme
.tymed
= TYMED_HGLOBAL
;
2240 hr
= pDataObj
->lpVtbl
->QueryGetData(pDataObj
, &fme
);
2244 ZeroMemory(&stgm
, sizeof(stgm
));
2245 hr
= pDataObj
->lpVtbl
->GetData(pDataObj
, &fme
, &stgm
);
2248 hGlobal
= stgm
.DUMMYUNIONNAME
.hGlobal
;
2251 if (IsWindowUnicode(hwndAccepter
))
2252 PostMessageW(hwndAccepter
, WM_DROPFILES
, (WPARAM
)hGlobal
, 0);
2254 PostMessageA(hwndAccepter
, WM_DROPFILES
, (WPARAM
)hGlobal
, 0);
2256 ReleaseStgMedium(&stgm
);
2263 static void drag_enter( TrackerWindowInfo
*info
, HWND new_target
)
2267 DWORD dwEffect
= *info
->pdwEffect
;
2270 info
->curTargetHWND
= new_target
;
2273 info
->accepterHWND
= NULL
;
2274 while (new_target
&& !is_droptarget( new_target
))
2276 if (is_acceptfiles(new_target
))
2278 dwEffect
= info
->dwOKEffect
;
2279 hr
= DefaultDragEnter(new_target
, info
->dataObject
,
2280 info
->dwKeyState
, info
->curMousePos
,
2282 dwEffect
&= info
->dwOKEffect
;
2286 info
->accepterHWND
= new_target
;
2287 info
->curDragTarget
= NULL
;
2288 *info
->pdwEffect
= dwEffect
;
2292 new_target
= GetParent( new_target
);
2295 while (new_target
&& !is_droptarget( new_target
))
2296 new_target
= GetParent( new_target
);
2299 info
->curDragTarget
= get_droptarget_pointer( new_target
);
2301 if (info
->curDragTarget
)
2303 *info
->pdwEffect
= info
->dwOKEffect
;
2304 hr
= IDropTarget_DragEnter( info
->curDragTarget
, info
->dataObject
,
2305 info
->dwKeyState
, info
->curMousePos
,
2307 *info
->pdwEffect
&= info
->dwOKEffect
;
2309 /* failed DragEnter() means invalid target */
2312 IDropTarget_Release( info
->curDragTarget
);
2313 info
->curDragTarget
= NULL
;
2314 info
->curTargetHWND
= NULL
;
2316 info
->accepterHWND
= NULL
;
2322 static void drag_end( TrackerWindowInfo
*info
)
2326 info
->trackingDone
= TRUE
;
2329 if (info
->curDragTarget
)
2331 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2332 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2334 *info
->pdwEffect
= info
->dwOKEffect
;
2335 hr
= IDropTarget_Drop( info
->curDragTarget
, info
->dataObject
, info
->dwKeyState
,
2336 info
->curMousePos
, info
->pdwEffect
);
2337 *info
->pdwEffect
&= info
->dwOKEffect
;
2340 info
->returnValue
= hr
;
2344 IDropTarget_DragLeave( info
->curDragTarget
);
2345 *info
->pdwEffect
= DROPEFFECT_NONE
;
2347 IDropTarget_Release( info
->curDragTarget
);
2348 info
->curDragTarget
= NULL
;
2351 else if (info
->accepterHWND
)
2353 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2354 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2356 *info
->pdwEffect
= info
->dwOKEffect
;
2357 hr
= DefaultDrop(info
->accepterHWND
, info
->dataObject
, info
->dwKeyState
,
2358 info
->curMousePos
, info
->pdwEffect
);
2359 *info
->pdwEffect
&= info
->dwOKEffect
;
2362 info
->returnValue
= hr
;
2366 *info
->pdwEffect
= DROPEFFECT_NONE
;
2368 info
->accepterHWND
= NULL
;
2372 *info
->pdwEffect
= DROPEFFECT_NONE
;
2375 static HRESULT
give_feedback( TrackerWindowInfo
*info
)
2382 if (info
->curDragTarget
== NULL
&& info
->accepterHWND
== NULL
)
2383 *info
->pdwEffect
= DROPEFFECT_NONE
;
2385 if (info
->curDragTarget
== NULL
)
2386 *info
->pdwEffect
= DROPEFFECT_NONE
;
2389 hr
= IDropSource_GiveFeedback( info
->dropSource
, *info
->pdwEffect
);
2391 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2393 if (*info
->pdwEffect
& DROPEFFECT_MOVE
)
2395 else if (*info
->pdwEffect
& DROPEFFECT_COPY
)
2397 else if (*info
->pdwEffect
& DROPEFFECT_LINK
)
2400 res
= CURSOR_NODROP
;
2402 cur
= LoadCursorW( hProxyDll
, MAKEINTRESOURCEW( res
) );
2410 * OLEDD_TrackStateChange()
2412 * This method is invoked while a drag and drop operation is in effect.
2415 * trackerInfo - Pointer to the structure identifying the
2416 * drag & drop operation that is currently
2419 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2421 HWND hwndNewTarget
= 0;
2425 * Get the handle of the window under the mouse
2427 pt
.x
= trackerInfo
->curMousePos
.x
;
2428 pt
.y
= trackerInfo
->curMousePos
.y
;
2429 hwndNewTarget
= WindowFromPoint(pt
);
2431 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2432 trackerInfo
->escPressed
,
2433 trackerInfo
->dwKeyState
);
2435 if (trackerInfo
->curTargetHWND
!= hwndNewTarget
&&
2436 (trackerInfo
->returnValue
== S_OK
||
2437 trackerInfo
->returnValue
== DRAGDROP_S_DROP
))
2439 if (trackerInfo
->curDragTarget
)
2441 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2442 IDropTarget_Release(trackerInfo
->curDragTarget
);
2443 trackerInfo
->curDragTarget
= NULL
;
2444 trackerInfo
->curTargetHWND
= NULL
;
2447 trackerInfo
->accepterHWND
= NULL
;
2451 drag_enter( trackerInfo
, hwndNewTarget
);
2453 give_feedback( trackerInfo
);
2457 if (trackerInfo
->returnValue
== S_OK
)
2459 if (trackerInfo
->curDragTarget
)
2461 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2462 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2463 trackerInfo
->dwKeyState
,
2464 trackerInfo
->curMousePos
,
2465 trackerInfo
->pdwEffect
);
2466 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2469 else if (trackerInfo
->accepterHWND
)
2471 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2474 give_feedback( trackerInfo
);
2477 drag_end( trackerInfo
);
2481 * OLEDD_GetButtonState()
2483 * This method will use the current state of the keyboard to build
2484 * a button state mask equivalent to the one passed in the
2485 * WM_MOUSEMOVE wParam.
2487 static DWORD
OLEDD_GetButtonState(void)
2489 BYTE keyboardState
[256];
2492 GetKeyboardState(keyboardState
);
2494 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2495 keyMask
|= MK_SHIFT
;
2497 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2498 keyMask
|= MK_CONTROL
;
2500 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2503 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2504 keyMask
|= MK_LBUTTON
;
2506 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2507 keyMask
|= MK_RBUTTON
;
2509 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2510 keyMask
|= MK_MBUTTON
;
2516 * OLEDD_GetButtonState()
2518 * This method will read the default value of the registry key in
2519 * parameter and extract a DWORD value from it. The registry key value
2520 * can be in a string key or a DWORD key.
2523 * regKey - Key to read the default value from
2524 * pdwValue - Pointer to the location where the DWORD
2525 * value is returned. This value is not modified
2526 * if the value is not found.
2529 static void OLEUTL_ReadRegistryDWORDValue(
2534 DWORD cbData
= sizeof(buffer
);
2538 lres
= RegQueryValueExW(regKey
,
2545 if (lres
==ERROR_SUCCESS
)
2550 *pdwValue
= *(DWORD
*)buffer
;
2555 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2561 /******************************************************************************
2564 * The operation of this function is documented literally in the WinAPI
2565 * documentation to involve a QueryInterface for the IViewObject interface,
2566 * followed by a call to IViewObject::Draw.
2568 HRESULT WINAPI
OleDraw(
2575 IViewObject
*viewobject
;
2577 if (!pUnk
) return E_INVALIDARG
;
2579 hres
= IUnknown_QueryInterface(pUnk
,
2581 (void**)&viewobject
);
2582 if (SUCCEEDED(hres
))
2584 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2585 IViewObject_Release(viewobject
);
2589 return DV_E_NOIVIEWOBJECT
;
2592 /***********************************************************************
2593 * OleTranslateAccelerator [OLE32.@]
2595 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2596 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2600 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2602 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2603 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2608 /******************************************************************************
2609 * OleCreate [OLE32.@]
2612 HRESULT WINAPI
OleCreate(
2616 LPFORMATETC pFormatEtc
,
2617 LPOLECLIENTSITE pClientSite
,
2622 IUnknown
* pUnk
= NULL
;
2623 IOleObject
*pOleObject
= NULL
;
2625 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2626 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2628 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2630 if (SUCCEEDED(hres
))
2631 hres
= IStorage_SetClass(pStg
, rclsid
);
2633 if (pClientSite
&& SUCCEEDED(hres
))
2635 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2636 if (SUCCEEDED(hres
))
2639 IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2643 if (SUCCEEDED(hres
))
2645 IPersistStorage
* pPS
;
2646 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2648 TRACE("trying to set stg %p\n", pStg
);
2649 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2650 TRACE("-- result 0x%08x\n", hres
);
2651 IPersistStorage_Release(pPS
);
2655 if (pClientSite
&& SUCCEEDED(hres
))
2657 TRACE("trying to set clientsite %p\n", pClientSite
);
2658 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2659 TRACE("-- result 0x%08x\n", hres
);
2663 IOleObject_Release(pOleObject
);
2665 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2668 hres
= OleRun(pUnk
);
2669 if (SUCCEEDED(hres
))
2671 IOleCache
*pOleCache
;
2673 if (SUCCEEDED(IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
)))
2676 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2680 pfe
.dwAspect
= DVASPECT_CONTENT
;
2682 pfe
.tymed
= TYMED_NULL
;
2683 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2686 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2687 IOleCache_Release(pOleCache
);
2692 if (FAILED(hres
) && pUnk
)
2694 IUnknown_Release(pUnk
);
2700 TRACE("-- %p\n", pUnk
);
2704 /******************************************************************************
2705 * OleGetAutoConvert [OLE32.@]
2707 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2709 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2711 WCHAR buf
[CHARS_IN_GUID
];
2715 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2720 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2722 res
= REGDB_E_KEYMISSING
;
2725 res
= CLSIDFromString(buf
, pClsidNew
);
2727 if (hkey
) RegCloseKey(hkey
);
2731 /******************************************************************************
2732 * OleSetAutoConvert [OLE32.@]
2734 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2736 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2738 WCHAR szClsidNew
[CHARS_IN_GUID
];
2741 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2743 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2746 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2747 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2749 res
= REGDB_E_WRITEREGDB
;
2754 if (hkey
) RegCloseKey(hkey
);
2758 /******************************************************************************
2759 * OleDoAutoConvert [OLE32.@]
2761 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2763 WCHAR
*user_type_old
, *user_type_new
;
2769 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2771 *pClsidNew
= CLSID_NULL
;
2773 return E_INVALIDARG
;
2774 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2778 *pClsidNew
= stat
.clsid
;
2779 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2783 hr
= IStorage_SetClass(pStg
, &clsid
);
2787 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2790 user_type_new
= NULL
;
2793 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2795 user_type_new
= NULL
;
2797 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2798 CoTaskMemFree(user_type_new
);
2801 CoTaskMemFree(user_type_old
);
2802 IStorage_SetClass(pStg
, &stat
.clsid
);
2806 hr
= SetConvertStg(pStg
, TRUE
);
2809 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2810 IStorage_SetClass(pStg
, &stat
.clsid
);
2814 CoTaskMemFree(user_type_old
);
2818 /******************************************************************************
2819 * OleIsRunning [OLE32.@]
2821 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2823 IRunnableObject
*pRunnable
;
2827 TRACE("(%p)\n", object
);
2829 if (!object
) return FALSE
;
2831 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2834 running
= IRunnableObject_IsRunning(pRunnable
);
2835 IRunnableObject_Release(pRunnable
);
2839 /***********************************************************************
2840 * OleNoteObjectVisible [OLE32.@]
2842 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2844 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2845 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2849 /***********************************************************************
2850 * OLE_FreeClipDataArray [internal]
2853 * frees the data associated with an array of CLIPDATAs
2855 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2858 for (i
= 0; i
< count
; i
++)
2859 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2862 /***********************************************************************
2863 * PropSysAllocString [OLE32.@]
2865 * Forward to oleaut32.
2867 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2869 return SysAllocString(str
);
2872 /***********************************************************************
2873 * PropSysFreeString [OLE32.@]
2875 * Forward to oleaut32.
2877 void WINAPI
PropSysFreeString(LPOLESTR str
)
2882 /******************************************************************************
2883 * Check if a PROPVARIANT's type is valid.
2885 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2917 case VT_STREAMED_OBJECT
:
2918 case VT_STORED_OBJECT
:
2919 case VT_BLOB_OBJECT
:
2922 case VT_I1
|VT_VECTOR
:
2923 case VT_I2
|VT_VECTOR
:
2924 case VT_I4
|VT_VECTOR
:
2925 case VT_I8
|VT_VECTOR
:
2926 case VT_R4
|VT_VECTOR
:
2927 case VT_R8
|VT_VECTOR
:
2928 case VT_CY
|VT_VECTOR
:
2929 case VT_DATE
|VT_VECTOR
:
2930 case VT_BSTR
|VT_VECTOR
:
2931 case VT_ERROR
|VT_VECTOR
:
2932 case VT_BOOL
|VT_VECTOR
:
2933 case VT_VARIANT
|VT_VECTOR
:
2934 case VT_UI1
|VT_VECTOR
:
2935 case VT_UI2
|VT_VECTOR
:
2936 case VT_UI4
|VT_VECTOR
:
2937 case VT_UI8
|VT_VECTOR
:
2938 case VT_LPSTR
|VT_VECTOR
:
2939 case VT_LPWSTR
|VT_VECTOR
:
2940 case VT_FILETIME
|VT_VECTOR
:
2941 case VT_CF
|VT_VECTOR
:
2942 case VT_CLSID
|VT_VECTOR
:
2945 WARN("Bad type %d\n", vt
);
2946 return STG_E_INVALIDPARAMETER
;
2949 /***********************************************************************
2950 * PropVariantClear [OLE32.@]
2952 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2956 TRACE("(%p)\n", pvar
);
2961 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2964 memset(pvar
, 0, sizeof(*pvar
));
2994 case VT_STREAMED_OBJECT
:
2996 case VT_STORED_OBJECT
:
2997 if (pvar
->u
.pStream
)
2998 IStream_Release(pvar
->u
.pStream
);
3003 /* pick an arbitrary typed pointer - we don't care about the type
3004 * as we are just freeing it */
3005 CoTaskMemFree(pvar
->u
.puuid
);
3008 case VT_BLOB_OBJECT
:
3009 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
3012 PropSysFreeString(pvar
->u
.bstrVal
);
3015 if (pvar
->u
.pclipdata
)
3017 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
3018 CoTaskMemFree(pvar
->u
.pclipdata
);
3022 if (pvar
->vt
& VT_VECTOR
)
3026 switch (pvar
->vt
& ~VT_VECTOR
)
3029 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
3032 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
3035 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
3036 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
3039 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
3040 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
3043 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
3044 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
3047 if (pvar
->vt
& ~VT_VECTOR
)
3049 /* pick an arbitrary VT_VECTOR structure - they all have the same
3051 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
3056 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
3057 hr
= STG_E_INVALIDPARAMETER
;
3061 memset(pvar
, 0, sizeof(*pvar
));
3065 /***********************************************************************
3066 * PropVariantCopy [OLE32.@]
3068 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
3069 const PROPVARIANT
*pvarSrc
) /* [in] */
3074 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
3076 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
3078 return DISP_E_BADVARTYPE
;
3080 /* this will deal with most cases */
3081 *pvarDest
= *pvarSrc
;
3109 case VT_STREAMED_OBJECT
:
3111 case VT_STORED_OBJECT
:
3112 if (pvarDest
->u
.pStream
)
3113 IStream_AddRef(pvarDest
->u
.pStream
);
3116 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
3117 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
3120 if (pvarSrc
->u
.pszVal
)
3122 len
= strlen(pvarSrc
->u
.pszVal
);
3123 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
3124 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
3128 if (pvarSrc
->u
.pwszVal
)
3130 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
3131 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
3132 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
3136 case VT_BLOB_OBJECT
:
3137 if (pvarSrc
->u
.blob
.pBlobData
)
3139 len
= pvarSrc
->u
.blob
.cbSize
;
3140 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
3141 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
3145 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
3148 if (pvarSrc
->u
.pclipdata
)
3150 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
3151 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
3152 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
3153 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
3154 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
3155 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
3159 if (pvarSrc
->vt
& VT_VECTOR
)
3164 switch(pvarSrc
->vt
& ~VT_VECTOR
)
3166 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3167 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3168 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3169 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3170 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3171 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3172 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3173 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3174 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3175 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3176 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3177 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3178 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3179 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3180 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3181 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3182 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3183 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3184 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3185 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3186 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3189 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3190 return E_INVALIDARG
;
3192 len
= pvarSrc
->u
.capropvar
.cElems
;
3193 pvarDest
->u
.capropvar
.pElems
= len
? CoTaskMemAlloc(len
* elemSize
) : NULL
;
3194 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3196 for (i
= 0; i
< len
; i
++)
3197 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3199 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3201 FIXME("Copy clipformats\n");
3203 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3205 for (i
= 0; i
< len
; i
++)
3206 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3208 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3211 for (i
= 0; i
< len
; i
++)
3213 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3214 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3215 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3216 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3219 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3222 for (i
= 0; i
< len
; i
++)
3224 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3226 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3227 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3228 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3232 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3235 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3241 /***********************************************************************
3242 * FreePropVariantArray [OLE32.@]
3244 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3245 PROPVARIANT
*rgvars
) /* [in/out] */
3249 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3252 return E_INVALIDARG
;
3254 for(i
= 0; i
< cVariants
; i
++)
3255 PropVariantClear(&rgvars
[i
]);
3260 /******************************************************************************
3261 * DllDebugObjectRPCHook (OLE32.@)
3262 * turns on and off internal debugging, pointer is only used on macintosh
3265 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)