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
36 #define NONAMELESSSTRUCT
48 #include "wine/unicode.h"
49 #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 it's state.
61 typedef struct tagTrackerWindowInfo
63 IDataObject
* dataObject
;
64 IDropSource
* dropSource
;
71 HWND curTargetHWND
; /* window the mouse is hovering over */
72 HWND curDragTargetHWND
; /* might be a ancestor of curTargetHWND */
73 IDropTarget
* curDragTarget
;
74 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
75 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
78 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
80 HWND hwndFrame
; /* The containers frame window */
81 HWND hwndActiveObject
; /* The active objects window */
82 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
83 HMENU hmenuCombined
; /* The combined menu */
84 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
87 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
89 DWORD tid
; /* Thread Id */
90 HANDLE hHeap
; /* Heap this is allocated from */
91 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
92 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
93 struct tagOleMenuHookItem
*next
;
96 static OleMenuHookItem
*hook_list
;
99 * This is the lock count on the OLE library. It is controlled by the
100 * OLEInitialize/OLEUninitialize methods.
102 static LONG OLE_moduleLockCount
= 0;
105 * Name of our registered window class.
107 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
108 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
111 * Name of menu descriptor property.
113 static const WCHAR prop_olemenuW
[] =
114 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
116 /* property to store IDropTarget pointer */
117 static const WCHAR prop_oledroptarget
[] =
118 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
120 /* property to store Marshalled IDropTarget pointer */
121 static const WCHAR prop_marshalleddroptarget
[] =
122 {'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};
124 static const WCHAR clsidfmtW
[] =
125 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
126 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
127 '%','0','2','x','%','0','2','x','}','\\',0};
129 static const WCHAR emptyW
[] = { 0 };
131 /******************************************************************************
132 * These are the prototypes of miscellaneous utility methods
134 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
136 /******************************************************************************
137 * These are the prototypes of the utility methods used to manage a shared menu
139 static void OLEMenu_Initialize(void);
140 static void OLEMenu_UnInitialize(void);
141 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
142 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
143 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
144 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
145 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
146 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
147 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
149 /******************************************************************************
150 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
152 extern void OLEClipbrd_UnInitialize(void);
153 extern void OLEClipbrd_Initialize(void);
155 /******************************************************************************
156 * These are the prototypes of the utility methods used for OLE Drag n Drop
158 static void OLEDD_Initialize(void);
159 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
160 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
);
161 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
162 static DWORD
OLEDD_GetButtonState(void);
164 /******************************************************************************
165 * OleBuildVersion [OLE32.@]
167 DWORD WINAPI
OleBuildVersion(void)
169 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
170 return (rmm
<<16)+rup
;
173 /***********************************************************************
174 * OleInitialize (OLE32.@)
176 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
180 TRACE("(%p)\n", reserved
);
183 * The first duty of the OleInitialize is to initialize the COM libraries.
185 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
188 * If the CoInitializeEx call failed, the OLE libraries can't be
194 if (!COM_CurrentInfo()->ole_inits
)
198 * Then, it has to initialize the OLE specific modules.
202 * Object linking and Embedding
203 * In-place activation
205 if (!COM_CurrentInfo()->ole_inits
++ &&
206 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
209 * Initialize the libraries.
211 TRACE("() - Initializing the OLE libraries\n");
216 OLEClipbrd_Initialize();
226 OLEMenu_Initialize();
232 /******************************************************************************
233 * OleUninitialize [OLE32.@]
235 void WINAPI
OleUninitialize(void)
240 * If we hit the bottom of the lock stack, free the libraries.
242 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
245 * Actually free the libraries.
247 TRACE("() - Freeing the last reference count\n");
252 OLEClipbrd_UnInitialize();
257 OLEMenu_UnInitialize();
261 * Then, uninitialize the COM libraries.
266 /******************************************************************************
267 * OleInitializeWOW [OLE32.@]
269 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
270 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
274 /*************************************************************
275 * get_droptarget_handle
277 * Retrieve a handle to the map containing the marshalled IDropTarget.
278 * This handle belongs to the process that called RegisterDragDrop.
279 * See get_droptarget_local_handle().
281 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
283 return GetPropW(hwnd
, prop_marshalleddroptarget
);
286 /*************************************************************
289 * Is the window a droptarget.
291 static inline BOOL
is_droptarget(HWND hwnd
)
293 return get_droptarget_handle(hwnd
) ? TRUE
: FALSE
;
296 /*************************************************************
297 * get_droptarget_local_handle
299 * Retrieve a handle to the map containing the marshalled IDropTarget.
300 * The handle should be closed when finished with.
302 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
304 HANDLE handle
, local_handle
= 0;
306 handle
= get_droptarget_handle(hwnd
);
313 GetWindowThreadProcessId(hwnd
, &pid
);
314 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
317 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
318 CloseHandle(process
);
324 /***********************************************************************
325 * create_map_from_stream
327 * Helper for RegisterDragDrop. Creates a file mapping object
328 * with the contents of the provided stream. The stream must
329 * be a global memory backed stream.
331 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
338 hr
= GetHGlobalFromStream(stream
, &hmem
);
339 if(FAILED(hr
)) return hr
;
341 size
= GlobalSize(hmem
);
342 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
343 if(!*map
) return E_OUTOFMEMORY
;
345 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
346 memcpy(data
, GlobalLock(hmem
), size
);
348 UnmapViewOfFile(data
);
352 /***********************************************************************
353 * create_stream_from_map
355 * Creates a stream from the provided map.
357 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
359 HRESULT hr
= E_OUTOFMEMORY
;
362 MEMORY_BASIC_INFORMATION info
;
364 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
367 VirtualQuery(data
, &info
, sizeof(info
));
368 TRACE("size %d\n", (int)info
.RegionSize
);
370 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
373 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
375 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
377 UnmapViewOfFile(data
);
381 /* This is to work around apps which break COM rules by not implementing
382 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
383 * doesn't call CoMarshallInterface() in RegisterDragDrop().
384 * The wrapper is only used internally, and only exists for the life of
387 IDropTarget IDropTarget_iface
;
392 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
394 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
397 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
401 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
402 if (IsEqualIID(riid
, &IID_IUnknown
) ||
403 IsEqualIID(riid
, &IID_IDropTarget
))
405 IDropTarget_AddRef(&This
->IDropTarget_iface
);
406 *ppvObject
= &This
->IDropTarget_iface
;
410 return E_NOINTERFACE
;
413 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
415 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
416 return InterlockedIncrement(&This
->refs
);
419 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
421 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
422 ULONG refs
= InterlockedDecrement(&This
->refs
);
425 IDropTarget_Release(This
->inner
);
426 HeapFree(GetProcessHeap(), 0, This
);
431 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
432 IDataObject
* pDataObj
,
437 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
438 return IDropTarget_DragEnter(This
->inner
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
441 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
446 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
447 return IDropTarget_DragOver(This
->inner
, grfKeyState
, pt
, pdwEffect
);
450 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
452 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
453 return IDropTarget_DragLeave(This
->inner
);
456 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
457 IDataObject
* pDataObj
,
462 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
463 return IDropTarget_Drop(This
->inner
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
466 static const IDropTargetVtbl DropTargetWrapperVTbl
=
468 DropTargetWrapper_QueryInterface
,
469 DropTargetWrapper_AddRef
,
470 DropTargetWrapper_Release
,
471 DropTargetWrapper_DragEnter
,
472 DropTargetWrapper_DragOver
,
473 DropTargetWrapper_DragLeave
,
474 DropTargetWrapper_Drop
477 static IDropTarget
* WrapDropTarget(IDropTarget
* inner
)
479 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
483 IDropTarget_AddRef(inner
);
484 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
488 return &This
->IDropTarget_iface
;
491 /***********************************************************************
492 * get_droptarget_pointer
494 * Retrieves the marshalled IDropTarget from the window.
496 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
498 IDropTarget
*droptarget
= NULL
;
502 map
= get_droptarget_local_handle(hwnd
);
503 if(!map
) return NULL
;
505 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
507 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
508 IStream_Release(stream
);
514 /***********************************************************************
515 * RegisterDragDrop (OLE32.@)
517 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
523 IDropTarget
*wrapper
;
525 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
527 if (!COM_CurrentApt())
529 ERR("COM not initialized\n");
530 return E_OUTOFMEMORY
;
538 ERR("invalid hwnd %p\n", hwnd
);
539 return DRAGDROP_E_INVALIDHWND
;
542 /* block register for other processes windows */
543 GetWindowThreadProcessId(hwnd
, &pid
);
544 if (pid
!= GetCurrentProcessId())
546 FIXME("register for another process windows is disabled\n");
547 return DRAGDROP_E_INVALIDHWND
;
550 /* check if the window is already registered */
551 if (is_droptarget(hwnd
))
552 return DRAGDROP_E_ALREADYREGISTERED
;
555 * Marshal the drop target pointer into a shared memory map and
556 * store the map's handle in a Wine specific window prop. We also
557 * store the drop target pointer itself in the
558 * "OleDropTargetInterface" prop for compatibility with Windows.
561 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
562 if(FAILED(hr
)) return hr
;
564 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
565 wrapper
= WrapDropTarget(pDropTarget
);
568 IStream_Release(stream
);
569 return E_OUTOFMEMORY
;
571 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
572 IDropTarget_Release(wrapper
);
576 hr
= create_map_from_stream(stream
, &map
);
579 IDropTarget_AddRef(pDropTarget
);
580 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
581 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
587 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
588 CoReleaseMarshalData(stream
);
591 IStream_Release(stream
);
596 /***********************************************************************
597 * RevokeDragDrop (OLE32.@)
599 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
603 IDropTarget
*drop_target
;
606 TRACE("(%p)\n", hwnd
);
610 ERR("invalid hwnd %p\n", hwnd
);
611 return DRAGDROP_E_INVALIDHWND
;
614 /* no registration data */
615 if (!(map
= get_droptarget_handle(hwnd
)))
616 return DRAGDROP_E_NOTREGISTERED
;
618 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
619 if(drop_target
) IDropTarget_Release(drop_target
);
621 RemovePropW(hwnd
, prop_oledroptarget
);
622 RemovePropW(hwnd
, prop_marshalleddroptarget
);
624 hr
= create_stream_from_map(map
, &stream
);
627 CoReleaseMarshalData(stream
);
628 IStream_Release(stream
);
635 /***********************************************************************
636 * OleRegGetUserType (OLE32.@)
638 * This implementation of OleRegGetUserType ignores the dwFormOfType
639 * parameter and always returns the full name of the object. This is
640 * not too bad since this is the case for many objects because of the
641 * way they are registered.
643 HRESULT WINAPI
OleRegGetUserType(
646 LPOLESTR
* pszUserType
)
655 * Initialize the out parameter.
660 * Build the key name we're looking for
662 sprintfW( keyName
, clsidfmtW
,
663 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
664 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
665 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
667 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwFormOfType
, pszUserType
);
670 * Open the class id Key
672 hres
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
676 if (hres
!= ERROR_SUCCESS
)
677 return REGDB_E_CLASSNOTREG
;
680 * Retrieve the size of the name string.
684 hres
= RegQueryValueExW(clsidKey
,
691 if (hres
!=ERROR_SUCCESS
)
693 RegCloseKey(clsidKey
);
694 return REGDB_E_READREGDB
;
698 * Allocate a buffer for the registry value.
700 *pszUserType
= CoTaskMemAlloc(cbData
);
702 if (*pszUserType
==NULL
)
704 RegCloseKey(clsidKey
);
705 return E_OUTOFMEMORY
;
708 hres
= RegQueryValueExW(clsidKey
,
712 (LPBYTE
) *pszUserType
,
715 RegCloseKey(clsidKey
);
717 if (hres
!= ERROR_SUCCESS
)
719 CoTaskMemFree(*pszUserType
);
722 return REGDB_E_READREGDB
;
728 /***********************************************************************
729 * DoDragDrop [OLE32.@]
731 HRESULT WINAPI
DoDragDrop (
732 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
733 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
734 DWORD dwOKEffect
, /* [in] effects allowed by the source */
735 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
737 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
738 TrackerWindowInfo trackerInfo
;
739 HWND hwndTrackWindow
;
742 TRACE("(%p, %p, %d, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
744 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
748 * Setup the drag n drop tracking window.
751 trackerInfo
.dataObject
= pDataObject
;
752 trackerInfo
.dropSource
= pDropSource
;
753 trackerInfo
.dwOKEffect
= dwOKEffect
;
754 trackerInfo
.pdwEffect
= pdwEffect
;
755 trackerInfo
.trackingDone
= FALSE
;
756 trackerInfo
.escPressed
= FALSE
;
757 trackerInfo
.curDragTargetHWND
= 0;
758 trackerInfo
.curTargetHWND
= 0;
759 trackerInfo
.curDragTarget
= 0;
761 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
762 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
763 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
769 * Capture the mouse input
771 SetCapture(hwndTrackWindow
);
776 * Pump messages. All mouse input should go to the capture window.
778 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
780 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
781 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
782 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
784 if ( (msg
.message
>= WM_KEYFIRST
) &&
785 (msg
.message
<= WM_KEYLAST
) )
788 * When keyboard messages are sent to windows on this thread, we
789 * want to ignore notify the drop source that the state changed.
790 * in the case of the Escape key, we also notify the drop source
791 * we give it a special meaning.
793 if ( (msg
.message
==WM_KEYDOWN
) &&
794 (msg
.wParam
==VK_ESCAPE
) )
796 trackerInfo
.escPressed
= TRUE
;
800 * Notify the drop source.
802 OLEDD_TrackStateChange(&trackerInfo
);
807 * Dispatch the messages only when it's not a keyboard message.
809 DispatchMessageW(&msg
);
813 /* re-post the quit message to outer message loop */
814 if (msg
.message
== WM_QUIT
)
815 PostQuitMessage(msg
.wParam
);
817 * Destroy the temporary window.
819 DestroyWindow(hwndTrackWindow
);
821 return trackerInfo
.returnValue
;
827 /***********************************************************************
828 * OleQueryLinkFromData [OLE32.@]
830 HRESULT WINAPI
OleQueryLinkFromData(
831 IDataObject
* pSrcDataObject
)
833 FIXME("(%p),stub!\n", pSrcDataObject
);
837 /***********************************************************************
838 * OleRegGetMiscStatus [OLE32.@]
840 HRESULT WINAPI
OleRegGetMiscStatus(
845 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
846 static const WCHAR dfmtW
[] = {'%','d',0};
854 * Initialize the out parameter.
859 * Build the key name we're looking for
861 sprintfW( keyName
, clsidfmtW
,
862 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
863 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
864 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
866 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwAspect
, pdwStatus
);
869 * Open the class id Key
871 result
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
875 if (result
!= ERROR_SUCCESS
)
876 return REGDB_E_CLASSNOTREG
;
881 result
= RegOpenKeyW(clsidKey
,
886 if (result
!= ERROR_SUCCESS
)
888 RegCloseKey(clsidKey
);
889 return REGDB_E_READREGDB
;
893 * Read the default value
895 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
898 * Open the key specific to the requested aspect.
900 sprintfW(keyName
, dfmtW
, dwAspect
);
902 result
= RegOpenKeyW(miscStatusKey
,
906 if (result
== ERROR_SUCCESS
)
908 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
909 RegCloseKey(aspectKey
);
915 RegCloseKey(miscStatusKey
);
916 RegCloseKey(clsidKey
);
921 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
925 IEnumOLEVERB IEnumOLEVERB_iface
;
932 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
934 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
937 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
938 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
940 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
941 if (IsEqualIID(riid
, &IID_IUnknown
) ||
942 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
944 IUnknown_AddRef(iface
);
948 return E_NOINTERFACE
;
951 static ULONG WINAPI
EnumOLEVERB_AddRef(
954 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
956 return InterlockedIncrement(&This
->ref
);
959 static ULONG WINAPI
EnumOLEVERB_Release(
962 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
963 LONG refs
= InterlockedDecrement(&This
->ref
);
967 RegCloseKey(This
->hkeyVerb
);
968 HeapFree(GetProcessHeap(), 0, This
);
973 static HRESULT WINAPI
EnumOLEVERB_Next(
974 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
977 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
980 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
985 for (; celt
; celt
--, rgelt
++)
990 LPWSTR pwszMenuFlags
;
992 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
993 if (res
== ERROR_NO_MORE_ITEMS
)
998 else if (res
!= ERROR_SUCCESS
)
1000 ERR("RegEnumKeyW failed with error %d\n", res
);
1001 hr
= REGDB_E_READREGDB
;
1004 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
1005 if (res
!= ERROR_SUCCESS
)
1007 ERR("RegQueryValueW failed with error %d\n", res
);
1008 hr
= REGDB_E_READREGDB
;
1011 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
1017 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
1018 if (res
!= ERROR_SUCCESS
)
1020 ERR("RegQueryValueW failed with error %d\n", res
);
1021 hr
= REGDB_E_READREGDB
;
1022 CoTaskMemFree(pwszOLEVERB
);
1026 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
1027 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
1030 hr
= OLEOBJ_E_INVALIDVERB
;
1031 CoTaskMemFree(pwszOLEVERB
);
1034 /* nul terminate the name string and advance to first character */
1035 *pwszMenuFlags
= '\0';
1037 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
1040 hr
= OLEOBJ_E_INVALIDVERB
;
1041 CoTaskMemFree(pwszOLEVERB
);
1044 /* nul terminate the menu string and advance to first character */
1045 *pwszAttribs
= '\0';
1048 /* fill out structure for this verb */
1049 rgelt
->lVerb
= atolW(wszSubKey
);
1050 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1051 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
1052 rgelt
->grfAttribs
= atolW(pwszAttribs
);
1061 static HRESULT WINAPI
EnumOLEVERB_Skip(
1062 IEnumOLEVERB
*iface
, ULONG celt
)
1064 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1066 TRACE("(%d)\n", celt
);
1068 This
->index
+= celt
;
1072 static HRESULT WINAPI
EnumOLEVERB_Reset(
1073 IEnumOLEVERB
*iface
)
1075 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1083 static HRESULT WINAPI
EnumOLEVERB_Clone(
1084 IEnumOLEVERB
*iface
,
1085 IEnumOLEVERB
**ppenum
)
1087 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1089 TRACE("(%p)\n", ppenum
);
1090 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1091 return HRESULT_FROM_WIN32(GetLastError());
1092 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1095 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1097 EnumOLEVERB_QueryInterface
,
1099 EnumOLEVERB_Release
,
1106 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1108 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1111 RegCloseKey(hkeyVerb
);
1112 return E_OUTOFMEMORY
;
1114 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1116 This
->index
= index
;
1117 This
->hkeyVerb
= hkeyVerb
;
1118 *ppenum
= &This
->IEnumOLEVERB_iface
;
1122 /***********************************************************************
1123 * OleRegEnumVerbs [OLE32.@]
1125 * Enumerates verbs associated with a class stored in the registry.
1128 * clsid [I] Class ID to enumerate the verbs for.
1129 * ppenum [O] Enumerator.
1133 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1134 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1135 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1136 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1138 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1143 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1145 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1147 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1150 if (res
== REGDB_E_CLASSNOTREG
)
1151 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1152 else if (res
== REGDB_E_KEYMISSING
)
1153 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1155 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1156 debugstr_guid(clsid
), res
);
1160 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1161 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1162 if (res
!= ERROR_SUCCESS
)
1164 ERR("failed to get subkey count with error %d\n", GetLastError());
1165 return REGDB_E_READREGDB
;
1170 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1171 RegCloseKey(hkeyVerb
);
1172 return OLEOBJ_E_NOVERBS
;
1175 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1178 /******************************************************************************
1179 * OleSetContainedObject [OLE32.@]
1181 HRESULT WINAPI
OleSetContainedObject(
1185 IRunnableObject
* runnable
= NULL
;
1188 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1190 hres
= IUnknown_QueryInterface(pUnknown
,
1191 &IID_IRunnableObject
,
1194 if (SUCCEEDED(hres
))
1196 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1198 IRunnableObject_Release(runnable
);
1206 /******************************************************************************
1209 * Set the OLE object to the running state.
1212 * pUnknown [I] OLE object to run.
1216 * Failure: Any HRESULT code.
1218 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
1220 IRunnableObject
*runable
;
1223 TRACE("(%p)\n", pUnknown
);
1225 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1227 return S_OK
; /* Appears to return no error. */
1229 hres
= IRunnableObject_Run(runable
, NULL
);
1230 IRunnableObject_Release(runable
);
1234 /******************************************************************************
1237 HRESULT WINAPI
OleLoad(
1240 LPOLECLIENTSITE pClientSite
,
1243 IPersistStorage
* persistStorage
= NULL
;
1245 IOleObject
* pOleObject
= NULL
;
1246 STATSTG storageInfo
;
1249 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1254 * TODO, Conversion ... OleDoAutoConvert
1258 * Get the class ID for the object.
1260 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1263 * Now, try and create the handler for the object
1265 hres
= CoCreateInstance(&storageInfo
.clsid
,
1267 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1272 * If that fails, as it will most times, load the default
1277 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1284 * If we couldn't find a handler... this is bad. Abort the whole thing.
1291 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1292 if (SUCCEEDED(hres
))
1295 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1300 * Initialize the object with its IPersistStorage interface.
1302 hres
= IOleObject_QueryInterface(pUnk
,
1303 &IID_IPersistStorage
,
1304 (void**)&persistStorage
);
1306 if (SUCCEEDED(hres
))
1308 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1310 IPersistStorage_Release(persistStorage
);
1311 persistStorage
= NULL
;
1314 if (SUCCEEDED(hres
) && pClientSite
)
1316 * Inform the new object of it's client site.
1318 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1321 * Cleanup interfaces used internally
1324 IOleObject_Release(pOleObject
);
1326 if (SUCCEEDED(hres
))
1330 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1331 if (SUCCEEDED(hres1
))
1333 FIXME("handle OLE link\n");
1334 IOleLink_Release(pOleLink
);
1340 IUnknown_Release(pUnk
);
1349 /***********************************************************************
1352 HRESULT WINAPI
OleSave(
1353 LPPERSISTSTORAGE pPS
,
1360 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1363 * First, we transfer the class ID (if available)
1365 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1367 if (SUCCEEDED(hres
))
1369 WriteClassStg(pStg
, &objectClass
);
1373 * Then, we ask the object to save itself to the
1374 * storage. If it is successful, we commit the storage.
1376 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1378 if (SUCCEEDED(hres
))
1380 IStorage_Commit(pStg
,
1388 /******************************************************************************
1389 * OleLockRunning [OLE32.@]
1391 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1393 IRunnableObject
* runnable
= NULL
;
1396 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1398 hres
= IUnknown_QueryInterface(pUnknown
,
1399 &IID_IRunnableObject
,
1402 if (SUCCEEDED(hres
))
1404 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1406 IRunnableObject_Release(runnable
);
1415 /**************************************************************************
1416 * Internal methods to manage the shared OLE menu in response to the
1417 * OLE***MenuDescriptor API
1421 * OLEMenu_Initialize()
1423 * Initializes the OLEMENU data structures.
1425 static void OLEMenu_Initialize(void)
1430 * OLEMenu_UnInitialize()
1432 * Releases the OLEMENU data structures.
1434 static void OLEMenu_UnInitialize(void)
1438 /*************************************************************************
1439 * OLEMenu_InstallHooks
1440 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1442 * RETURNS: TRUE if message hooks were successfully installed
1445 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1447 OleMenuHookItem
*pHookItem
;
1449 /* Create an entry for the hook table */
1450 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1451 sizeof(OleMenuHookItem
)) ) )
1454 pHookItem
->tid
= tid
;
1455 pHookItem
->hHeap
= GetProcessHeap();
1456 pHookItem
->CallWndProc_hHook
= NULL
;
1458 /* Install a thread scope message hook for WH_GETMESSAGE */
1459 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1460 0, GetCurrentThreadId() );
1461 if ( !pHookItem
->GetMsg_hHook
)
1464 /* Install a thread scope message hook for WH_CALLWNDPROC */
1465 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1466 0, GetCurrentThreadId() );
1467 if ( !pHookItem
->CallWndProc_hHook
)
1470 /* Insert the hook table entry */
1471 pHookItem
->next
= hook_list
;
1472 hook_list
= pHookItem
;
1477 /* Unhook any hooks */
1478 if ( pHookItem
->GetMsg_hHook
)
1479 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1480 if ( pHookItem
->CallWndProc_hHook
)
1481 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1482 /* Release the hook table entry */
1483 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1488 /*************************************************************************
1489 * OLEMenu_UnInstallHooks
1490 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1492 * RETURNS: TRUE if message hooks were successfully installed
1495 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1497 OleMenuHookItem
*pHookItem
= NULL
;
1498 OleMenuHookItem
**ppHook
= &hook_list
;
1502 if ((*ppHook
)->tid
== tid
)
1504 pHookItem
= *ppHook
;
1505 *ppHook
= pHookItem
->next
;
1508 ppHook
= &(*ppHook
)->next
;
1510 if (!pHookItem
) return FALSE
;
1512 /* Uninstall the hooks installed for this thread */
1513 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1515 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1518 /* Release the hook table entry */
1519 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1524 /* Release the hook table entry */
1525 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1530 /*************************************************************************
1531 * OLEMenu_IsHookInstalled
1532 * Tests if OLEMenu hooks have been installed for a thread
1534 * RETURNS: The pointer and index of the hook table entry for the tid
1535 * NULL and -1 for the index if no hooks were installed for this thread
1537 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1539 OleMenuHookItem
*pHookItem
;
1541 /* Do a simple linear search for an entry whose tid matches ours.
1542 * We really need a map but efficiency is not a concern here. */
1543 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1545 if ( tid
== pHookItem
->tid
)
1552 /***********************************************************************
1553 * OLEMenu_FindMainMenuIndex
1555 * Used by OLEMenu API to find the top level group a menu item belongs to.
1556 * On success pnPos contains the index of the item in the top level menu group
1558 * RETURNS: TRUE if the ID was found, FALSE on failure
1560 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1564 nItems
= GetMenuItemCount( hMainMenu
);
1566 for (i
= 0; i
< nItems
; i
++)
1570 /* Is the current item a submenu? */
1571 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1573 /* If the handle is the same we're done */
1574 if ( hsubmenu
== hPopupMenu
)
1580 /* Recursively search without updating pnPos */
1581 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1593 /***********************************************************************
1594 * OLEMenu_SetIsServerMenu
1596 * Checks whether a popup menu belongs to a shared menu group which is
1597 * owned by the server, and sets the menu descriptor state accordingly.
1598 * All menu messages from these groups should be routed to the server.
1600 * RETURNS: TRUE if the popup menu is part of a server owned group
1601 * FALSE if the popup menu is part of a container owned group
1603 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1605 UINT nPos
= 0, nWidth
, i
;
1607 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1609 /* Don't bother searching if the popup is the combined menu itself */
1610 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1613 /* Find the menu item index in the shared OLE menu that this item belongs to */
1614 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1617 /* The group widths array has counts for the number of elements
1618 * in the groups File, Edit, Container, Object, Window, Help.
1619 * The Edit, Object & Help groups belong to the server object
1620 * and the other three belong to the container.
1621 * Loop through the group widths and locate the group we are a member of.
1623 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1625 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1626 if ( nPos
< nWidth
)
1628 /* Odd elements are server menu widths */
1629 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1634 return pOleMenuDescriptor
->bIsServerItem
;
1637 /*************************************************************************
1638 * OLEMenu_CallWndProc
1639 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1640 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1642 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1645 HOLEMENU hOleMenu
= 0;
1646 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1647 OleMenuHookItem
*pHookItem
= NULL
;
1650 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1652 /* Check if we're being asked to process the message */
1653 if ( HC_ACTION
!= code
)
1656 /* Retrieve the current message being dispatched from lParam */
1657 pMsg
= (LPCWPSTRUCT
)lParam
;
1659 /* Check if the message is destined for a window we are interested in:
1660 * If the window has an OLEMenu property we may need to dispatch
1661 * the menu message to its active objects window instead. */
1663 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1667 /* Get the menu descriptor */
1668 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1669 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1672 /* Process menu messages */
1673 switch( pMsg
->message
)
1677 /* Reset the menu descriptor state */
1678 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1680 /* Send this message to the server as well */
1681 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1682 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1686 case WM_INITMENUPOPUP
:
1688 /* Save the state for whether this is a server owned menu */
1689 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1695 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1696 if ( fuFlags
& MF_SYSMENU
)
1699 /* Save the state for whether this is a server owned popup menu */
1700 else if ( fuFlags
& MF_POPUP
)
1701 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1708 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1709 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1710 goto NEXTHOOK
; /* Not a menu message */
1719 /* If the message was for the server dispatch it accordingly */
1720 if ( pOleMenuDescriptor
->bIsServerItem
)
1722 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1723 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1727 if ( pOleMenuDescriptor
)
1728 GlobalUnlock( hOleMenu
);
1730 /* Lookup the hook item for the current thread */
1731 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1733 /* This should never fail!! */
1734 WARN("could not retrieve hHook for current thread!\n" );
1738 /* Pass on the message to the next hooker */
1739 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1742 /*************************************************************************
1743 * OLEMenu_GetMsgProc
1744 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1745 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1747 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1750 HOLEMENU hOleMenu
= 0;
1751 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1752 OleMenuHookItem
*pHookItem
= NULL
;
1755 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1757 /* Check if we're being asked to process a messages */
1758 if ( HC_ACTION
!= code
)
1761 /* Retrieve the current message being dispatched from lParam */
1762 pMsg
= (LPMSG
)lParam
;
1764 /* Check if the message is destined for a window we are interested in:
1765 * If the window has an OLEMenu property we may need to dispatch
1766 * the menu message to its active objects window instead. */
1768 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1772 /* Process menu messages */
1773 switch( pMsg
->message
)
1777 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1779 goto NEXTHOOK
; /* Not a menu message */
1786 /* Get the menu descriptor */
1787 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1788 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1791 /* If the message was for the server dispatch it accordingly */
1792 if ( pOleMenuDescriptor
->bIsServerItem
)
1794 /* Change the hWnd in the message to the active objects hWnd.
1795 * The message loop which reads this message will automatically
1796 * dispatch it to the embedded objects window. */
1797 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1801 if ( pOleMenuDescriptor
)
1802 GlobalUnlock( hOleMenu
);
1804 /* Lookup the hook item for the current thread */
1805 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1807 /* This should never fail!! */
1808 WARN("could not retrieve hHook for current thread!\n" );
1812 /* Pass on the message to the next hooker */
1813 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1816 /***********************************************************************
1817 * OleCreateMenuDescriptor [OLE32.@]
1818 * Creates an OLE menu descriptor for OLE to use when dispatching
1819 * menu messages and commands.
1822 * hmenuCombined - Handle to the objects combined menu
1823 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1826 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1827 HMENU hmenuCombined
,
1828 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1831 OleMenuDescriptor
*pOleMenuDescriptor
;
1834 if ( !hmenuCombined
|| !lpMenuWidths
)
1837 /* Create an OLE menu descriptor */
1838 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1839 sizeof(OleMenuDescriptor
) ) ) )
1842 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1843 if ( !pOleMenuDescriptor
)
1846 /* Initialize menu group widths and hmenu */
1847 for ( i
= 0; i
< 6; i
++ )
1848 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1850 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1851 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1852 GlobalUnlock( hOleMenu
);
1857 /***********************************************************************
1858 * OleDestroyMenuDescriptor [OLE32.@]
1859 * Destroy the shared menu descriptor
1861 HRESULT WINAPI
OleDestroyMenuDescriptor(
1862 HOLEMENU hmenuDescriptor
)
1864 if ( hmenuDescriptor
)
1865 GlobalFree( hmenuDescriptor
);
1869 /***********************************************************************
1870 * OleSetMenuDescriptor [OLE32.@]
1871 * Installs or removes OLE dispatching code for the containers frame window.
1874 * hOleMenu Handle to composite menu descriptor
1875 * hwndFrame Handle to containers frame window
1876 * hwndActiveObject Handle to objects in-place activation window
1877 * lpFrame Pointer to IOleInPlaceFrame on containers window
1878 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1881 * S_OK - menu installed correctly
1882 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1885 * The lpFrame and lpActiveObject parameters are currently ignored
1886 * OLE should install context sensitive help F1 filtering for the app when
1887 * these are non null.
1889 HRESULT WINAPI
OleSetMenuDescriptor(
1892 HWND hwndActiveObject
,
1893 LPOLEINPLACEFRAME lpFrame
,
1894 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1896 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1899 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1900 return E_INVALIDARG
;
1902 if ( lpFrame
|| lpActiveObject
)
1904 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1912 /* Set up a message hook to intercept the containers frame window messages.
1913 * The message filter is responsible for dispatching menu messages from the
1914 * shared menu which are intended for the object.
1917 if ( hOleMenu
) /* Want to install dispatching code */
1919 /* If OLEMenu hooks are already installed for this thread, fail
1920 * Note: This effectively means that OleSetMenuDescriptor cannot
1921 * be called twice in succession on the same frame window
1922 * without first calling it with a null hOleMenu to uninstall */
1923 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1926 /* Get the menu descriptor */
1927 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1928 if ( !pOleMenuDescriptor
)
1929 return E_UNEXPECTED
;
1931 /* Update the menu descriptor */
1932 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1933 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1935 GlobalUnlock( hOleMenu
);
1936 pOleMenuDescriptor
= NULL
;
1938 /* Add a menu descriptor windows property to the frame window */
1939 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1941 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1942 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1945 else /* Want to uninstall dispatching code */
1947 /* Uninstall the hooks */
1948 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1951 /* Remove the menu descriptor property from the frame window */
1952 RemovePropW( hwndFrame
, prop_olemenuW
);
1958 /******************************************************************************
1959 * IsAccelerator [OLE32.@]
1960 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1962 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1967 if(!lpMsg
) return FALSE
;
1970 WARN_(accel
)("NULL accel handle\n");
1973 if((lpMsg
->message
!= WM_KEYDOWN
&&
1974 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1975 lpMsg
->message
!= WM_SYSCHAR
&&
1976 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1977 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1978 if (NULL
== lpAccelTbl
)
1982 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1984 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1985 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1989 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1990 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1991 hAccel
, cAccelEntries
,
1992 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1993 for(i
= 0; i
< cAccelEntries
; i
++)
1995 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1998 if(lpMsg
->message
== WM_CHAR
)
2000 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
2002 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
2008 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
2011 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
2012 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
2013 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
2014 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
2015 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
2016 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
2017 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
2021 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2023 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2024 { /* ^^ ALT pressed */
2025 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2033 WARN_(accel
)("couldn't translate accelerator key\n");
2034 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2038 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2039 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2043 /***********************************************************************
2044 * ReleaseStgMedium [OLE32.@]
2046 void WINAPI
ReleaseStgMedium(
2049 switch (pmedium
->tymed
)
2053 if ( (pmedium
->pUnkForRelease
==0) &&
2054 (pmedium
->u
.hGlobal
!=0) )
2055 GlobalFree(pmedium
->u
.hGlobal
);
2060 if (pmedium
->u
.lpszFileName
!=0)
2062 if (pmedium
->pUnkForRelease
==0)
2064 DeleteFileW(pmedium
->u
.lpszFileName
);
2067 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2073 if (pmedium
->u
.pstm
!=0)
2075 IStream_Release(pmedium
->u
.pstm
);
2079 case TYMED_ISTORAGE
:
2081 if (pmedium
->u
.pstg
!=0)
2083 IStorage_Release(pmedium
->u
.pstg
);
2089 if ( (pmedium
->pUnkForRelease
==0) &&
2090 (pmedium
->u
.hBitmap
!=0) )
2091 DeleteObject(pmedium
->u
.hBitmap
);
2096 if ( (pmedium
->pUnkForRelease
==0) &&
2097 (pmedium
->u
.hMetaFilePict
!=0) )
2099 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2100 DeleteMetaFile(pMP
->hMF
);
2101 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2102 GlobalFree(pmedium
->u
.hMetaFilePict
);
2108 if ( (pmedium
->pUnkForRelease
==0) &&
2109 (pmedium
->u
.hEnhMetaFile
!=0) )
2111 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2119 pmedium
->tymed
=TYMED_NULL
;
2122 * After cleaning up, the unknown is released
2124 if (pmedium
->pUnkForRelease
!=0)
2126 IUnknown_Release(pmedium
->pUnkForRelease
);
2127 pmedium
->pUnkForRelease
= 0;
2132 * OLEDD_Initialize()
2134 * Initializes the OLE drag and drop data structures.
2136 static void OLEDD_Initialize(void)
2140 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2141 wndClass
.style
= CS_GLOBALCLASS
;
2142 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2143 wndClass
.cbClsExtra
= 0;
2144 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2145 wndClass
.hCursor
= 0;
2146 wndClass
.hbrBackground
= 0;
2147 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2149 RegisterClassW (&wndClass
);
2153 * OLEDD_DragTrackerWindowProc()
2155 * This method is the WindowProcedure of the drag n drop tracking
2156 * window. During a drag n Drop operation, an invisible window is created
2157 * to receive the user input and act upon it. This procedure is in charge
2161 #define DRAG_TIMER_ID 1
2163 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2173 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2175 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2176 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2183 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
2189 case WM_LBUTTONDOWN
:
2190 case WM_MBUTTONDOWN
:
2191 case WM_RBUTTONDOWN
:
2193 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
2198 KillTimer(hwnd
, DRAG_TIMER_ID
);
2204 * This is a window proc after all. Let's call the default.
2206 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2210 * OLEDD_TrackMouseMove()
2212 * This method is invoked while a drag and drop operation is in effect.
2213 * it will generate the appropriate callbacks in the drop source
2214 * and drop target. It will also provide the expected feedback to
2218 * trackerInfo - Pointer to the structure identifying the
2219 * drag & drop operation that is currently
2222 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2224 HWND hwndNewTarget
= 0;
2229 * Get the handle of the window under the mouse
2231 pt
.x
= trackerInfo
->curMousePos
.x
;
2232 pt
.y
= trackerInfo
->curMousePos
.y
;
2233 hwndNewTarget
= WindowFromPoint(pt
);
2236 * Every time, we re-initialize the effects passed to the
2237 * IDropTarget to the effects allowed by the source.
2239 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2242 * If we are hovering over the same target as before, send the
2243 * DragOver notification
2245 if ( (trackerInfo
->curDragTarget
!= 0) &&
2246 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2248 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2249 trackerInfo
->dwKeyState
,
2250 trackerInfo
->curMousePos
,
2251 trackerInfo
->pdwEffect
);
2256 * If we changed window, we have to notify our old target and check for
2259 if (trackerInfo
->curDragTarget
)
2260 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2263 * Make sure we're hovering over a window.
2268 * Find-out if there is a drag target under the mouse
2270 HWND next_target_wnd
= hwndNewTarget
;
2272 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2274 while (next_target_wnd
&& !is_droptarget(next_target_wnd
))
2275 next_target_wnd
= GetParent(next_target_wnd
);
2277 if (next_target_wnd
) hwndNewTarget
= next_target_wnd
;
2279 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2280 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2281 trackerInfo
->curDragTarget
= get_droptarget_pointer(hwndNewTarget
);
2284 * If there is, notify it that we just dragged-in
2286 if (trackerInfo
->curDragTarget
)
2288 hr
= IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2289 trackerInfo
->dataObject
,
2290 trackerInfo
->dwKeyState
,
2291 trackerInfo
->curMousePos
,
2292 trackerInfo
->pdwEffect
);
2294 /* failed DragEnter() means invalid target */
2297 trackerInfo
->curDragTargetHWND
= 0;
2298 trackerInfo
->curTargetHWND
= 0;
2299 IDropTarget_Release(trackerInfo
->curDragTarget
);
2300 trackerInfo
->curDragTarget
= 0;
2307 * The mouse is not over a window so we don't track anything.
2309 trackerInfo
->curDragTargetHWND
= 0;
2310 trackerInfo
->curTargetHWND
= 0;
2311 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2312 trackerInfo
->curDragTarget
= 0;
2317 * Now that we have done that, we have to tell the source to give
2318 * us feedback on the work being done by the target. If we don't
2319 * have a target, simulate no effect.
2321 if (trackerInfo
->curDragTarget
==0)
2323 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2326 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2327 *trackerInfo
->pdwEffect
);
2330 * When we ask for feedback from the drop source, sometimes it will
2331 * do all the necessary work and sometimes it will not handle it
2332 * when that's the case, we must display the standard drag and drop
2335 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2339 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2341 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(2));
2343 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2345 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(3));
2347 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2349 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(4));
2353 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(1));
2361 * OLEDD_TrackStateChange()
2363 * This method is invoked while a drag and drop operation is in effect.
2364 * It is used to notify the drop target/drop source callbacks when
2365 * the state of the keyboard or mouse button change.
2368 * trackerInfo - Pointer to the structure identifying the
2369 * drag & drop operation that is currently
2372 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2375 * Ask the drop source what to do with the operation.
2377 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2378 trackerInfo
->dropSource
,
2379 trackerInfo
->escPressed
,
2380 trackerInfo
->dwKeyState
);
2383 * All the return valued will stop the operation except the S_OK
2386 if (trackerInfo
->returnValue
!=S_OK
)
2389 * Make sure the message loop in DoDragDrop stops
2391 trackerInfo
->trackingDone
= TRUE
;
2394 * Release the mouse in case the drop target decides to show a popup
2395 * or a menu or something.
2400 * If we end-up over a target, drop the object in the target or
2401 * inform the target that the operation was cancelled.
2403 if (trackerInfo
->curDragTarget
)
2405 switch (trackerInfo
->returnValue
)
2408 * If the source wants us to complete the operation, we tell
2409 * the drop target that we just dropped the object in it.
2411 case DRAGDROP_S_DROP
:
2412 if (*trackerInfo
->pdwEffect
!= DROPEFFECT_NONE
)
2413 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2414 trackerInfo
->dataObject
,
2415 trackerInfo
->dwKeyState
,
2416 trackerInfo
->curMousePos
,
2417 trackerInfo
->pdwEffect
);
2419 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2423 * If the source told us that we should cancel, fool the drop
2424 * target by telling it that the mouse left it's window.
2425 * Also set the drop effect to "NONE" in case the application
2426 * ignores the result of DoDragDrop.
2428 case DRAGDROP_S_CANCEL
:
2429 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2430 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2438 * OLEDD_GetButtonState()
2440 * This method will use the current state of the keyboard to build
2441 * a button state mask equivalent to the one passed in the
2442 * WM_MOUSEMOVE wParam.
2444 static DWORD
OLEDD_GetButtonState(void)
2446 BYTE keyboardState
[256];
2449 GetKeyboardState(keyboardState
);
2451 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2452 keyMask
|= MK_SHIFT
;
2454 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2455 keyMask
|= MK_CONTROL
;
2457 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2458 keyMask
|= MK_LBUTTON
;
2460 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2461 keyMask
|= MK_RBUTTON
;
2463 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2464 keyMask
|= MK_MBUTTON
;
2470 * OLEDD_GetButtonState()
2472 * This method will read the default value of the registry key in
2473 * parameter and extract a DWORD value from it. The registry key value
2474 * can be in a string key or a DWORD key.
2477 * regKey - Key to read the default value from
2478 * pdwValue - Pointer to the location where the DWORD
2479 * value is returned. This value is not modified
2480 * if the value is not found.
2483 static void OLEUTL_ReadRegistryDWORDValue(
2488 DWORD cbData
= sizeof(buffer
);
2492 lres
= RegQueryValueExW(regKey
,
2499 if (lres
==ERROR_SUCCESS
)
2504 *pdwValue
= *(DWORD
*)buffer
;
2509 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2515 /******************************************************************************
2518 * The operation of this function is documented literally in the WinAPI
2519 * documentation to involve a QueryInterface for the IViewObject interface,
2520 * followed by a call to IViewObject::Draw.
2522 HRESULT WINAPI
OleDraw(
2529 IViewObject
*viewobject
;
2531 hres
= IUnknown_QueryInterface(pUnk
,
2533 (void**)&viewobject
);
2535 if (SUCCEEDED(hres
))
2539 rectl
.left
= lprcBounds
->left
;
2540 rectl
.right
= lprcBounds
->right
;
2541 rectl
.top
= lprcBounds
->top
;
2542 rectl
.bottom
= lprcBounds
->bottom
;
2543 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2545 IViewObject_Release(viewobject
);
2550 return DV_E_NOIVIEWOBJECT
;
2554 /***********************************************************************
2555 * OleTranslateAccelerator [OLE32.@]
2557 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2558 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2562 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2564 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2565 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2570 /******************************************************************************
2571 * OleCreate [OLE32.@]
2574 HRESULT WINAPI
OleCreate(
2578 LPFORMATETC pFormatEtc
,
2579 LPOLECLIENTSITE pClientSite
,
2584 IUnknown
* pUnk
= NULL
;
2585 IOleObject
*pOleObject
= NULL
;
2587 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2588 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2590 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2592 if (SUCCEEDED(hres
))
2593 hres
= IStorage_SetClass(pStg
, rclsid
);
2595 if (pClientSite
&& SUCCEEDED(hres
))
2597 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2598 if (SUCCEEDED(hres
))
2601 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2605 if (SUCCEEDED(hres
))
2607 IPersistStorage
* pPS
;
2608 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2610 TRACE("trying to set stg %p\n", pStg
);
2611 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2612 TRACE("-- result 0x%08x\n", hres
);
2613 IPersistStorage_Release(pPS
);
2617 if (pClientSite
&& SUCCEEDED(hres
))
2619 TRACE("trying to set clientsite %p\n", pClientSite
);
2620 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2621 TRACE("-- result 0x%08x\n", hres
);
2625 IOleObject_Release(pOleObject
);
2627 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2630 IRunnableObject
*pRunnable
;
2631 IOleCache
*pOleCache
;
2634 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2635 if (SUCCEEDED(hres2
))
2637 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2638 IRunnableObject_Release(pRunnable
);
2641 if (SUCCEEDED(hres
))
2643 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2644 if (SUCCEEDED(hres2
))
2647 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2651 pfe
.dwAspect
= DVASPECT_CONTENT
;
2653 pfe
.tymed
= TYMED_NULL
;
2654 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2657 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2658 IOleCache_Release(pOleCache
);
2663 if (FAILED(hres
) && pUnk
)
2665 IUnknown_Release(pUnk
);
2671 TRACE("-- %p\n", pUnk
);
2675 /******************************************************************************
2676 * OleGetAutoConvert [OLE32.@]
2678 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2680 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2682 WCHAR buf
[CHARS_IN_GUID
];
2686 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2691 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2693 res
= REGDB_E_KEYMISSING
;
2696 res
= CLSIDFromString(buf
, pClsidNew
);
2698 if (hkey
) RegCloseKey(hkey
);
2702 /******************************************************************************
2703 * OleSetAutoConvert [OLE32.@]
2705 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2707 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2709 WCHAR szClsidNew
[CHARS_IN_GUID
];
2712 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2714 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2717 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2718 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2720 res
= REGDB_E_WRITEREGDB
;
2725 if (hkey
) RegCloseKey(hkey
);
2729 /******************************************************************************
2730 * OleDoAutoConvert [OLE32.@]
2732 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2734 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2738 /******************************************************************************
2739 * OleIsRunning [OLE32.@]
2741 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2743 IRunnableObject
*pRunnable
;
2747 TRACE("(%p)\n", object
);
2749 if (!object
) return FALSE
;
2751 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2754 running
= IRunnableObject_IsRunning(pRunnable
);
2755 IRunnableObject_Release(pRunnable
);
2759 /***********************************************************************
2760 * OleNoteObjectVisible [OLE32.@]
2762 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2764 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2765 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2769 /***********************************************************************
2770 * OLE_FreeClipDataArray [internal]
2773 * frees the data associated with an array of CLIPDATAs
2775 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2778 for (i
= 0; i
< count
; i
++)
2779 if (pClipDataArray
[i
].pClipData
)
2780 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2783 /***********************************************************************
2784 * PropSysAllocString [OLE32.@]
2786 * Basically a copy of SysAllocStringLen.
2788 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2792 WCHAR
* stringBuffer
;
2797 len
= lstrlenW(str
);
2799 * Find the length of the buffer passed-in, in bytes.
2801 bufferSize
= len
* sizeof (WCHAR
);
2804 * Allocate a new buffer to hold the string.
2805 * Don't forget to keep an empty spot at the beginning of the
2806 * buffer for the character count and an extra character at the
2809 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2810 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2813 * If the memory allocation failed, return a null pointer.
2819 * Copy the length of the string in the placeholder.
2821 *newBuffer
= bufferSize
;
2824 * Skip the byte count.
2828 memcpy(newBuffer
, str
, bufferSize
);
2831 * Make sure that there is a nul character at the end of the
2834 stringBuffer
= (WCHAR
*)newBuffer
;
2835 stringBuffer
[len
] = '\0';
2837 return stringBuffer
;
2840 /***********************************************************************
2841 * PropSysFreeString [OLE32.@]
2843 * Copy of SysFreeString.
2845 void WINAPI
PropSysFreeString(LPOLESTR str
)
2847 DWORD
* bufferPointer
;
2849 /* NULL is a valid parameter */
2853 * We have to be careful when we free a BSTR pointer, it points to
2854 * the beginning of the string but it skips the byte count contained
2855 * before the string.
2857 bufferPointer
= (DWORD
*)str
;
2862 * Free the memory from its "real" origin.
2864 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2867 /******************************************************************************
2868 * Check if a PROPVARIANT's type is valid.
2870 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2897 case VT_STREAMED_OBJECT
:
2898 case VT_STORED_OBJECT
:
2899 case VT_BLOB_OBJECT
:
2902 case VT_I2
|VT_VECTOR
:
2903 case VT_I4
|VT_VECTOR
:
2904 case VT_R4
|VT_VECTOR
:
2905 case VT_R8
|VT_VECTOR
:
2906 case VT_CY
|VT_VECTOR
:
2907 case VT_DATE
|VT_VECTOR
:
2908 case VT_BSTR
|VT_VECTOR
:
2909 case VT_ERROR
|VT_VECTOR
:
2910 case VT_BOOL
|VT_VECTOR
:
2911 case VT_VARIANT
|VT_VECTOR
:
2912 case VT_UI1
|VT_VECTOR
:
2913 case VT_UI2
|VT_VECTOR
:
2914 case VT_UI4
|VT_VECTOR
:
2915 case VT_I8
|VT_VECTOR
:
2916 case VT_UI8
|VT_VECTOR
:
2917 case VT_LPSTR
|VT_VECTOR
:
2918 case VT_LPWSTR
|VT_VECTOR
:
2919 case VT_FILETIME
|VT_VECTOR
:
2920 case VT_CF
|VT_VECTOR
:
2921 case VT_CLSID
|VT_VECTOR
:
2924 WARN("Bad type %d\n", vt
);
2925 return STG_E_INVALIDPARAMETER
;
2928 /***********************************************************************
2929 * PropVariantClear [OLE32.@]
2931 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2935 TRACE("(%p)\n", pvar
);
2940 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2965 case VT_STREAMED_OBJECT
:
2967 case VT_STORED_OBJECT
:
2968 if (pvar
->u
.pStream
)
2969 IUnknown_Release(pvar
->u
.pStream
);
2974 /* pick an arbitrary typed pointer - we don't care about the type
2975 * as we are just freeing it */
2976 CoTaskMemFree(pvar
->u
.puuid
);
2979 case VT_BLOB_OBJECT
:
2980 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2983 if (pvar
->u
.bstrVal
)
2984 PropSysFreeString(pvar
->u
.bstrVal
);
2987 if (pvar
->u
.pclipdata
)
2989 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2990 CoTaskMemFree(pvar
->u
.pclipdata
);
2994 if (pvar
->vt
& VT_VECTOR
)
2998 switch (pvar
->vt
& ~VT_VECTOR
)
3001 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
3004 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
3007 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
3008 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
3011 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
3012 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
3015 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
3016 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
3019 if (pvar
->vt
& ~VT_VECTOR
)
3021 /* pick an arbitrary VT_VECTOR structure - they all have the same
3023 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
3027 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
3030 ZeroMemory(pvar
, sizeof(*pvar
));
3035 /***********************************************************************
3036 * PropVariantCopy [OLE32.@]
3038 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
3039 const PROPVARIANT
*pvarSrc
) /* [in] */
3044 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
3046 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
3050 /* this will deal with most cases */
3051 *pvarDest
= *pvarSrc
;
3075 case VT_STREAMED_OBJECT
:
3077 case VT_STORED_OBJECT
:
3078 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
3081 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
3082 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
3085 len
= strlen(pvarSrc
->u
.pszVal
);
3086 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
3087 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
3090 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
3091 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
3092 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
3095 case VT_BLOB_OBJECT
:
3096 if (pvarSrc
->u
.blob
.pBlobData
)
3098 len
= pvarSrc
->u
.blob
.cbSize
;
3099 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
3100 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
3104 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
3107 if (pvarSrc
->u
.pclipdata
)
3109 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
3110 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
3111 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
3112 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
3113 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
3114 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
3118 if (pvarSrc
->vt
& VT_VECTOR
)
3123 switch(pvarSrc
->vt
& ~VT_VECTOR
)
3125 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3126 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3127 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3128 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3129 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3130 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3131 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3132 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3133 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3134 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3135 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3136 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3137 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3138 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3139 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3140 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3141 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3142 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3143 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3144 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3145 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3148 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3149 return E_INVALIDARG
;
3151 len
= pvarSrc
->u
.capropvar
.cElems
;
3152 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
3153 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3155 for (i
= 0; i
< len
; i
++)
3156 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3158 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3160 FIXME("Copy clipformats\n");
3162 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3164 for (i
= 0; i
< len
; i
++)
3165 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3167 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3170 for (i
= 0; i
< len
; i
++)
3172 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3173 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3174 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3175 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3178 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3181 for (i
= 0; i
< len
; i
++)
3183 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3185 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3186 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3187 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3191 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3194 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3200 /***********************************************************************
3201 * FreePropVariantArray [OLE32.@]
3203 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3204 PROPVARIANT
*rgvars
) /* [in/out] */
3208 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3211 return E_INVALIDARG
;
3213 for(i
= 0; i
< cVariants
; i
++)
3214 PropVariantClear(&rgvars
[i
]);
3219 /******************************************************************************
3220 * DllDebugObjectRPCHook (OLE32.@)
3221 * turns on and off internal debugging, pointer is only used on macintosh
3224 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)