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
28 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
29 WINE_DECLARE_DEBUG_CHANNEL(accel
);
31 /******************************************************************************
32 * These are static/global variables and internal data structures that the
33 * OLE module uses to maintain its state.
35 typedef struct tagTrackerWindowInfo
37 IDataObject
* dataObject
;
38 IDropSource
* dropSource
;
45 HWND curTargetHWND
; /* window the mouse is hovering over */
46 HWND curDragTargetHWND
; /* might be an ancestor of curTargetHWND */
47 IDropTarget
* curDragTarget
;
48 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
49 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
52 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
54 HWND hwndFrame
; /* The containers frame window */
55 HWND hwndActiveObject
; /* The active objects window */
56 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
57 HMENU hmenuCombined
; /* The combined menu */
58 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
61 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
63 DWORD tid
; /* Thread Id */
64 HANDLE hHeap
; /* Heap this is allocated from */
65 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
66 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
67 struct tagOleMenuHookItem
*next
;
70 static OleMenuHookItem
*hook_list
;
73 * This is the lock count on the OLE library. It is controlled by the
74 * OLEInitialize/OLEUninitialize methods.
76 static LONG OLE_moduleLockCount
= 0;
79 * Name of our registered window class.
81 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
82 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
85 * Name of menu descriptor property.
87 static const WCHAR prop_olemenuW
[] =
88 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
90 /* property to store IDropTarget pointer */
91 static const WCHAR prop_oledroptarget
[] =
92 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
94 /* property to store Marshalled IDropTarget pointer */
95 static const WCHAR prop_marshalleddroptarget
[] =
96 {'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};
98 static const WCHAR clsidfmtW
[] =
99 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
100 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
101 '%','0','2','x','%','0','2','x','}','\\',0};
103 static const WCHAR emptyW
[] = { 0 };
105 /******************************************************************************
106 * These are the prototypes of miscellaneous utility methods
108 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
110 /******************************************************************************
111 * These are the prototypes of the utility methods used to manage a shared menu
113 static void OLEMenu_Initialize(void);
114 static void OLEMenu_UnInitialize(void);
115 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
116 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
117 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
118 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
119 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
120 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
121 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
123 /******************************************************************************
124 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
126 extern void OLEClipbrd_UnInitialize(void);
127 extern void OLEClipbrd_Initialize(void);
129 /******************************************************************************
130 * These are the prototypes of the utility methods used for OLE Drag n Drop
132 static void OLEDD_Initialize(void);
133 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
134 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
135 static DWORD
OLEDD_GetButtonState(void);
137 /******************************************************************************
138 * OleBuildVersion [OLE32.@]
140 DWORD WINAPI
OleBuildVersion(void)
142 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
143 return (rmm
<<16)+rup
;
146 /***********************************************************************
147 * OleInitialize (OLE32.@)
149 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
153 TRACE("(%p)\n", reserved
);
156 * The first duty of the OleInitialize is to initialize the COM libraries.
158 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
161 * If the CoInitializeEx call failed, the OLE libraries can't be
167 if (!COM_CurrentInfo()->ole_inits
)
171 * Then, it has to initialize the OLE specific modules.
175 * Object linking and Embedding
176 * In-place activation
178 if (!COM_CurrentInfo()->ole_inits
++ &&
179 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
182 * Initialize the libraries.
184 TRACE("() - Initializing the OLE libraries\n");
189 OLEClipbrd_Initialize();
199 OLEMenu_Initialize();
205 /******************************************************************************
206 * OleUninitialize [OLE32.@]
208 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
213 * If we hit the bottom of the lock stack, free the libraries.
215 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
218 * Actually free the libraries.
220 TRACE("() - Freeing the last reference count\n");
225 OLEClipbrd_UnInitialize();
230 OLEMenu_UnInitialize();
234 * Then, uninitialize the COM libraries.
239 /******************************************************************************
240 * OleInitializeWOW [OLE32.@]
242 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
243 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
247 /*************************************************************
248 * get_droptarget_handle
250 * Retrieve a handle to the map containing the marshalled IDropTarget.
251 * This handle belongs to the process that called RegisterDragDrop.
252 * See get_droptarget_local_handle().
254 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
256 return GetPropW(hwnd
, prop_marshalleddroptarget
);
259 /*************************************************************
262 * Is the window a droptarget.
264 static inline BOOL
is_droptarget(HWND hwnd
)
266 return get_droptarget_handle(hwnd
) != 0;
269 /*************************************************************
270 * get_droptarget_local_handle
272 * Retrieve a handle to the map containing the marshalled IDropTarget.
273 * The handle should be closed when finished with.
275 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
277 HANDLE handle
, local_handle
= 0;
279 handle
= get_droptarget_handle(hwnd
);
286 GetWindowThreadProcessId(hwnd
, &pid
);
287 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
290 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
291 CloseHandle(process
);
297 /***********************************************************************
298 * create_map_from_stream
300 * Helper for RegisterDragDrop. Creates a file mapping object
301 * with the contents of the provided stream. The stream must
302 * be a global memory backed stream.
304 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
311 hr
= GetHGlobalFromStream(stream
, &hmem
);
312 if(FAILED(hr
)) return hr
;
314 size
= GlobalSize(hmem
);
315 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
316 if(!*map
) return E_OUTOFMEMORY
;
318 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
319 memcpy(data
, GlobalLock(hmem
), size
);
321 UnmapViewOfFile(data
);
325 /***********************************************************************
326 * create_stream_from_map
328 * Creates a stream from the provided map.
330 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
332 HRESULT hr
= E_OUTOFMEMORY
;
335 MEMORY_BASIC_INFORMATION info
;
337 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
340 VirtualQuery(data
, &info
, sizeof(info
));
341 TRACE("size %d\n", (int)info
.RegionSize
);
343 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
346 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
348 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
350 UnmapViewOfFile(data
);
354 /* This is to work around apps which break COM rules by not implementing
355 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
356 * doesn't call CoMarshallInterface() in RegisterDragDrop().
357 * The wrapper is only used internally, and only exists for the life of
358 * the marshal. We don't want to hold a ref on the app provided target
359 * as some apps destroy this prior to CoUninitialize without calling
360 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
362 IDropTarget IDropTarget_iface
;
367 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
369 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
372 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
376 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
377 if (IsEqualIID(riid
, &IID_IUnknown
) ||
378 IsEqualIID(riid
, &IID_IDropTarget
))
380 IDropTarget_AddRef(&This
->IDropTarget_iface
);
381 *ppvObject
= &This
->IDropTarget_iface
;
385 return E_NOINTERFACE
;
388 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
390 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
391 return InterlockedIncrement(&This
->refs
);
394 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
396 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
397 ULONG refs
= InterlockedDecrement(&This
->refs
);
398 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
402 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
404 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
405 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
406 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
407 IDropTarget_AddRef( *target
);
411 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
412 IDataObject
* pDataObj
,
418 HRESULT r
= get_target_from_wrapper( iface
, &target
);
422 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
423 IDropTarget_Release( target
);
428 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
434 HRESULT r
= get_target_from_wrapper( iface
, &target
);
438 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
439 IDropTarget_Release( target
);
444 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
447 HRESULT r
= get_target_from_wrapper( iface
, &target
);
451 r
= IDropTarget_DragLeave( target
);
452 IDropTarget_Release( target
);
457 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
458 IDataObject
* pDataObj
,
464 HRESULT r
= get_target_from_wrapper( iface
, &target
);
468 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
469 IDropTarget_Release( target
);
474 static const IDropTargetVtbl DropTargetWrapperVTbl
=
476 DropTargetWrapper_QueryInterface
,
477 DropTargetWrapper_AddRef
,
478 DropTargetWrapper_Release
,
479 DropTargetWrapper_DragEnter
,
480 DropTargetWrapper_DragOver
,
481 DropTargetWrapper_DragLeave
,
482 DropTargetWrapper_Drop
485 static IDropTarget
* WrapDropTarget( HWND hwnd
)
487 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
491 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
495 return &This
->IDropTarget_iface
;
498 /***********************************************************************
499 * get_droptarget_pointer
501 * Retrieves the marshalled IDropTarget from the window.
503 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
505 IDropTarget
*droptarget
= NULL
;
509 map
= get_droptarget_local_handle(hwnd
);
510 if(!map
) return NULL
;
512 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
514 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
515 IStream_Release(stream
);
521 /***********************************************************************
522 * RegisterDragDrop (OLE32.@)
524 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
530 IDropTarget
*wrapper
;
532 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
534 if (!COM_CurrentApt())
536 ERR("COM not initialized\n");
537 return E_OUTOFMEMORY
;
545 ERR("invalid hwnd %p\n", hwnd
);
546 return DRAGDROP_E_INVALIDHWND
;
549 /* block register for other processes windows */
550 GetWindowThreadProcessId(hwnd
, &pid
);
551 if (pid
!= GetCurrentProcessId())
553 FIXME("register for another process windows is disabled\n");
554 return DRAGDROP_E_INVALIDHWND
;
557 /* check if the window is already registered */
558 if (is_droptarget(hwnd
))
559 return DRAGDROP_E_ALREADYREGISTERED
;
562 * Marshal the drop target pointer into a shared memory map and
563 * store the map's handle in a Wine specific window prop. We also
564 * store the drop target pointer itself in the
565 * "OleDropTargetInterface" prop for compatibility with Windows.
568 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
569 if(FAILED(hr
)) return hr
;
571 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
572 wrapper
= WrapDropTarget( hwnd
);
575 IStream_Release(stream
);
576 return E_OUTOFMEMORY
;
578 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
579 IDropTarget_Release(wrapper
);
583 hr
= create_map_from_stream(stream
, &map
);
586 IDropTarget_AddRef(pDropTarget
);
587 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
588 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
594 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
595 CoReleaseMarshalData(stream
);
598 IStream_Release(stream
);
603 /***********************************************************************
604 * RevokeDragDrop (OLE32.@)
606 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
610 IDropTarget
*drop_target
;
613 TRACE("(%p)\n", hwnd
);
617 ERR("invalid hwnd %p\n", hwnd
);
618 return DRAGDROP_E_INVALIDHWND
;
621 /* no registration data */
622 if (!(map
= get_droptarget_handle(hwnd
)))
623 return DRAGDROP_E_NOTREGISTERED
;
625 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
626 if(drop_target
) IDropTarget_Release(drop_target
);
628 RemovePropW(hwnd
, prop_oledroptarget
);
629 RemovePropW(hwnd
, prop_marshalleddroptarget
);
631 hr
= create_stream_from_map(map
, &stream
);
634 CoReleaseMarshalData(stream
);
635 IStream_Release(stream
);
642 /***********************************************************************
643 * OleRegGetUserType (OLE32.@)
645 * This implementation of OleRegGetUserType ignores the dwFormOfType
646 * parameter and always returns the full name of the object. This is
647 * not too bad since this is the case for many objects because of the
648 * way they are registered.
650 HRESULT WINAPI
OleRegGetUserType(
653 LPOLESTR
* pszUserType
)
662 * Initialize the out parameter.
667 * Build the key name we're looking for
669 sprintfW( keyName
, clsidfmtW
,
670 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
671 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
672 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
674 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwFormOfType
, pszUserType
);
677 * Open the class id Key
679 hres
= open_classes_key(HKEY_CLASSES_ROOT
, keyName
, MAXIMUM_ALLOWED
, &clsidKey
);
680 if (hres
!= ERROR_SUCCESS
)
681 return REGDB_E_CLASSNOTREG
;
684 * Retrieve the size of the name string.
688 hres
= RegQueryValueExW(clsidKey
,
695 if (hres
!=ERROR_SUCCESS
)
697 RegCloseKey(clsidKey
);
698 return REGDB_E_READREGDB
;
702 * Allocate a buffer for the registry value.
704 *pszUserType
= CoTaskMemAlloc(cbData
);
706 if (*pszUserType
==NULL
)
708 RegCloseKey(clsidKey
);
709 return E_OUTOFMEMORY
;
712 hres
= RegQueryValueExW(clsidKey
,
716 (LPBYTE
) *pszUserType
,
719 RegCloseKey(clsidKey
);
721 if (hres
!= ERROR_SUCCESS
)
723 CoTaskMemFree(*pszUserType
);
726 return REGDB_E_READREGDB
;
732 /***********************************************************************
733 * DoDragDrop [OLE32.@]
735 HRESULT WINAPI
DoDragDrop (
736 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
737 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
738 DWORD dwOKEffect
, /* [in] effects allowed by the source */
739 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
741 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
742 TrackerWindowInfo trackerInfo
;
743 HWND hwndTrackWindow
;
746 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
748 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
752 * Setup the drag n drop tracking window.
755 trackerInfo
.dataObject
= pDataObject
;
756 trackerInfo
.dropSource
= pDropSource
;
757 trackerInfo
.dwOKEffect
= dwOKEffect
;
758 trackerInfo
.pdwEffect
= pdwEffect
;
759 trackerInfo
.trackingDone
= FALSE
;
760 trackerInfo
.escPressed
= FALSE
;
761 trackerInfo
.curDragTargetHWND
= 0;
762 trackerInfo
.curTargetHWND
= 0;
763 trackerInfo
.curDragTarget
= 0;
765 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
766 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
767 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
773 * Capture the mouse input
775 SetCapture(hwndTrackWindow
);
780 * Pump messages. All mouse input should go to the capture window.
782 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
784 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
785 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
786 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
788 if ( (msg
.message
>= WM_KEYFIRST
) &&
789 (msg
.message
<= WM_KEYLAST
) )
792 * When keyboard messages are sent to windows on this thread, we
793 * want to ignore notify the drop source that the state changed.
794 * in the case of the Escape key, we also notify the drop source
795 * we give it a special meaning.
797 if ( (msg
.message
==WM_KEYDOWN
) &&
798 (msg
.wParam
==VK_ESCAPE
) )
800 trackerInfo
.escPressed
= TRUE
;
804 * Notify the drop source.
806 OLEDD_TrackStateChange(&trackerInfo
);
811 * Dispatch the messages only when it's not a keyboard message.
813 DispatchMessageW(&msg
);
817 /* re-post the quit message to outer message loop */
818 if (msg
.message
== WM_QUIT
)
819 PostQuitMessage(msg
.wParam
);
821 * Destroy the temporary window.
823 DestroyWindow(hwndTrackWindow
);
825 return trackerInfo
.returnValue
;
831 /***********************************************************************
832 * OleQueryLinkFromData [OLE32.@]
834 HRESULT WINAPI
OleQueryLinkFromData(
835 IDataObject
* pSrcDataObject
)
837 FIXME("(%p),stub!\n", pSrcDataObject
);
841 /***********************************************************************
842 * OleRegGetMiscStatus [OLE32.@]
844 HRESULT WINAPI
OleRegGetMiscStatus(
849 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
850 static const WCHAR dfmtW
[] = {'%','d',0};
858 * Build the key name we're looking for
860 sprintfW( keyName
, clsidfmtW
,
861 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
862 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
863 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
865 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwAspect
, pdwStatus
);
867 if (!pdwStatus
) return E_INVALIDARG
;
871 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
874 * Open the class id Key
876 result
= open_classes_key(HKEY_CLASSES_ROOT
, keyName
, MAXIMUM_ALLOWED
, &clsidKey
);
877 if (result
!= ERROR_SUCCESS
)
878 return REGDB_E_CLASSNOTREG
;
883 result
= open_classes_key(clsidKey
, miscstatusW
, MAXIMUM_ALLOWED
, &miscStatusKey
);
884 if (result
!= ERROR_SUCCESS
)
886 RegCloseKey(clsidKey
);
891 * Read the default value
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
, MAXIMUM_ALLOWED
, &aspectKey
);
901 if (result
== ERROR_SUCCESS
)
903 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
904 RegCloseKey(aspectKey
);
910 RegCloseKey(miscStatusKey
);
911 RegCloseKey(clsidKey
);
916 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
920 IEnumOLEVERB IEnumOLEVERB_iface
;
927 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
929 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
932 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
933 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
935 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
936 if (IsEqualIID(riid
, &IID_IUnknown
) ||
937 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
939 IEnumOLEVERB_AddRef(iface
);
943 return E_NOINTERFACE
;
946 static ULONG WINAPI
EnumOLEVERB_AddRef(
949 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
951 return InterlockedIncrement(&This
->ref
);
954 static ULONG WINAPI
EnumOLEVERB_Release(
957 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
958 LONG refs
= InterlockedDecrement(&This
->ref
);
962 RegCloseKey(This
->hkeyVerb
);
963 HeapFree(GetProcessHeap(), 0, This
);
968 static HRESULT WINAPI
EnumOLEVERB_Next(
969 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
972 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
975 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
980 for (; celt
; celt
--, rgelt
++)
985 LPWSTR pwszMenuFlags
;
987 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
988 if (res
== ERROR_NO_MORE_ITEMS
)
993 else if (res
!= ERROR_SUCCESS
)
995 ERR("RegEnumKeyW failed with error %d\n", res
);
996 hr
= REGDB_E_READREGDB
;
999 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
1000 if (res
!= ERROR_SUCCESS
)
1002 ERR("RegQueryValueW failed with error %d\n", res
);
1003 hr
= REGDB_E_READREGDB
;
1006 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
1012 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
1013 if (res
!= ERROR_SUCCESS
)
1015 ERR("RegQueryValueW failed with error %d\n", res
);
1016 hr
= REGDB_E_READREGDB
;
1017 CoTaskMemFree(pwszOLEVERB
);
1021 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
1022 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
1025 hr
= OLEOBJ_E_INVALIDVERB
;
1026 CoTaskMemFree(pwszOLEVERB
);
1029 /* nul terminate the name string and advance to first character */
1030 *pwszMenuFlags
= '\0';
1032 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
1035 hr
= OLEOBJ_E_INVALIDVERB
;
1036 CoTaskMemFree(pwszOLEVERB
);
1039 /* nul terminate the menu string and advance to first character */
1040 *pwszAttribs
= '\0';
1043 /* fill out structure for this verb */
1044 rgelt
->lVerb
= atolW(wszSubKey
);
1045 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1046 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
1047 rgelt
->grfAttribs
= atolW(pwszAttribs
);
1056 static HRESULT WINAPI
EnumOLEVERB_Skip(
1057 IEnumOLEVERB
*iface
, ULONG celt
)
1059 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1061 TRACE("(%d)\n", celt
);
1063 This
->index
+= celt
;
1067 static HRESULT WINAPI
EnumOLEVERB_Reset(
1068 IEnumOLEVERB
*iface
)
1070 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1078 static HRESULT WINAPI
EnumOLEVERB_Clone(
1079 IEnumOLEVERB
*iface
,
1080 IEnumOLEVERB
**ppenum
)
1082 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1084 TRACE("(%p)\n", ppenum
);
1085 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1086 return HRESULT_FROM_WIN32(GetLastError());
1087 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1090 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1092 EnumOLEVERB_QueryInterface
,
1094 EnumOLEVERB_Release
,
1101 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1103 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1106 RegCloseKey(hkeyVerb
);
1107 return E_OUTOFMEMORY
;
1109 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1111 This
->index
= index
;
1112 This
->hkeyVerb
= hkeyVerb
;
1113 *ppenum
= &This
->IEnumOLEVERB_iface
;
1117 /***********************************************************************
1118 * OleRegEnumVerbs [OLE32.@]
1120 * Enumerates verbs associated with a class stored in the registry.
1123 * clsid [I] Class ID to enumerate the verbs for.
1124 * ppenum [O] Enumerator.
1128 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1129 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1130 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1131 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1133 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1138 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1140 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1142 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1145 if (res
== REGDB_E_CLASSNOTREG
)
1146 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1147 else if (res
== REGDB_E_KEYMISSING
)
1148 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1150 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1151 debugstr_guid(clsid
), res
);
1155 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1156 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1157 if (res
!= ERROR_SUCCESS
)
1159 ERR("failed to get subkey count with error %d\n", GetLastError());
1160 return REGDB_E_READREGDB
;
1165 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1166 RegCloseKey(hkeyVerb
);
1167 return OLEOBJ_E_NOVERBS
;
1170 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1173 /******************************************************************************
1174 * OleSetContainedObject [OLE32.@]
1176 HRESULT WINAPI
OleSetContainedObject(
1180 IRunnableObject
* runnable
= NULL
;
1183 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1185 hres
= IUnknown_QueryInterface(pUnknown
,
1186 &IID_IRunnableObject
,
1189 if (SUCCEEDED(hres
))
1191 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1193 IRunnableObject_Release(runnable
);
1201 /******************************************************************************
1204 * Set the OLE object to the running state.
1207 * pUnknown [I] OLE object to run.
1211 * Failure: Any HRESULT code.
1213 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1215 IRunnableObject
*runable
;
1218 TRACE("(%p)\n", pUnknown
);
1220 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1222 return S_OK
; /* Appears to return no error. */
1224 hres
= IRunnableObject_Run(runable
, NULL
);
1225 IRunnableObject_Release(runable
);
1229 /******************************************************************************
1232 HRESULT WINAPI
OleLoad(
1235 LPOLECLIENTSITE pClientSite
,
1238 IPersistStorage
* persistStorage
= NULL
;
1240 IOleObject
* pOleObject
= NULL
;
1241 STATSTG storageInfo
;
1244 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1249 * TODO, Conversion ... OleDoAutoConvert
1253 * Get the class ID for the object.
1255 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1260 * Now, try and create the handler for the object
1262 hres
= CoCreateInstance(&storageInfo
.clsid
,
1264 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1269 * If that fails, as it will most times, load the default
1274 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1281 * If we couldn't find a handler... this is bad. Abort the whole thing.
1288 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1289 if (SUCCEEDED(hres
))
1292 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1297 * Initialize the object with its IPersistStorage interface.
1299 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1300 if (SUCCEEDED(hres
))
1302 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1304 IPersistStorage_Release(persistStorage
);
1305 persistStorage
= NULL
;
1308 if (SUCCEEDED(hres
) && pClientSite
)
1310 * Inform the new object of its client site.
1312 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1315 * Cleanup interfaces used internally
1318 IOleObject_Release(pOleObject
);
1320 if (SUCCEEDED(hres
))
1324 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1325 if (SUCCEEDED(hres1
))
1327 FIXME("handle OLE link\n");
1328 IOleLink_Release(pOleLink
);
1334 IUnknown_Release(pUnk
);
1343 /***********************************************************************
1346 HRESULT WINAPI
OleSave(
1347 LPPERSISTSTORAGE pPS
,
1354 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1357 * First, we transfer the class ID (if available)
1359 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1361 if (SUCCEEDED(hres
))
1363 WriteClassStg(pStg
, &objectClass
);
1367 * Then, we ask the object to save itself to the
1368 * storage. If it is successful, we commit the storage.
1370 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1372 if (SUCCEEDED(hres
))
1374 IStorage_Commit(pStg
,
1382 /******************************************************************************
1383 * OleLockRunning [OLE32.@]
1385 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1387 IRunnableObject
* runnable
= NULL
;
1390 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1392 hres
= IUnknown_QueryInterface(pUnknown
,
1393 &IID_IRunnableObject
,
1396 if (SUCCEEDED(hres
))
1398 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1400 IRunnableObject_Release(runnable
);
1409 /**************************************************************************
1410 * Internal methods to manage the shared OLE menu in response to the
1411 * OLE***MenuDescriptor API
1415 * OLEMenu_Initialize()
1417 * Initializes the OLEMENU data structures.
1419 static void OLEMenu_Initialize(void)
1424 * OLEMenu_UnInitialize()
1426 * Releases the OLEMENU data structures.
1428 static void OLEMenu_UnInitialize(void)
1432 /*************************************************************************
1433 * OLEMenu_InstallHooks
1434 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1436 * RETURNS: TRUE if message hooks were successfully installed
1439 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1441 OleMenuHookItem
*pHookItem
;
1443 /* Create an entry for the hook table */
1444 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1445 sizeof(OleMenuHookItem
)) ) )
1448 pHookItem
->tid
= tid
;
1449 pHookItem
->hHeap
= GetProcessHeap();
1450 pHookItem
->CallWndProc_hHook
= NULL
;
1452 /* Install a thread scope message hook for WH_GETMESSAGE */
1453 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1454 0, GetCurrentThreadId() );
1455 if ( !pHookItem
->GetMsg_hHook
)
1458 /* Install a thread scope message hook for WH_CALLWNDPROC */
1459 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1460 0, GetCurrentThreadId() );
1461 if ( !pHookItem
->CallWndProc_hHook
)
1464 /* Insert the hook table entry */
1465 pHookItem
->next
= hook_list
;
1466 hook_list
= pHookItem
;
1471 /* Unhook any hooks */
1472 if ( pHookItem
->GetMsg_hHook
)
1473 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1474 if ( pHookItem
->CallWndProc_hHook
)
1475 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1476 /* Release the hook table entry */
1477 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1482 /*************************************************************************
1483 * OLEMenu_UnInstallHooks
1484 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1486 * RETURNS: TRUE if message hooks were successfully installed
1489 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1491 OleMenuHookItem
*pHookItem
= NULL
;
1492 OleMenuHookItem
**ppHook
= &hook_list
;
1496 if ((*ppHook
)->tid
== tid
)
1498 pHookItem
= *ppHook
;
1499 *ppHook
= pHookItem
->next
;
1502 ppHook
= &(*ppHook
)->next
;
1504 if (!pHookItem
) return FALSE
;
1506 /* Uninstall the hooks installed for this thread */
1507 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1509 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1512 /* Release the hook table entry */
1513 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1518 /* Release the hook table entry */
1519 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1524 /*************************************************************************
1525 * OLEMenu_IsHookInstalled
1526 * Tests if OLEMenu hooks have been installed for a thread
1528 * RETURNS: The pointer and index of the hook table entry for the tid
1529 * NULL and -1 for the index if no hooks were installed for this thread
1531 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1533 OleMenuHookItem
*pHookItem
;
1535 /* Do a simple linear search for an entry whose tid matches ours.
1536 * We really need a map but efficiency is not a concern here. */
1537 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1539 if ( tid
== pHookItem
->tid
)
1546 /***********************************************************************
1547 * OLEMenu_FindMainMenuIndex
1549 * Used by OLEMenu API to find the top level group a menu item belongs to.
1550 * On success pnPos contains the index of the item in the top level menu group
1552 * RETURNS: TRUE if the ID was found, FALSE on failure
1554 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1558 nItems
= GetMenuItemCount( hMainMenu
);
1560 for (i
= 0; i
< nItems
; i
++)
1564 /* Is the current item a submenu? */
1565 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1567 /* If the handle is the same we're done */
1568 if ( hsubmenu
== hPopupMenu
)
1574 /* Recursively search without updating pnPos */
1575 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1587 /***********************************************************************
1588 * OLEMenu_SetIsServerMenu
1590 * Checks whether a popup menu belongs to a shared menu group which is
1591 * owned by the server, and sets the menu descriptor state accordingly.
1592 * All menu messages from these groups should be routed to the server.
1594 * RETURNS: TRUE if the popup menu is part of a server owned group
1595 * FALSE if the popup menu is part of a container owned group
1597 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1599 UINT nPos
= 0, nWidth
, i
;
1601 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1603 /* Don't bother searching if the popup is the combined menu itself */
1604 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1607 /* Find the menu item index in the shared OLE menu that this item belongs to */
1608 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1611 /* The group widths array has counts for the number of elements
1612 * in the groups File, Edit, Container, Object, Window, Help.
1613 * The Edit, Object & Help groups belong to the server object
1614 * and the other three belong to the container.
1615 * Loop through the group widths and locate the group we are a member of.
1617 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1619 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1620 if ( nPos
< nWidth
)
1622 /* Odd elements are server menu widths */
1623 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1628 return pOleMenuDescriptor
->bIsServerItem
;
1631 /*************************************************************************
1632 * OLEMenu_CallWndProc
1633 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1634 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1636 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1639 HOLEMENU hOleMenu
= 0;
1640 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1641 OleMenuHookItem
*pHookItem
= NULL
;
1644 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1646 /* Check if we're being asked to process the message */
1647 if ( HC_ACTION
!= code
)
1650 /* Retrieve the current message being dispatched from lParam */
1651 pMsg
= (LPCWPSTRUCT
)lParam
;
1653 /* Check if the message is destined for a window we are interested in:
1654 * If the window has an OLEMenu property we may need to dispatch
1655 * the menu message to its active objects window instead. */
1657 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1661 /* Get the menu descriptor */
1662 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1663 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1666 /* Process menu messages */
1667 switch( pMsg
->message
)
1671 /* Reset the menu descriptor state */
1672 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1674 /* Send this message to the server as well */
1675 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1676 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1680 case WM_INITMENUPOPUP
:
1682 /* Save the state for whether this is a server owned menu */
1683 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1689 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1690 if ( fuFlags
& MF_SYSMENU
)
1693 /* Save the state for whether this is a server owned popup menu */
1694 else if ( fuFlags
& MF_POPUP
)
1695 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1702 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1703 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1704 goto NEXTHOOK
; /* Not a menu message */
1713 /* If the message was for the server dispatch it accordingly */
1714 if ( pOleMenuDescriptor
->bIsServerItem
)
1716 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1717 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1721 if ( pOleMenuDescriptor
)
1722 GlobalUnlock( hOleMenu
);
1724 /* Lookup the hook item for the current thread */
1725 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1727 /* This should never fail!! */
1728 WARN("could not retrieve hHook for current thread!\n" );
1732 /* Pass on the message to the next hooker */
1733 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1736 /*************************************************************************
1737 * OLEMenu_GetMsgProc
1738 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1739 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1741 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1744 HOLEMENU hOleMenu
= 0;
1745 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1746 OleMenuHookItem
*pHookItem
= NULL
;
1749 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1751 /* Check if we're being asked to process a messages */
1752 if ( HC_ACTION
!= code
)
1755 /* Retrieve the current message being dispatched from lParam */
1756 pMsg
= (LPMSG
)lParam
;
1758 /* Check if the message is destined for a window we are interested in:
1759 * If the window has an OLEMenu property we may need to dispatch
1760 * the menu message to its active objects window instead. */
1762 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1766 /* Process menu messages */
1767 switch( pMsg
->message
)
1771 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1773 goto NEXTHOOK
; /* Not a menu message */
1780 /* Get the menu descriptor */
1781 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1782 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1785 /* If the message was for the server dispatch it accordingly */
1786 if ( pOleMenuDescriptor
->bIsServerItem
)
1788 /* Change the hWnd in the message to the active objects hWnd.
1789 * The message loop which reads this message will automatically
1790 * dispatch it to the embedded objects window. */
1791 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1795 if ( pOleMenuDescriptor
)
1796 GlobalUnlock( hOleMenu
);
1798 /* Lookup the hook item for the current thread */
1799 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1801 /* This should never fail!! */
1802 WARN("could not retrieve hHook for current thread!\n" );
1806 /* Pass on the message to the next hooker */
1807 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1810 /***********************************************************************
1811 * OleCreateMenuDescriptor [OLE32.@]
1812 * Creates an OLE menu descriptor for OLE to use when dispatching
1813 * menu messages and commands.
1816 * hmenuCombined - Handle to the objects combined menu
1817 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1820 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1821 HMENU hmenuCombined
,
1822 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1825 OleMenuDescriptor
*pOleMenuDescriptor
;
1828 if ( !hmenuCombined
|| !lpMenuWidths
)
1831 /* Create an OLE menu descriptor */
1832 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1833 sizeof(OleMenuDescriptor
) ) ) )
1836 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1837 if ( !pOleMenuDescriptor
)
1840 /* Initialize menu group widths and hmenu */
1841 for ( i
= 0; i
< 6; i
++ )
1842 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1844 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1845 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1846 GlobalUnlock( hOleMenu
);
1851 /***********************************************************************
1852 * OleDestroyMenuDescriptor [OLE32.@]
1853 * Destroy the shared menu descriptor
1855 HRESULT WINAPI
OleDestroyMenuDescriptor(
1856 HOLEMENU hmenuDescriptor
)
1858 if ( hmenuDescriptor
)
1859 GlobalFree( hmenuDescriptor
);
1863 /***********************************************************************
1864 * OleSetMenuDescriptor [OLE32.@]
1865 * Installs or removes OLE dispatching code for the containers frame window.
1868 * hOleMenu Handle to composite menu descriptor
1869 * hwndFrame Handle to containers frame window
1870 * hwndActiveObject Handle to objects in-place activation window
1871 * lpFrame Pointer to IOleInPlaceFrame on containers window
1872 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1875 * S_OK - menu installed correctly
1876 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1879 * The lpFrame and lpActiveObject parameters are currently ignored
1880 * OLE should install context sensitive help F1 filtering for the app when
1881 * these are non null.
1883 HRESULT WINAPI
OleSetMenuDescriptor(
1886 HWND hwndActiveObject
,
1887 LPOLEINPLACEFRAME lpFrame
,
1888 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1890 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1893 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1894 return E_INVALIDARG
;
1896 if ( lpFrame
|| lpActiveObject
)
1898 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1906 /* Set up a message hook to intercept the containers frame window messages.
1907 * The message filter is responsible for dispatching menu messages from the
1908 * shared menu which are intended for the object.
1911 if ( hOleMenu
) /* Want to install dispatching code */
1913 /* If OLEMenu hooks are already installed for this thread, fail
1914 * Note: This effectively means that OleSetMenuDescriptor cannot
1915 * be called twice in succession on the same frame window
1916 * without first calling it with a null hOleMenu to uninstall
1918 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1921 /* Get the menu descriptor */
1922 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1923 if ( !pOleMenuDescriptor
)
1924 return E_UNEXPECTED
;
1926 /* Update the menu descriptor */
1927 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1928 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1930 GlobalUnlock( hOleMenu
);
1931 pOleMenuDescriptor
= NULL
;
1933 /* Add a menu descriptor windows property to the frame window */
1934 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1936 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1937 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1940 else /* Want to uninstall dispatching code */
1942 /* Uninstall the hooks */
1943 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1946 /* Remove the menu descriptor property from the frame window */
1947 RemovePropW( hwndFrame
, prop_olemenuW
);
1953 /******************************************************************************
1954 * IsAccelerator [OLE32.@]
1955 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1957 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1962 if(!lpMsg
) return FALSE
;
1965 WARN_(accel
)("NULL accel handle\n");
1968 if((lpMsg
->message
!= WM_KEYDOWN
&&
1969 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1970 lpMsg
->message
!= WM_SYSCHAR
&&
1971 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1972 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1973 if (NULL
== lpAccelTbl
)
1977 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1979 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1980 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1984 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1985 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1986 hAccel
, cAccelEntries
,
1987 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1988 for(i
= 0; i
< cAccelEntries
; i
++)
1990 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1993 if(lpMsg
->message
== WM_CHAR
)
1995 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1997 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
2003 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
2006 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
2007 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
2008 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
2009 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
2010 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
2011 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
2012 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
2016 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2018 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2019 { /* ^^ ALT pressed */
2020 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2028 WARN_(accel
)("couldn't translate accelerator key\n");
2029 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2033 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2034 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2038 /***********************************************************************
2039 * ReleaseStgMedium [OLE32.@]
2041 void WINAPI
ReleaseStgMedium(
2044 switch (pmedium
->tymed
)
2048 if ( (pmedium
->pUnkForRelease
==0) &&
2049 (pmedium
->u
.hGlobal
!=0) )
2050 GlobalFree(pmedium
->u
.hGlobal
);
2055 if (pmedium
->u
.lpszFileName
!=0)
2057 if (pmedium
->pUnkForRelease
==0)
2059 DeleteFileW(pmedium
->u
.lpszFileName
);
2062 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2068 if (pmedium
->u
.pstm
!=0)
2070 IStream_Release(pmedium
->u
.pstm
);
2074 case TYMED_ISTORAGE
:
2076 if (pmedium
->u
.pstg
!=0)
2078 IStorage_Release(pmedium
->u
.pstg
);
2084 if ( (pmedium
->pUnkForRelease
==0) &&
2085 (pmedium
->u
.hBitmap
!=0) )
2086 DeleteObject(pmedium
->u
.hBitmap
);
2091 if ( (pmedium
->pUnkForRelease
==0) &&
2092 (pmedium
->u
.hMetaFilePict
!=0) )
2094 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2095 DeleteMetaFile(pMP
->hMF
);
2096 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2097 GlobalFree(pmedium
->u
.hMetaFilePict
);
2103 if ( (pmedium
->pUnkForRelease
==0) &&
2104 (pmedium
->u
.hEnhMetaFile
!=0) )
2106 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2114 pmedium
->tymed
=TYMED_NULL
;
2117 * After cleaning up, the unknown is released
2119 if (pmedium
->pUnkForRelease
!=0)
2121 IUnknown_Release(pmedium
->pUnkForRelease
);
2122 pmedium
->pUnkForRelease
= 0;
2127 * OLEDD_Initialize()
2129 * Initializes the OLE drag and drop data structures.
2131 static void OLEDD_Initialize(void)
2135 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2136 wndClass
.style
= CS_GLOBALCLASS
;
2137 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2138 wndClass
.cbClsExtra
= 0;
2139 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2140 wndClass
.hCursor
= 0;
2141 wndClass
.hbrBackground
= 0;
2142 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2144 RegisterClassW (&wndClass
);
2148 * OLEDD_DragTrackerWindowProc()
2150 * This method is the WindowProcedure of the drag n drop tracking
2151 * window. During a drag n Drop operation, an invisible window is created
2152 * to receive the user input and act upon it. This procedure is in charge
2156 #define DRAG_TIMER_ID 1
2158 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2168 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2170 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2171 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2180 case WM_LBUTTONDOWN
:
2181 case WM_MBUTTONDOWN
:
2182 case WM_RBUTTONDOWN
:
2184 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2185 if (trackerInfo
->trackingDone
) break;
2186 OLEDD_TrackStateChange(trackerInfo
);
2191 KillTimer(hwnd
, DRAG_TIMER_ID
);
2197 * This is a window proc after all. Let's call the default.
2199 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2203 * OLEDD_TrackStateChange()
2205 * This method is invoked while a drag and drop operation is in effect.
2208 * trackerInfo - Pointer to the structure identifying the
2209 * drag & drop operation that is currently
2212 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2214 HWND hwndNewTarget
= 0;
2219 * Get the handle of the window under the mouse
2221 pt
.x
= trackerInfo
->curMousePos
.x
;
2222 pt
.y
= trackerInfo
->curMousePos
.y
;
2223 hwndNewTarget
= WindowFromPoint(pt
);
2225 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2226 trackerInfo
->escPressed
,
2227 trackerInfo
->dwKeyState
);
2230 * Every time, we re-initialize the effects passed to the
2231 * IDropTarget to the effects allowed by the source.
2233 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2236 * If we are hovering over the same target as before, send the
2237 * DragOver notification
2239 if ( (trackerInfo
->curDragTarget
!= 0) &&
2240 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2242 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2243 trackerInfo
->dwKeyState
,
2244 trackerInfo
->curMousePos
,
2245 trackerInfo
->pdwEffect
);
2246 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2251 * If we changed window, we have to notify our old target and check for
2254 if (trackerInfo
->curDragTarget
)
2255 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2258 * Make sure we're hovering over a window.
2263 * Find-out if there is a drag target under the mouse
2265 HWND next_target_wnd
= hwndNewTarget
;
2267 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2269 while (next_target_wnd
&& !is_droptarget(next_target_wnd
))
2270 next_target_wnd
= GetParent(next_target_wnd
);
2272 if (next_target_wnd
) hwndNewTarget
= next_target_wnd
;
2274 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2275 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2276 trackerInfo
->curDragTarget
= get_droptarget_pointer(hwndNewTarget
);
2279 * If there is, notify it that we just dragged-in
2281 if (trackerInfo
->curDragTarget
)
2283 hr
= IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2284 trackerInfo
->dataObject
,
2285 trackerInfo
->dwKeyState
,
2286 trackerInfo
->curMousePos
,
2287 trackerInfo
->pdwEffect
);
2288 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2290 /* failed DragEnter() means invalid target */
2293 trackerInfo
->curDragTargetHWND
= 0;
2294 trackerInfo
->curTargetHWND
= 0;
2295 IDropTarget_Release(trackerInfo
->curDragTarget
);
2296 trackerInfo
->curDragTarget
= 0;
2303 * The mouse is not over a window so we don't track anything.
2305 trackerInfo
->curDragTargetHWND
= 0;
2306 trackerInfo
->curTargetHWND
= 0;
2307 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2308 trackerInfo
->curDragTarget
= 0;
2313 * Now that we have done that, we have to tell the source to give
2314 * us feedback on the work being done by the target. If we don't
2315 * have a target, simulate no effect.
2317 if (trackerInfo
->curDragTarget
==0)
2319 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2322 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2323 *trackerInfo
->pdwEffect
);
2326 * When we ask for feedback from the drop source, sometimes it will
2327 * do all the necessary work and sometimes it will not handle it
2328 * when that's the case, we must display the standard drag and drop
2331 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2335 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2337 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(2));
2339 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2341 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(3));
2343 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2345 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(4));
2349 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(1));
2356 * All the return valued will stop the operation except the S_OK
2359 if (trackerInfo
->returnValue
!=S_OK
)
2362 * Make sure the message loop in DoDragDrop stops
2364 trackerInfo
->trackingDone
= TRUE
;
2367 * Release the mouse in case the drop target decides to show a popup
2368 * or a menu or something.
2373 * If we end-up over a target, drop the object in the target or
2374 * inform the target that the operation was cancelled.
2376 if (trackerInfo
->curDragTarget
)
2378 switch (trackerInfo
->returnValue
)
2381 * If the source wants us to complete the operation, we tell
2382 * the drop target that we just dropped the object in it.
2384 case DRAGDROP_S_DROP
:
2385 if (*trackerInfo
->pdwEffect
!= DROPEFFECT_NONE
)
2387 hr
= IDropTarget_Drop(trackerInfo
->curDragTarget
, trackerInfo
->dataObject
,
2388 trackerInfo
->dwKeyState
, trackerInfo
->curMousePos
, trackerInfo
->pdwEffect
);
2390 trackerInfo
->returnValue
= hr
;
2393 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2397 * If the source told us that we should cancel, fool the drop
2398 * target by telling it that the mouse left its window.
2399 * Also set the drop effect to "NONE" in case the application
2400 * ignores the result of DoDragDrop.
2402 case DRAGDROP_S_CANCEL
:
2403 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2404 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2412 * OLEDD_GetButtonState()
2414 * This method will use the current state of the keyboard to build
2415 * a button state mask equivalent to the one passed in the
2416 * WM_MOUSEMOVE wParam.
2418 static DWORD
OLEDD_GetButtonState(void)
2420 BYTE keyboardState
[256];
2423 GetKeyboardState(keyboardState
);
2425 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2426 keyMask
|= MK_SHIFT
;
2428 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2429 keyMask
|= MK_CONTROL
;
2431 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2434 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2435 keyMask
|= MK_LBUTTON
;
2437 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2438 keyMask
|= MK_RBUTTON
;
2440 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2441 keyMask
|= MK_MBUTTON
;
2447 * OLEDD_GetButtonState()
2449 * This method will read the default value of the registry key in
2450 * parameter and extract a DWORD value from it. The registry key value
2451 * can be in a string key or a DWORD key.
2454 * regKey - Key to read the default value from
2455 * pdwValue - Pointer to the location where the DWORD
2456 * value is returned. This value is not modified
2457 * if the value is not found.
2460 static void OLEUTL_ReadRegistryDWORDValue(
2465 DWORD cbData
= sizeof(buffer
);
2469 lres
= RegQueryValueExW(regKey
,
2476 if (lres
==ERROR_SUCCESS
)
2481 *pdwValue
= *(DWORD
*)buffer
;
2486 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2492 /******************************************************************************
2495 * The operation of this function is documented literally in the WinAPI
2496 * documentation to involve a QueryInterface for the IViewObject interface,
2497 * followed by a call to IViewObject::Draw.
2499 HRESULT WINAPI
OleDraw(
2506 IViewObject
*viewobject
;
2508 if (!pUnk
) return E_INVALIDARG
;
2510 hres
= IUnknown_QueryInterface(pUnk
,
2512 (void**)&viewobject
);
2513 if (SUCCEEDED(hres
))
2515 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2516 IViewObject_Release(viewobject
);
2520 return DV_E_NOIVIEWOBJECT
;
2523 /***********************************************************************
2524 * OleTranslateAccelerator [OLE32.@]
2526 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2527 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2531 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2533 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2534 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2539 /******************************************************************************
2540 * OleCreate [OLE32.@]
2543 HRESULT WINAPI
OleCreate(
2547 LPFORMATETC pFormatEtc
,
2548 LPOLECLIENTSITE pClientSite
,
2553 IUnknown
* pUnk
= NULL
;
2554 IOleObject
*pOleObject
= NULL
;
2556 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2557 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2559 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2561 if (SUCCEEDED(hres
))
2562 hres
= IStorage_SetClass(pStg
, rclsid
);
2564 if (pClientSite
&& SUCCEEDED(hres
))
2566 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2567 if (SUCCEEDED(hres
))
2570 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2574 if (SUCCEEDED(hres
))
2576 IPersistStorage
* pPS
;
2577 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2579 TRACE("trying to set stg %p\n", pStg
);
2580 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2581 TRACE("-- result 0x%08x\n", hres
);
2582 IPersistStorage_Release(pPS
);
2586 if (pClientSite
&& SUCCEEDED(hres
))
2588 TRACE("trying to set clientsite %p\n", pClientSite
);
2589 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2590 TRACE("-- result 0x%08x\n", hres
);
2594 IOleObject_Release(pOleObject
);
2596 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2599 IRunnableObject
*pRunnable
;
2600 IOleCache
*pOleCache
;
2603 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2604 if (SUCCEEDED(hres2
))
2606 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2607 IRunnableObject_Release(pRunnable
);
2610 if (SUCCEEDED(hres
))
2612 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2613 if (SUCCEEDED(hres2
))
2616 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2620 pfe
.dwAspect
= DVASPECT_CONTENT
;
2622 pfe
.tymed
= TYMED_NULL
;
2623 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2626 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2627 IOleCache_Release(pOleCache
);
2632 if (FAILED(hres
) && pUnk
)
2634 IUnknown_Release(pUnk
);
2640 TRACE("-- %p\n", pUnk
);
2644 /******************************************************************************
2645 * OleGetAutoConvert [OLE32.@]
2647 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2649 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2651 WCHAR buf
[CHARS_IN_GUID
];
2655 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2660 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2662 res
= REGDB_E_KEYMISSING
;
2665 res
= CLSIDFromString(buf
, pClsidNew
);
2667 if (hkey
) RegCloseKey(hkey
);
2671 /******************************************************************************
2672 * OleSetAutoConvert [OLE32.@]
2674 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2676 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2678 WCHAR szClsidNew
[CHARS_IN_GUID
];
2681 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2683 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2686 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2687 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2689 res
= REGDB_E_WRITEREGDB
;
2694 if (hkey
) RegCloseKey(hkey
);
2698 /******************************************************************************
2699 * OleDoAutoConvert [OLE32.@]
2701 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2703 WCHAR
*user_type_old
, *user_type_new
;
2709 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2711 *pClsidNew
= CLSID_NULL
;
2713 return E_INVALIDARG
;
2714 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2718 *pClsidNew
= stat
.clsid
;
2719 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2723 hr
= IStorage_SetClass(pStg
, &clsid
);
2727 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2730 user_type_new
= NULL
;
2733 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2735 user_type_new
= NULL
;
2737 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2738 CoTaskMemFree(user_type_new
);
2741 CoTaskMemFree(user_type_old
);
2742 IStorage_SetClass(pStg
, &stat
.clsid
);
2746 hr
= SetConvertStg(pStg
, TRUE
);
2749 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2750 IStorage_SetClass(pStg
, &stat
.clsid
);
2754 CoTaskMemFree(user_type_old
);
2758 /******************************************************************************
2759 * OleIsRunning [OLE32.@]
2761 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2763 IRunnableObject
*pRunnable
;
2767 TRACE("(%p)\n", object
);
2769 if (!object
) return FALSE
;
2771 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2774 running
= IRunnableObject_IsRunning(pRunnable
);
2775 IRunnableObject_Release(pRunnable
);
2779 /***********************************************************************
2780 * OleNoteObjectVisible [OLE32.@]
2782 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2784 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2785 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2789 /***********************************************************************
2790 * OLE_FreeClipDataArray [internal]
2793 * frees the data associated with an array of CLIPDATAs
2795 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2798 for (i
= 0; i
< count
; i
++)
2799 if (pClipDataArray
[i
].pClipData
)
2800 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2803 /***********************************************************************
2804 * PropSysAllocString [OLE32.@]
2806 * Forward to oleaut32.
2808 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2810 return SysAllocString(str
);
2813 /***********************************************************************
2814 * PropSysFreeString [OLE32.@]
2816 * Forward to oleaut32.
2818 void WINAPI
PropSysFreeString(LPOLESTR str
)
2823 /******************************************************************************
2824 * Check if a PROPVARIANT's type is valid.
2826 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2858 case VT_STREAMED_OBJECT
:
2859 case VT_STORED_OBJECT
:
2860 case VT_BLOB_OBJECT
:
2863 case VT_I1
|VT_VECTOR
:
2864 case VT_I2
|VT_VECTOR
:
2865 case VT_I4
|VT_VECTOR
:
2866 case VT_I8
|VT_VECTOR
:
2867 case VT_R4
|VT_VECTOR
:
2868 case VT_R8
|VT_VECTOR
:
2869 case VT_CY
|VT_VECTOR
:
2870 case VT_DATE
|VT_VECTOR
:
2871 case VT_BSTR
|VT_VECTOR
:
2872 case VT_ERROR
|VT_VECTOR
:
2873 case VT_BOOL
|VT_VECTOR
:
2874 case VT_VARIANT
|VT_VECTOR
:
2875 case VT_UI1
|VT_VECTOR
:
2876 case VT_UI2
|VT_VECTOR
:
2877 case VT_UI4
|VT_VECTOR
:
2878 case VT_UI8
|VT_VECTOR
:
2879 case VT_LPSTR
|VT_VECTOR
:
2880 case VT_LPWSTR
|VT_VECTOR
:
2881 case VT_FILETIME
|VT_VECTOR
:
2882 case VT_CF
|VT_VECTOR
:
2883 case VT_CLSID
|VT_VECTOR
:
2886 WARN("Bad type %d\n", vt
);
2887 return STG_E_INVALIDPARAMETER
;
2890 /***********************************************************************
2891 * PropVariantClear [OLE32.@]
2893 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2897 TRACE("(%p)\n", pvar
);
2902 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2905 memset(pvar
, 0, sizeof(*pvar
));
2935 case VT_STREAMED_OBJECT
:
2937 case VT_STORED_OBJECT
:
2938 if (pvar
->u
.pStream
)
2939 IStream_Release(pvar
->u
.pStream
);
2944 /* pick an arbitrary typed pointer - we don't care about the type
2945 * as we are just freeing it */
2946 CoTaskMemFree(pvar
->u
.puuid
);
2949 case VT_BLOB_OBJECT
:
2950 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2953 PropSysFreeString(pvar
->u
.bstrVal
);
2956 if (pvar
->u
.pclipdata
)
2958 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2959 CoTaskMemFree(pvar
->u
.pclipdata
);
2963 if (pvar
->vt
& VT_VECTOR
)
2967 switch (pvar
->vt
& ~VT_VECTOR
)
2970 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2973 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2976 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2977 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2980 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2981 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2984 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2985 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2988 if (pvar
->vt
& ~VT_VECTOR
)
2990 /* pick an arbitrary VT_VECTOR structure - they all have the same
2992 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2997 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2998 hr
= STG_E_INVALIDPARAMETER
;
3002 memset(pvar
, 0, sizeof(*pvar
));
3006 /***********************************************************************
3007 * PropVariantCopy [OLE32.@]
3009 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
3010 const PROPVARIANT
*pvarSrc
) /* [in] */
3015 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
3017 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
3019 return DISP_E_BADVARTYPE
;
3021 /* this will deal with most cases */
3022 *pvarDest
= *pvarSrc
;
3050 case VT_STREAMED_OBJECT
:
3052 case VT_STORED_OBJECT
:
3053 if (pvarDest
->u
.pStream
)
3054 IStream_AddRef(pvarDest
->u
.pStream
);
3057 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
3058 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
3061 if (pvarSrc
->u
.pszVal
)
3063 len
= strlen(pvarSrc
->u
.pszVal
);
3064 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
3065 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
3069 if (pvarSrc
->u
.pwszVal
)
3071 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
3072 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
3073 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
3077 case VT_BLOB_OBJECT
:
3078 if (pvarSrc
->u
.blob
.pBlobData
)
3080 len
= pvarSrc
->u
.blob
.cbSize
;
3081 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
3082 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
3086 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
3089 if (pvarSrc
->u
.pclipdata
)
3091 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
3092 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
3093 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
3094 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
3095 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
3096 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
3100 if (pvarSrc
->vt
& VT_VECTOR
)
3105 switch(pvarSrc
->vt
& ~VT_VECTOR
)
3107 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3108 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3109 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3110 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3111 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3112 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3113 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3114 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3115 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3116 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3117 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3118 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3119 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3120 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3121 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3122 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3123 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3124 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3125 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3126 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3127 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3130 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3131 return E_INVALIDARG
;
3133 len
= pvarSrc
->u
.capropvar
.cElems
;
3134 pvarDest
->u
.capropvar
.pElems
= len
? CoTaskMemAlloc(len
* elemSize
) : NULL
;
3135 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3137 for (i
= 0; i
< len
; i
++)
3138 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3140 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3142 FIXME("Copy clipformats\n");
3144 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3146 for (i
= 0; i
< len
; i
++)
3147 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3149 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3152 for (i
= 0; i
< len
; i
++)
3154 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3155 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3156 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3157 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3160 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3163 for (i
= 0; i
< len
; i
++)
3165 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3167 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3168 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3169 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3173 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3176 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3182 /***********************************************************************
3183 * FreePropVariantArray [OLE32.@]
3185 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3186 PROPVARIANT
*rgvars
) /* [in/out] */
3190 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3193 return E_INVALIDARG
;
3195 for(i
= 0; i
< cVariants
; i
++)
3196 PropVariantClear(&rgvars
[i
]);
3201 /******************************************************************************
3202 * DllDebugObjectRPCHook (OLE32.@)
3203 * turns on and off internal debugging, pointer is only used on macintosh
3206 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)