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
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
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
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
);
1258 * Now, try and create the handler for the object
1260 hres
= CoCreateInstance(&storageInfo
.clsid
,
1262 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1267 * If that fails, as it will most times, load the default
1272 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1279 * If we couldn't find a handler... this is bad. Abort the whole thing.
1286 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1287 if (SUCCEEDED(hres
))
1290 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1295 * Initialize the object with its IPersistStorage interface.
1297 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1298 if (SUCCEEDED(hres
))
1300 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1302 IPersistStorage_Release(persistStorage
);
1303 persistStorage
= NULL
;
1306 if (SUCCEEDED(hres
) && pClientSite
)
1308 * Inform the new object of its client site.
1310 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1313 * Cleanup interfaces used internally
1316 IOleObject_Release(pOleObject
);
1318 if (SUCCEEDED(hres
))
1322 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1323 if (SUCCEEDED(hres1
))
1325 FIXME("handle OLE link\n");
1326 IOleLink_Release(pOleLink
);
1332 IUnknown_Release(pUnk
);
1341 /***********************************************************************
1344 HRESULT WINAPI
OleSave(
1345 LPPERSISTSTORAGE pPS
,
1352 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1355 * First, we transfer the class ID (if available)
1357 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1359 if (SUCCEEDED(hres
))
1361 WriteClassStg(pStg
, &objectClass
);
1365 * Then, we ask the object to save itself to the
1366 * storage. If it is successful, we commit the storage.
1368 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1370 if (SUCCEEDED(hres
))
1372 IStorage_Commit(pStg
,
1380 /******************************************************************************
1381 * OleLockRunning [OLE32.@]
1383 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1385 IRunnableObject
* runnable
= NULL
;
1388 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1390 hres
= IUnknown_QueryInterface(pUnknown
,
1391 &IID_IRunnableObject
,
1394 if (SUCCEEDED(hres
))
1396 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1398 IRunnableObject_Release(runnable
);
1407 /**************************************************************************
1408 * Internal methods to manage the shared OLE menu in response to the
1409 * OLE***MenuDescriptor API
1413 * OLEMenu_Initialize()
1415 * Initializes the OLEMENU data structures.
1417 static void OLEMenu_Initialize(void)
1422 * OLEMenu_UnInitialize()
1424 * Releases the OLEMENU data structures.
1426 static void OLEMenu_UnInitialize(void)
1430 /*************************************************************************
1431 * OLEMenu_InstallHooks
1432 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1434 * RETURNS: TRUE if message hooks were successfully installed
1437 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1439 OleMenuHookItem
*pHookItem
;
1441 /* Create an entry for the hook table */
1442 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1443 sizeof(OleMenuHookItem
)) ) )
1446 pHookItem
->tid
= tid
;
1447 pHookItem
->hHeap
= GetProcessHeap();
1448 pHookItem
->CallWndProc_hHook
= NULL
;
1450 /* Install a thread scope message hook for WH_GETMESSAGE */
1451 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1452 0, GetCurrentThreadId() );
1453 if ( !pHookItem
->GetMsg_hHook
)
1456 /* Install a thread scope message hook for WH_CALLWNDPROC */
1457 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1458 0, GetCurrentThreadId() );
1459 if ( !pHookItem
->CallWndProc_hHook
)
1462 /* Insert the hook table entry */
1463 pHookItem
->next
= hook_list
;
1464 hook_list
= pHookItem
;
1469 /* Unhook any hooks */
1470 if ( pHookItem
->GetMsg_hHook
)
1471 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1472 if ( pHookItem
->CallWndProc_hHook
)
1473 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1474 /* Release the hook table entry */
1475 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1480 /*************************************************************************
1481 * OLEMenu_UnInstallHooks
1482 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1484 * RETURNS: TRUE if message hooks were successfully installed
1487 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1489 OleMenuHookItem
*pHookItem
= NULL
;
1490 OleMenuHookItem
**ppHook
= &hook_list
;
1494 if ((*ppHook
)->tid
== tid
)
1496 pHookItem
= *ppHook
;
1497 *ppHook
= pHookItem
->next
;
1500 ppHook
= &(*ppHook
)->next
;
1502 if (!pHookItem
) return FALSE
;
1504 /* Uninstall the hooks installed for this thread */
1505 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1507 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1510 /* Release the hook table entry */
1511 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1516 /* Release the hook table entry */
1517 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1522 /*************************************************************************
1523 * OLEMenu_IsHookInstalled
1524 * Tests if OLEMenu hooks have been installed for a thread
1526 * RETURNS: The pointer and index of the hook table entry for the tid
1527 * NULL and -1 for the index if no hooks were installed for this thread
1529 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1531 OleMenuHookItem
*pHookItem
;
1533 /* Do a simple linear search for an entry whose tid matches ours.
1534 * We really need a map but efficiency is not a concern here. */
1535 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1537 if ( tid
== pHookItem
->tid
)
1544 /***********************************************************************
1545 * OLEMenu_FindMainMenuIndex
1547 * Used by OLEMenu API to find the top level group a menu item belongs to.
1548 * On success pnPos contains the index of the item in the top level menu group
1550 * RETURNS: TRUE if the ID was found, FALSE on failure
1552 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1556 nItems
= GetMenuItemCount( hMainMenu
);
1558 for (i
= 0; i
< nItems
; i
++)
1562 /* Is the current item a submenu? */
1563 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1565 /* If the handle is the same we're done */
1566 if ( hsubmenu
== hPopupMenu
)
1572 /* Recursively search without updating pnPos */
1573 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1585 /***********************************************************************
1586 * OLEMenu_SetIsServerMenu
1588 * Checks whether a popup menu belongs to a shared menu group which is
1589 * owned by the server, and sets the menu descriptor state accordingly.
1590 * All menu messages from these groups should be routed to the server.
1592 * RETURNS: TRUE if the popup menu is part of a server owned group
1593 * FALSE if the popup menu is part of a container owned group
1595 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1597 UINT nPos
= 0, nWidth
, i
;
1599 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1601 /* Don't bother searching if the popup is the combined menu itself */
1602 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1605 /* Find the menu item index in the shared OLE menu that this item belongs to */
1606 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1609 /* The group widths array has counts for the number of elements
1610 * in the groups File, Edit, Container, Object, Window, Help.
1611 * The Edit, Object & Help groups belong to the server object
1612 * and the other three belong to the container.
1613 * Loop through the group widths and locate the group we are a member of.
1615 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1617 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1618 if ( nPos
< nWidth
)
1620 /* Odd elements are server menu widths */
1621 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1626 return pOleMenuDescriptor
->bIsServerItem
;
1629 /*************************************************************************
1630 * OLEMenu_CallWndProc
1631 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1632 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1634 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1637 HOLEMENU hOleMenu
= 0;
1638 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1639 OleMenuHookItem
*pHookItem
= NULL
;
1642 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1644 /* Check if we're being asked to process the message */
1645 if ( HC_ACTION
!= code
)
1648 /* Retrieve the current message being dispatched from lParam */
1649 pMsg
= (LPCWPSTRUCT
)lParam
;
1651 /* Check if the message is destined for a window we are interested in:
1652 * If the window has an OLEMenu property we may need to dispatch
1653 * the menu message to its active objects window instead. */
1655 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1659 /* Get the menu descriptor */
1660 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1661 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1664 /* Process menu messages */
1665 switch( pMsg
->message
)
1669 /* Reset the menu descriptor state */
1670 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1672 /* Send this message to the server as well */
1673 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1674 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1678 case WM_INITMENUPOPUP
:
1680 /* Save the state for whether this is a server owned menu */
1681 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1687 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1688 if ( fuFlags
& MF_SYSMENU
)
1691 /* Save the state for whether this is a server owned popup menu */
1692 else if ( fuFlags
& MF_POPUP
)
1693 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1700 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1701 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1702 goto NEXTHOOK
; /* Not a menu message */
1711 /* If the message was for the server dispatch it accordingly */
1712 if ( pOleMenuDescriptor
->bIsServerItem
)
1714 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1715 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1719 if ( pOleMenuDescriptor
)
1720 GlobalUnlock( hOleMenu
);
1722 /* Lookup the hook item for the current thread */
1723 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1725 /* This should never fail!! */
1726 WARN("could not retrieve hHook for current thread!\n" );
1730 /* Pass on the message to the next hooker */
1731 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1734 /*************************************************************************
1735 * OLEMenu_GetMsgProc
1736 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1737 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1739 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1742 HOLEMENU hOleMenu
= 0;
1743 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1744 OleMenuHookItem
*pHookItem
= NULL
;
1747 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1749 /* Check if we're being asked to process a messages */
1750 if ( HC_ACTION
!= code
)
1753 /* Retrieve the current message being dispatched from lParam */
1754 pMsg
= (LPMSG
)lParam
;
1756 /* Check if the message is destined for a window we are interested in:
1757 * If the window has an OLEMenu property we may need to dispatch
1758 * the menu message to its active objects window instead. */
1760 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1764 /* Process menu messages */
1765 switch( pMsg
->message
)
1769 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1771 goto NEXTHOOK
; /* Not a menu message */
1778 /* Get the menu descriptor */
1779 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1780 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1783 /* If the message was for the server dispatch it accordingly */
1784 if ( pOleMenuDescriptor
->bIsServerItem
)
1786 /* Change the hWnd in the message to the active objects hWnd.
1787 * The message loop which reads this message will automatically
1788 * dispatch it to the embedded objects window. */
1789 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1793 if ( pOleMenuDescriptor
)
1794 GlobalUnlock( hOleMenu
);
1796 /* Lookup the hook item for the current thread */
1797 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1799 /* This should never fail!! */
1800 WARN("could not retrieve hHook for current thread!\n" );
1804 /* Pass on the message to the next hooker */
1805 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1808 /***********************************************************************
1809 * OleCreateMenuDescriptor [OLE32.@]
1810 * Creates an OLE menu descriptor for OLE to use when dispatching
1811 * menu messages and commands.
1814 * hmenuCombined - Handle to the objects combined menu
1815 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1818 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1819 HMENU hmenuCombined
,
1820 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1823 OleMenuDescriptor
*pOleMenuDescriptor
;
1826 if ( !hmenuCombined
|| !lpMenuWidths
)
1829 /* Create an OLE menu descriptor */
1830 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1831 sizeof(OleMenuDescriptor
) ) ) )
1834 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1835 if ( !pOleMenuDescriptor
)
1838 /* Initialize menu group widths and hmenu */
1839 for ( i
= 0; i
< 6; i
++ )
1840 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1842 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1843 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1844 GlobalUnlock( hOleMenu
);
1849 /***********************************************************************
1850 * OleDestroyMenuDescriptor [OLE32.@]
1851 * Destroy the shared menu descriptor
1853 HRESULT WINAPI
OleDestroyMenuDescriptor(
1854 HOLEMENU hmenuDescriptor
)
1856 if ( hmenuDescriptor
)
1857 GlobalFree( hmenuDescriptor
);
1861 /***********************************************************************
1862 * OleSetMenuDescriptor [OLE32.@]
1863 * Installs or removes OLE dispatching code for the containers frame window.
1866 * hOleMenu Handle to composite menu descriptor
1867 * hwndFrame Handle to containers frame window
1868 * hwndActiveObject Handle to objects in-place activation window
1869 * lpFrame Pointer to IOleInPlaceFrame on containers window
1870 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1873 * S_OK - menu installed correctly
1874 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1877 * The lpFrame and lpActiveObject parameters are currently ignored
1878 * OLE should install context sensitive help F1 filtering for the app when
1879 * these are non null.
1881 HRESULT WINAPI
OleSetMenuDescriptor(
1884 HWND hwndActiveObject
,
1885 LPOLEINPLACEFRAME lpFrame
,
1886 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1888 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1891 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1892 return E_INVALIDARG
;
1894 if ( lpFrame
|| lpActiveObject
)
1896 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1904 /* Set up a message hook to intercept the containers frame window messages.
1905 * The message filter is responsible for dispatching menu messages from the
1906 * shared menu which are intended for the object.
1909 if ( hOleMenu
) /* Want to install dispatching code */
1911 /* If OLEMenu hooks are already installed for this thread, fail
1912 * Note: This effectively means that OleSetMenuDescriptor cannot
1913 * be called twice in succession on the same frame window
1914 * without first calling it with a null hOleMenu to uninstall
1916 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1919 /* Get the menu descriptor */
1920 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1921 if ( !pOleMenuDescriptor
)
1922 return E_UNEXPECTED
;
1924 /* Update the menu descriptor */
1925 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1926 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1928 GlobalUnlock( hOleMenu
);
1929 pOleMenuDescriptor
= NULL
;
1931 /* Add a menu descriptor windows property to the frame window */
1932 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1934 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1935 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1938 else /* Want to uninstall dispatching code */
1940 /* Uninstall the hooks */
1941 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1944 /* Remove the menu descriptor property from the frame window */
1945 RemovePropW( hwndFrame
, prop_olemenuW
);
1951 /******************************************************************************
1952 * IsAccelerator [OLE32.@]
1953 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1955 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1960 if(!lpMsg
) return FALSE
;
1963 WARN_(accel
)("NULL accel handle\n");
1966 if((lpMsg
->message
!= WM_KEYDOWN
&&
1967 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1968 lpMsg
->message
!= WM_SYSCHAR
&&
1969 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1970 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1971 if (NULL
== lpAccelTbl
)
1975 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1977 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1978 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1982 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1983 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1984 hAccel
, cAccelEntries
,
1985 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1986 for(i
= 0; i
< cAccelEntries
; i
++)
1988 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1991 if(lpMsg
->message
== WM_CHAR
)
1993 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1995 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
2001 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
2004 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
2005 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
2006 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
2007 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
2008 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
2009 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
2010 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
2014 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
2016 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
2017 { /* ^^ ALT pressed */
2018 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
2026 WARN_(accel
)("couldn't translate accelerator key\n");
2027 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2031 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2032 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2036 /***********************************************************************
2037 * ReleaseStgMedium [OLE32.@]
2039 void WINAPI
ReleaseStgMedium(
2042 switch (pmedium
->tymed
)
2046 if ( (pmedium
->pUnkForRelease
==0) &&
2047 (pmedium
->u
.hGlobal
!=0) )
2048 GlobalFree(pmedium
->u
.hGlobal
);
2053 if (pmedium
->u
.lpszFileName
!=0)
2055 if (pmedium
->pUnkForRelease
==0)
2057 DeleteFileW(pmedium
->u
.lpszFileName
);
2060 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2066 if (pmedium
->u
.pstm
!=0)
2068 IStream_Release(pmedium
->u
.pstm
);
2072 case TYMED_ISTORAGE
:
2074 if (pmedium
->u
.pstg
!=0)
2076 IStorage_Release(pmedium
->u
.pstg
);
2082 if ( (pmedium
->pUnkForRelease
==0) &&
2083 (pmedium
->u
.hBitmap
!=0) )
2084 DeleteObject(pmedium
->u
.hBitmap
);
2089 if ( (pmedium
->pUnkForRelease
==0) &&
2090 (pmedium
->u
.hMetaFilePict
!=0) )
2092 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2093 DeleteMetaFile(pMP
->hMF
);
2094 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2095 GlobalFree(pmedium
->u
.hMetaFilePict
);
2101 if ( (pmedium
->pUnkForRelease
==0) &&
2102 (pmedium
->u
.hEnhMetaFile
!=0) )
2104 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2112 pmedium
->tymed
=TYMED_NULL
;
2115 * After cleaning up, the unknown is released
2117 if (pmedium
->pUnkForRelease
!=0)
2119 IUnknown_Release(pmedium
->pUnkForRelease
);
2120 pmedium
->pUnkForRelease
= 0;
2125 * OLEDD_Initialize()
2127 * Initializes the OLE drag and drop data structures.
2129 static void OLEDD_Initialize(void)
2133 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2134 wndClass
.style
= CS_GLOBALCLASS
;
2135 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2136 wndClass
.cbClsExtra
= 0;
2137 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2138 wndClass
.hCursor
= 0;
2139 wndClass
.hbrBackground
= 0;
2140 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2142 RegisterClassW (&wndClass
);
2146 * OLEDD_DragTrackerWindowProc()
2148 * This method is the WindowProcedure of the drag n drop tracking
2149 * window. During a drag n Drop operation, an invisible window is created
2150 * to receive the user input and act upon it. This procedure is in charge
2154 #define DRAG_TIMER_ID 1
2156 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2166 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2168 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2169 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2178 case WM_LBUTTONDOWN
:
2179 case WM_MBUTTONDOWN
:
2180 case WM_RBUTTONDOWN
:
2182 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
2187 KillTimer(hwnd
, DRAG_TIMER_ID
);
2193 * This is a window proc after all. Let's call the default.
2195 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2199 * OLEDD_TrackStateChange()
2201 * This method is invoked while a drag and drop operation is in effect.
2204 * trackerInfo - Pointer to the structure identifying the
2205 * drag & drop operation that is currently
2208 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2210 HWND hwndNewTarget
= 0;
2215 * Get the handle of the window under the mouse
2217 pt
.x
= trackerInfo
->curMousePos
.x
;
2218 pt
.y
= trackerInfo
->curMousePos
.y
;
2219 hwndNewTarget
= WindowFromPoint(pt
);
2221 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2222 trackerInfo
->escPressed
,
2223 trackerInfo
->dwKeyState
);
2226 * Every time, we re-initialize the effects passed to the
2227 * IDropTarget to the effects allowed by the source.
2229 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2232 * If we are hovering over the same target as before, send the
2233 * DragOver notification
2235 if ( (trackerInfo
->curDragTarget
!= 0) &&
2236 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2238 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2239 trackerInfo
->dwKeyState
,
2240 trackerInfo
->curMousePos
,
2241 trackerInfo
->pdwEffect
);
2242 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2247 * If we changed window, we have to notify our old target and check for
2250 if (trackerInfo
->curDragTarget
)
2251 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2254 * Make sure we're hovering over a window.
2259 * Find-out if there is a drag target under the mouse
2261 HWND next_target_wnd
= hwndNewTarget
;
2263 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2265 while (next_target_wnd
&& !is_droptarget(next_target_wnd
))
2266 next_target_wnd
= GetParent(next_target_wnd
);
2268 if (next_target_wnd
) hwndNewTarget
= next_target_wnd
;
2270 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2271 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2272 trackerInfo
->curDragTarget
= get_droptarget_pointer(hwndNewTarget
);
2275 * If there is, notify it that we just dragged-in
2277 if (trackerInfo
->curDragTarget
)
2279 hr
= IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2280 trackerInfo
->dataObject
,
2281 trackerInfo
->dwKeyState
,
2282 trackerInfo
->curMousePos
,
2283 trackerInfo
->pdwEffect
);
2284 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2286 /* failed DragEnter() means invalid target */
2289 trackerInfo
->curDragTargetHWND
= 0;
2290 trackerInfo
->curTargetHWND
= 0;
2291 IDropTarget_Release(trackerInfo
->curDragTarget
);
2292 trackerInfo
->curDragTarget
= 0;
2299 * The mouse is not over a window so we don't track anything.
2301 trackerInfo
->curDragTargetHWND
= 0;
2302 trackerInfo
->curTargetHWND
= 0;
2303 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2304 trackerInfo
->curDragTarget
= 0;
2309 * Now that we have done that, we have to tell the source to give
2310 * us feedback on the work being done by the target. If we don't
2311 * have a target, simulate no effect.
2313 if (trackerInfo
->curDragTarget
==0)
2315 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2318 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2319 *trackerInfo
->pdwEffect
);
2322 * When we ask for feedback from the drop source, sometimes it will
2323 * do all the necessary work and sometimes it will not handle it
2324 * when that's the case, we must display the standard drag and drop
2327 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2331 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2333 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(2));
2335 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2337 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(3));
2339 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2341 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(4));
2345 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(1));
2352 * All the return valued will stop the operation except the S_OK
2355 if (trackerInfo
->returnValue
!=S_OK
)
2358 * Make sure the message loop in DoDragDrop stops
2360 trackerInfo
->trackingDone
= TRUE
;
2363 * Release the mouse in case the drop target decides to show a popup
2364 * or a menu or something.
2369 * If we end-up over a target, drop the object in the target or
2370 * inform the target that the operation was cancelled.
2372 if (trackerInfo
->curDragTarget
)
2374 switch (trackerInfo
->returnValue
)
2377 * If the source wants us to complete the operation, we tell
2378 * the drop target that we just dropped the object in it.
2380 case DRAGDROP_S_DROP
:
2381 if (*trackerInfo
->pdwEffect
!= DROPEFFECT_NONE
)
2382 trackerInfo
->returnValue
= IDropTarget_Drop(trackerInfo
->curDragTarget
,
2383 trackerInfo
->dataObject
,
2384 trackerInfo
->dwKeyState
,
2385 trackerInfo
->curMousePos
,
2386 trackerInfo
->pdwEffect
);
2388 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2392 * If the source told us that we should cancel, fool the drop
2393 * target by telling it that the mouse left its window.
2394 * Also set the drop effect to "NONE" in case the application
2395 * ignores the result of DoDragDrop.
2397 case DRAGDROP_S_CANCEL
:
2398 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2399 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2407 * OLEDD_GetButtonState()
2409 * This method will use the current state of the keyboard to build
2410 * a button state mask equivalent to the one passed in the
2411 * WM_MOUSEMOVE wParam.
2413 static DWORD
OLEDD_GetButtonState(void)
2415 BYTE keyboardState
[256];
2418 GetKeyboardState(keyboardState
);
2420 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2421 keyMask
|= MK_SHIFT
;
2423 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2424 keyMask
|= MK_CONTROL
;
2426 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2427 keyMask
|= MK_LBUTTON
;
2429 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2430 keyMask
|= MK_RBUTTON
;
2432 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2433 keyMask
|= MK_MBUTTON
;
2439 * OLEDD_GetButtonState()
2441 * This method will read the default value of the registry key in
2442 * parameter and extract a DWORD value from it. The registry key value
2443 * can be in a string key or a DWORD key.
2446 * regKey - Key to read the default value from
2447 * pdwValue - Pointer to the location where the DWORD
2448 * value is returned. This value is not modified
2449 * if the value is not found.
2452 static void OLEUTL_ReadRegistryDWORDValue(
2457 DWORD cbData
= sizeof(buffer
);
2461 lres
= RegQueryValueExW(regKey
,
2468 if (lres
==ERROR_SUCCESS
)
2473 *pdwValue
= *(DWORD
*)buffer
;
2478 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2484 /******************************************************************************
2487 * The operation of this function is documented literally in the WinAPI
2488 * documentation to involve a QueryInterface for the IViewObject interface,
2489 * followed by a call to IViewObject::Draw.
2491 HRESULT WINAPI
OleDraw(
2498 IViewObject
*viewobject
;
2500 if (!pUnk
) return E_INVALIDARG
;
2502 hres
= IUnknown_QueryInterface(pUnk
,
2504 (void**)&viewobject
);
2505 if (SUCCEEDED(hres
))
2507 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2508 IViewObject_Release(viewobject
);
2512 return DV_E_NOIVIEWOBJECT
;
2515 /***********************************************************************
2516 * OleTranslateAccelerator [OLE32.@]
2518 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2519 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2523 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2525 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2526 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2531 /******************************************************************************
2532 * OleCreate [OLE32.@]
2535 HRESULT WINAPI
OleCreate(
2539 LPFORMATETC pFormatEtc
,
2540 LPOLECLIENTSITE pClientSite
,
2545 IUnknown
* pUnk
= NULL
;
2546 IOleObject
*pOleObject
= NULL
;
2548 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2549 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2551 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2553 if (SUCCEEDED(hres
))
2554 hres
= IStorage_SetClass(pStg
, rclsid
);
2556 if (pClientSite
&& SUCCEEDED(hres
))
2558 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2559 if (SUCCEEDED(hres
))
2562 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2566 if (SUCCEEDED(hres
))
2568 IPersistStorage
* pPS
;
2569 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2571 TRACE("trying to set stg %p\n", pStg
);
2572 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2573 TRACE("-- result 0x%08x\n", hres
);
2574 IPersistStorage_Release(pPS
);
2578 if (pClientSite
&& SUCCEEDED(hres
))
2580 TRACE("trying to set clientsite %p\n", pClientSite
);
2581 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2582 TRACE("-- result 0x%08x\n", hres
);
2586 IOleObject_Release(pOleObject
);
2588 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2591 IRunnableObject
*pRunnable
;
2592 IOleCache
*pOleCache
;
2595 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2596 if (SUCCEEDED(hres2
))
2598 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2599 IRunnableObject_Release(pRunnable
);
2602 if (SUCCEEDED(hres
))
2604 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2605 if (SUCCEEDED(hres2
))
2608 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2612 pfe
.dwAspect
= DVASPECT_CONTENT
;
2614 pfe
.tymed
= TYMED_NULL
;
2615 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2618 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2619 IOleCache_Release(pOleCache
);
2624 if (FAILED(hres
) && pUnk
)
2626 IUnknown_Release(pUnk
);
2632 TRACE("-- %p\n", pUnk
);
2636 /******************************************************************************
2637 * OleGetAutoConvert [OLE32.@]
2639 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2641 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2643 WCHAR buf
[CHARS_IN_GUID
];
2647 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2652 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2654 res
= REGDB_E_KEYMISSING
;
2657 res
= CLSIDFromString(buf
, pClsidNew
);
2659 if (hkey
) RegCloseKey(hkey
);
2663 /******************************************************************************
2664 * OleSetAutoConvert [OLE32.@]
2666 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2668 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2670 WCHAR szClsidNew
[CHARS_IN_GUID
];
2673 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2675 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2678 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2679 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2681 res
= REGDB_E_WRITEREGDB
;
2686 if (hkey
) RegCloseKey(hkey
);
2690 /******************************************************************************
2691 * OleDoAutoConvert [OLE32.@]
2693 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2695 WCHAR
*user_type_old
, *user_type_new
;
2701 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2703 *pClsidNew
= CLSID_NULL
;
2705 return E_INVALIDARG
;
2706 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2710 *pClsidNew
= stat
.clsid
;
2711 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2715 hr
= IStorage_SetClass(pStg
, &clsid
);
2719 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2722 user_type_new
= NULL
;
2725 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2727 user_type_new
= NULL
;
2729 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2730 CoTaskMemFree(user_type_new
);
2733 CoTaskMemFree(user_type_old
);
2734 IStorage_SetClass(pStg
, &stat
.clsid
);
2738 hr
= SetConvertStg(pStg
, TRUE
);
2741 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2742 IStorage_SetClass(pStg
, &stat
.clsid
);
2746 CoTaskMemFree(user_type_old
);
2750 /******************************************************************************
2751 * OleIsRunning [OLE32.@]
2753 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2755 IRunnableObject
*pRunnable
;
2759 TRACE("(%p)\n", object
);
2761 if (!object
) return FALSE
;
2763 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2766 running
= IRunnableObject_IsRunning(pRunnable
);
2767 IRunnableObject_Release(pRunnable
);
2771 /***********************************************************************
2772 * OleNoteObjectVisible [OLE32.@]
2774 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2776 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2777 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2781 /***********************************************************************
2782 * OLE_FreeClipDataArray [internal]
2785 * frees the data associated with an array of CLIPDATAs
2787 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2790 for (i
= 0; i
< count
; i
++)
2791 if (pClipDataArray
[i
].pClipData
)
2792 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2795 /***********************************************************************
2796 * PropSysAllocString [OLE32.@]
2798 * Forward to oleaut32.
2800 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2802 return SysAllocString(str
);
2805 /***********************************************************************
2806 * PropSysFreeString [OLE32.@]
2808 * Forward to oleaut32.
2810 void WINAPI
PropSysFreeString(LPOLESTR str
)
2815 /******************************************************************************
2816 * Check if a PROPVARIANT's type is valid.
2818 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2848 case VT_STREAMED_OBJECT
:
2849 case VT_STORED_OBJECT
:
2850 case VT_BLOB_OBJECT
:
2853 case VT_I1
|VT_VECTOR
:
2854 case VT_I2
|VT_VECTOR
:
2855 case VT_I4
|VT_VECTOR
:
2856 case VT_I8
|VT_VECTOR
:
2857 case VT_R4
|VT_VECTOR
:
2858 case VT_R8
|VT_VECTOR
:
2859 case VT_CY
|VT_VECTOR
:
2860 case VT_DATE
|VT_VECTOR
:
2861 case VT_BSTR
|VT_VECTOR
:
2862 case VT_ERROR
|VT_VECTOR
:
2863 case VT_BOOL
|VT_VECTOR
:
2864 case VT_VARIANT
|VT_VECTOR
:
2865 case VT_UI1
|VT_VECTOR
:
2866 case VT_UI2
|VT_VECTOR
:
2867 case VT_UI4
|VT_VECTOR
:
2868 case VT_UI8
|VT_VECTOR
:
2869 case VT_LPSTR
|VT_VECTOR
:
2870 case VT_LPWSTR
|VT_VECTOR
:
2871 case VT_FILETIME
|VT_VECTOR
:
2872 case VT_CF
|VT_VECTOR
:
2873 case VT_CLSID
|VT_VECTOR
:
2876 WARN("Bad type %d\n", vt
);
2877 return STG_E_INVALIDPARAMETER
;
2880 /***********************************************************************
2881 * PropVariantClear [OLE32.@]
2883 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2887 TRACE("(%p)\n", pvar
);
2892 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2895 memset(pvar
, 0, sizeof(*pvar
));
2923 case VT_STREAMED_OBJECT
:
2925 case VT_STORED_OBJECT
:
2926 if (pvar
->u
.pStream
)
2927 IStream_Release(pvar
->u
.pStream
);
2932 /* pick an arbitrary typed pointer - we don't care about the type
2933 * as we are just freeing it */
2934 CoTaskMemFree(pvar
->u
.puuid
);
2937 case VT_BLOB_OBJECT
:
2938 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2941 PropSysFreeString(pvar
->u
.bstrVal
);
2944 if (pvar
->u
.pclipdata
)
2946 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2947 CoTaskMemFree(pvar
->u
.pclipdata
);
2951 if (pvar
->vt
& VT_VECTOR
)
2955 switch (pvar
->vt
& ~VT_VECTOR
)
2958 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2961 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2964 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2965 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2968 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2969 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2972 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2973 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2976 if (pvar
->vt
& ~VT_VECTOR
)
2978 /* pick an arbitrary VT_VECTOR structure - they all have the same
2980 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2985 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2986 hr
= STG_E_INVALIDPARAMETER
;
2990 memset(pvar
, 0, sizeof(*pvar
));
2994 /***********************************************************************
2995 * PropVariantCopy [OLE32.@]
2997 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2998 const PROPVARIANT
*pvarSrc
) /* [in] */
3003 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
3005 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
3009 /* this will deal with most cases */
3010 *pvarDest
= *pvarSrc
;
3036 case VT_STREAMED_OBJECT
:
3038 case VT_STORED_OBJECT
:
3039 if (pvarDest
->u
.pStream
)
3040 IStream_AddRef(pvarDest
->u
.pStream
);
3043 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
3044 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
3047 if (pvarSrc
->u
.pszVal
)
3049 len
= strlen(pvarSrc
->u
.pszVal
);
3050 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
3051 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
3055 if (pvarSrc
->u
.pwszVal
)
3057 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
3058 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
3059 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
3063 case VT_BLOB_OBJECT
:
3064 if (pvarSrc
->u
.blob
.pBlobData
)
3066 len
= pvarSrc
->u
.blob
.cbSize
;
3067 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
3068 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
3072 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
3075 if (pvarSrc
->u
.pclipdata
)
3077 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
3078 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
3079 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
3080 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
3081 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
3082 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
3086 if (pvarSrc
->vt
& VT_VECTOR
)
3091 switch(pvarSrc
->vt
& ~VT_VECTOR
)
3093 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
3094 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
3095 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3096 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3097 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3098 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3099 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3100 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3101 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3102 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3103 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3104 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3105 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3106 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3107 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3108 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3109 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3110 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3111 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3112 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3113 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3116 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3117 return E_INVALIDARG
;
3119 len
= pvarSrc
->u
.capropvar
.cElems
;
3120 pvarDest
->u
.capropvar
.pElems
= len
? CoTaskMemAlloc(len
* elemSize
) : NULL
;
3121 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3123 for (i
= 0; i
< len
; i
++)
3124 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3126 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3128 FIXME("Copy clipformats\n");
3130 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3132 for (i
= 0; i
< len
; i
++)
3133 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3135 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3138 for (i
= 0; i
< len
; i
++)
3140 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3141 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3142 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3143 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3146 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3149 for (i
= 0; i
< len
; i
++)
3151 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3153 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3154 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3155 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3159 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3162 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3168 /***********************************************************************
3169 * FreePropVariantArray [OLE32.@]
3171 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3172 PROPVARIANT
*rgvars
) /* [in/out] */
3176 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3179 return E_INVALIDARG
;
3181 for(i
= 0; i
< cVariants
; i
++)
3182 PropVariantClear(&rgvars
[i
]);
3187 /******************************************************************************
3188 * DllDebugObjectRPCHook (OLE32.@)
3189 * turns on and off internal debugging, pointer is only used on macintosh
3192 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)