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
33 #define NONAMELESSUNION
45 #include "compobj_private.h"
47 #include "wine/list.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
52 WINE_DECLARE_DEBUG_CHANNEL(accel
);
54 /******************************************************************************
55 * These are static/global variables and internal data structures that the
56 * OLE module uses to maintain its state.
58 typedef struct tagTrackerWindowInfo
60 IDataObject
* dataObject
;
61 IDropSource
* dropSource
;
69 HWND curTargetHWND
; /* window the mouse is hovering over */
70 IDropTarget
* curDragTarget
;
71 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
72 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
75 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
77 HWND hwndFrame
; /* The containers frame window */
78 HWND hwndActiveObject
; /* The active objects window */
79 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
80 HMENU hmenuCombined
; /* The combined menu */
81 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
84 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
86 DWORD tid
; /* Thread Id */
87 HANDLE hHeap
; /* Heap this is allocated from */
88 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
89 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
90 struct tagOleMenuHookItem
*next
;
93 static OleMenuHookItem
*hook_list
;
96 * This is the lock count on the OLE library. It is controlled by the
97 * OLEInitialize/OLEUninitialize methods.
99 static LONG OLE_moduleLockCount
= 0;
102 * Name of our registered window class.
104 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] = L
"WineDragDropTracker32";
107 * Name of menu descriptor property.
109 static const WCHAR prop_olemenuW
[] = L
"PROP_OLEMenuDescriptor";
111 /* property to store IDropTarget pointer */
112 static const WCHAR prop_oledroptarget
[] = L
"OleDropTargetInterface";
114 /* property to store Marshalled IDropTarget pointer */
115 static const WCHAR prop_marshalleddroptarget
[] = L
"WineMarshalledDropTarget";
117 /******************************************************************************
118 * These are the prototypes of miscellaneous utility methods
120 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
122 /******************************************************************************
123 * These are the prototypes of the utility methods used to manage a shared menu
125 static void OLEMenu_Initialize(void);
126 static void OLEMenu_UnInitialize(void);
127 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
128 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
129 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
130 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
131 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
132 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
133 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
135 /******************************************************************************
136 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
138 extern void OLEClipbrd_UnInitialize(void);
139 extern void OLEClipbrd_Initialize(void);
141 /******************************************************************************
142 * These are the prototypes of the utility methods used for OLE Drag n Drop
144 static void OLEDD_Initialize(void);
145 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
146 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
147 static DWORD
OLEDD_GetButtonState(void);
149 /******************************************************************************
150 * OleBuildVersion [OLE32.@]
152 DWORD WINAPI
OleBuildVersion(void)
154 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
155 return (rmm
<<16)+rup
;
158 /***********************************************************************
159 * OleInitialize (OLE32.@)
161 HRESULT WINAPI DECLSPEC_HOTPATCH
OleInitialize(LPVOID reserved
)
165 TRACE("(%p)\n", reserved
);
168 * The first duty of the OleInitialize is to initialize the COM libraries.
170 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
173 * If the CoInitializeEx call failed, the OLE libraries can't be
179 if (!COM_CurrentInfo()->ole_inits
)
185 * Then, it has to initialize the OLE specific modules.
189 * Object linking and Embedding
190 * In-place activation
192 if (!COM_CurrentInfo()->ole_inits
++ &&
193 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
196 * Initialize the libraries.
198 TRACE("() - Initializing the OLE libraries\n");
203 OLEClipbrd_Initialize();
213 OLEMenu_Initialize();
219 /******************************************************************************
220 * OleUninitialize [OLE32.@]
222 void WINAPI DECLSPEC_HOTPATCH
OleUninitialize(void)
226 if (COM_CurrentInfo()->ole_inits
== 0)
228 WARN("ole_inits is already 0\n");
232 * If we hit the bottom of the lock stack, free the libraries.
234 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
237 * Actually free the libraries.
239 TRACE("() - Freeing the last reference count\n");
244 OLEClipbrd_UnInitialize();
249 OLEMenu_UnInitialize();
253 * Then, uninitialize the COM libraries.
258 /******************************************************************************
259 * OleInitializeWOW [OLE32.@]
261 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
262 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
266 /*************************************************************
267 * get_droptarget_handle
269 * Retrieve a handle to the map containing the marshalled IDropTarget.
270 * This handle belongs to the process that called RegisterDragDrop.
271 * See get_droptarget_local_handle().
273 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
275 return GetPropW(hwnd
, prop_marshalleddroptarget
);
278 /*************************************************************
281 * Is the window a droptarget.
283 static inline BOOL
is_droptarget(HWND hwnd
)
285 return get_droptarget_handle(hwnd
) != 0;
288 /*************************************************************
289 * get_droptarget_local_handle
291 * Retrieve a handle to the map containing the marshalled IDropTarget.
292 * The handle should be closed when finished with.
294 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
296 HANDLE handle
, local_handle
= 0;
298 handle
= get_droptarget_handle(hwnd
);
305 GetWindowThreadProcessId(hwnd
, &pid
);
306 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
309 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
310 CloseHandle(process
);
316 /***********************************************************************
317 * create_map_from_stream
319 * Helper for RegisterDragDrop. Creates a file mapping object
320 * with the contents of the provided stream. The stream must
321 * be a global memory backed stream.
323 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
330 hr
= GetHGlobalFromStream(stream
, &hmem
);
331 if(FAILED(hr
)) return hr
;
333 size
= GlobalSize(hmem
);
334 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
335 if(!*map
) return E_OUTOFMEMORY
;
337 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
338 memcpy(data
, GlobalLock(hmem
), size
);
340 UnmapViewOfFile(data
);
344 /***********************************************************************
345 * create_stream_from_map
347 * Creates a stream from the provided map.
349 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
351 HRESULT hr
= E_OUTOFMEMORY
;
354 MEMORY_BASIC_INFORMATION info
;
356 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
359 VirtualQuery(data
, &info
, sizeof(info
));
360 TRACE("size %d\n", (int)info
.RegionSize
);
362 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
365 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
367 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
369 UnmapViewOfFile(data
);
373 /* This is to work around apps which break COM rules by not implementing
374 * IDropTarget::QueryInterface(). Windows doesn't expose this because it
375 * doesn't call CoMarshallInterface() in RegisterDragDrop().
376 * The wrapper is only used internally, and only exists for the life of
377 * the marshal. We don't want to hold a ref on the app provided target
378 * as some apps destroy this prior to CoUninitialize without calling
379 * RevokeDragDrop. The only (long-term) ref is held by the window prop. */
381 IDropTarget IDropTarget_iface
;
386 static inline DropTargetWrapper
* impl_from_IDropTarget(IDropTarget
* iface
)
388 return CONTAINING_RECORD(iface
, DropTargetWrapper
, IDropTarget_iface
);
391 static HRESULT WINAPI
DropTargetWrapper_QueryInterface(IDropTarget
* iface
,
395 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
396 if (IsEqualIID(riid
, &IID_IUnknown
) ||
397 IsEqualIID(riid
, &IID_IDropTarget
))
399 IDropTarget_AddRef(&This
->IDropTarget_iface
);
400 *ppvObject
= &This
->IDropTarget_iface
;
404 return E_NOINTERFACE
;
407 static ULONG WINAPI
DropTargetWrapper_AddRef(IDropTarget
* iface
)
409 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
410 return InterlockedIncrement(&This
->refs
);
413 static ULONG WINAPI
DropTargetWrapper_Release(IDropTarget
* iface
)
415 DropTargetWrapper
* This
= impl_from_IDropTarget(iface
);
416 ULONG refs
= InterlockedDecrement(&This
->refs
);
417 if (!refs
) HeapFree(GetProcessHeap(), 0, This
);
421 static inline HRESULT
get_target_from_wrapper( IDropTarget
*wrapper
, IDropTarget
**target
)
423 DropTargetWrapper
* This
= impl_from_IDropTarget( wrapper
);
424 *target
= GetPropW( This
->hwnd
, prop_oledroptarget
);
425 if (!*target
) return DRAGDROP_E_NOTREGISTERED
;
426 IDropTarget_AddRef( *target
);
430 static HRESULT WINAPI
DropTargetWrapper_DragEnter(IDropTarget
* iface
,
431 IDataObject
* pDataObj
,
437 HRESULT r
= get_target_from_wrapper( iface
, &target
);
441 r
= IDropTarget_DragEnter( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
442 IDropTarget_Release( target
);
447 static HRESULT WINAPI
DropTargetWrapper_DragOver(IDropTarget
* iface
,
453 HRESULT r
= get_target_from_wrapper( iface
, &target
);
457 r
= IDropTarget_DragOver( target
, grfKeyState
, pt
, pdwEffect
);
458 IDropTarget_Release( target
);
463 static HRESULT WINAPI
DropTargetWrapper_DragLeave(IDropTarget
* iface
)
466 HRESULT r
= get_target_from_wrapper( iface
, &target
);
470 r
= IDropTarget_DragLeave( target
);
471 IDropTarget_Release( target
);
476 static HRESULT WINAPI
DropTargetWrapper_Drop(IDropTarget
* iface
,
477 IDataObject
* pDataObj
,
483 HRESULT r
= get_target_from_wrapper( iface
, &target
);
487 r
= IDropTarget_Drop( target
, pDataObj
, grfKeyState
, pt
, pdwEffect
);
488 IDropTarget_Release( target
);
493 static const IDropTargetVtbl DropTargetWrapperVTbl
=
495 DropTargetWrapper_QueryInterface
,
496 DropTargetWrapper_AddRef
,
497 DropTargetWrapper_Release
,
498 DropTargetWrapper_DragEnter
,
499 DropTargetWrapper_DragOver
,
500 DropTargetWrapper_DragLeave
,
501 DropTargetWrapper_Drop
504 static IDropTarget
* WrapDropTarget( HWND hwnd
)
506 DropTargetWrapper
* This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
510 This
->IDropTarget_iface
.lpVtbl
= &DropTargetWrapperVTbl
;
514 return &This
->IDropTarget_iface
;
517 /***********************************************************************
518 * get_droptarget_pointer
520 * Retrieves the marshalled IDropTarget from the window.
522 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
524 IDropTarget
*droptarget
= NULL
;
528 map
= get_droptarget_local_handle(hwnd
);
529 if(!map
) return NULL
;
531 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
533 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
534 IStream_Release(stream
);
540 /***********************************************************************
541 * RegisterDragDrop (OLE32.@)
543 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
549 IDropTarget
*wrapper
;
551 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
553 if (!COM_CurrentApt())
555 ERR("COM not initialized\n");
556 return E_OUTOFMEMORY
;
564 ERR("invalid hwnd %p\n", hwnd
);
565 return DRAGDROP_E_INVALIDHWND
;
568 /* block register for other processes windows */
569 GetWindowThreadProcessId(hwnd
, &pid
);
570 if (pid
!= GetCurrentProcessId())
572 FIXME("register for another process windows is disabled\n");
573 return DRAGDROP_E_INVALIDHWND
;
576 /* check if the window is already registered */
577 if (is_droptarget(hwnd
))
578 return DRAGDROP_E_ALREADYREGISTERED
;
581 * Marshal the drop target pointer into a shared memory map and
582 * store the map's handle in a Wine specific window prop. We also
583 * store the drop target pointer itself in the
584 * "OleDropTargetInterface" prop for compatibility with Windows.
587 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
588 if(FAILED(hr
)) return hr
;
590 /* IDropTarget::QueryInterface() shouldn't be called, some (broken) apps depend on this. */
591 wrapper
= WrapDropTarget( hwnd
);
594 IStream_Release(stream
);
595 return E_OUTOFMEMORY
;
597 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, (IUnknown
*)wrapper
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
598 IDropTarget_Release(wrapper
);
602 hr
= create_map_from_stream(stream
, &map
);
605 IDropTarget_AddRef(pDropTarget
);
606 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
607 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
613 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
614 CoReleaseMarshalData(stream
);
617 IStream_Release(stream
);
622 /***********************************************************************
623 * RevokeDragDrop (OLE32.@)
625 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
629 IDropTarget
*drop_target
;
632 TRACE("(%p)\n", hwnd
);
636 ERR("invalid hwnd %p\n", hwnd
);
637 return DRAGDROP_E_INVALIDHWND
;
640 /* no registration data */
641 if (!(map
= get_droptarget_handle(hwnd
)))
642 return DRAGDROP_E_NOTREGISTERED
;
644 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
645 if(drop_target
) IDropTarget_Release(drop_target
);
647 RemovePropW(hwnd
, prop_oledroptarget
);
648 RemovePropW(hwnd
, prop_marshalleddroptarget
);
650 hr
= create_stream_from_map(map
, &stream
);
653 CoReleaseMarshalData(stream
);
654 IStream_Release(stream
);
661 /***********************************************************************
662 * OleRegGetUserType (OLE32.@)
664 HRESULT WINAPI
OleRegGetUserType(REFCLSID clsid
, DWORD form
, LPOLESTR
*usertype
)
666 DWORD valuetype
, valuelen
;
667 WCHAR auxkeynameW
[16];
672 TRACE("(%s, %u, %p)\n", debugstr_guid(clsid
), form
, usertype
);
679 /* Return immediately if it's not registered. */
680 hres
= COM_OpenKeyForCLSID(clsid
, NULL
, KEY_READ
, &usertypekey
);
686 /* Try additional types if requested. If they don't exist fall back to USERCLASSTYPE_FULL. */
687 if (form
!= USERCLASSTYPE_FULL
)
691 swprintf(auxkeynameW
, ARRAY_SIZE(auxkeynameW
), L
"AuxUserType\\%d", form
);
692 if (COM_OpenKeyForCLSID(clsid
, auxkeynameW
, KEY_READ
, &auxkey
) == S_OK
)
694 if (!RegQueryValueExW(auxkey
, L
"", NULL
, &valuetype
, NULL
, &valuelen
) && valuelen
)
696 RegCloseKey(usertypekey
);
697 usertypekey
= auxkey
;
705 if (RegQueryValueExW(usertypekey
, L
"", NULL
, &valuetype
, NULL
, &valuelen
))
707 RegCloseKey(usertypekey
);
708 return REGDB_E_READREGDB
;
711 *usertype
= CoTaskMemAlloc(valuelen
);
714 RegCloseKey(usertypekey
);
715 return E_OUTOFMEMORY
;
718 ret
= RegQueryValueExW(usertypekey
, L
"", NULL
, &valuetype
, (BYTE
*)*usertype
, &valuelen
);
719 RegCloseKey(usertypekey
);
720 if (ret
!= ERROR_SUCCESS
)
722 CoTaskMemFree(*usertype
);
724 return REGDB_E_READREGDB
;
730 /***********************************************************************
731 * DoDragDrop [OLE32.@]
733 HRESULT WINAPI
DoDragDrop (
734 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
735 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
736 DWORD dwOKEffect
, /* [in] effects allowed by the source */
737 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
739 TrackerWindowInfo trackerInfo
;
740 HWND hwndTrackWindow
;
743 TRACE("(%p, %p, %08x, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
745 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
749 * Setup the drag n drop tracking window.
752 trackerInfo
.dataObject
= pDataObject
;
753 trackerInfo
.dropSource
= pDropSource
;
754 trackerInfo
.dwOKEffect
= dwOKEffect
;
755 trackerInfo
.pdwEffect
= pdwEffect
;
756 trackerInfo
.trackingDone
= FALSE
;
757 trackerInfo
.inTrackCall
= FALSE
;
758 trackerInfo
.escPressed
= FALSE
;
759 trackerInfo
.curTargetHWND
= 0;
760 trackerInfo
.curDragTarget
= 0;
762 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, L
"TrackerWindow",
763 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
764 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
770 * Capture the mouse input
772 SetCapture(hwndTrackWindow
);
777 * Pump messages. All mouse input should go to the capture window.
779 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
781 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
782 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
783 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
785 if ( (msg
.message
>= WM_KEYFIRST
) &&
786 (msg
.message
<= WM_KEYLAST
) )
789 * When keyboard messages are sent to windows on this thread, we
790 * want to ignore notify the drop source that the state changed.
791 * in the case of the Escape key, we also notify the drop source
792 * we give it a special meaning.
794 if ( (msg
.message
==WM_KEYDOWN
) &&
795 (msg
.wParam
==VK_ESCAPE
) )
797 trackerInfo
.escPressed
= TRUE
;
801 * Notify the drop source.
803 OLEDD_TrackStateChange(&trackerInfo
);
808 * Dispatch the messages only when it's not a keyboard message.
810 DispatchMessageW(&msg
);
814 /* re-post the quit message to outer message loop */
815 if (msg
.message
== WM_QUIT
)
816 PostQuitMessage(msg
.wParam
);
818 * Destroy the temporary window.
820 DestroyWindow(hwndTrackWindow
);
822 return trackerInfo
.returnValue
;
828 /***********************************************************************
829 * OleQueryLinkFromData [OLE32.@]
831 HRESULT WINAPI
OleQueryLinkFromData(
832 IDataObject
* pSrcDataObject
)
834 FIXME("(%p),stub!\n", pSrcDataObject
);
838 /***********************************************************************
839 * OleRegGetMiscStatus [OLE32.@]
841 HRESULT WINAPI
OleRegGetMiscStatus(
852 TRACE("(%s, %d, %p)\n", debugstr_guid(clsid
), dwAspect
, pdwStatus
);
854 if (!pdwStatus
) return E_INVALIDARG
;
858 if (actctx_get_miscstatus(clsid
, dwAspect
, pdwStatus
)) return S_OK
;
860 hr
= COM_OpenKeyForCLSID(clsid
, L
"MiscStatus", KEY_READ
, &miscStatusKey
);
862 /* missing key is not a failure */
863 return hr
== REGDB_E_KEYMISSING
? S_OK
: hr
;
865 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
868 * Open the key specific to the requested aspect.
870 swprintf(keyName
, ARRAY_SIZE(keyName
), L
"%d", dwAspect
);
872 result
= open_classes_key(miscStatusKey
, keyName
, KEY_READ
, &aspectKey
);
873 if (result
== ERROR_SUCCESS
)
875 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
876 RegCloseKey(aspectKey
);
879 RegCloseKey(miscStatusKey
);
883 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
887 IEnumOLEVERB IEnumOLEVERB_iface
;
894 static inline EnumOLEVERB
*impl_from_IEnumOLEVERB(IEnumOLEVERB
*iface
)
896 return CONTAINING_RECORD(iface
, EnumOLEVERB
, IEnumOLEVERB_iface
);
899 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
900 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
902 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
903 if (IsEqualIID(riid
, &IID_IUnknown
) ||
904 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
906 IEnumOLEVERB_AddRef(iface
);
910 return E_NOINTERFACE
;
913 static ULONG WINAPI
EnumOLEVERB_AddRef(
916 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
918 return InterlockedIncrement(&This
->ref
);
921 static ULONG WINAPI
EnumOLEVERB_Release(
924 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
925 LONG refs
= InterlockedDecrement(&This
->ref
);
929 RegCloseKey(This
->hkeyVerb
);
930 HeapFree(GetProcessHeap(), 0, This
);
935 static HRESULT WINAPI
EnumOLEVERB_Next(
936 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
939 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
942 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
947 for (; celt
; celt
--, rgelt
++)
952 LPWSTR pwszMenuFlags
;
954 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, ARRAY_SIZE(wszSubKey
));
955 if (res
== ERROR_NO_MORE_ITEMS
)
960 else if (res
!= ERROR_SUCCESS
)
962 ERR("RegEnumKeyW failed with error %d\n", res
);
963 hr
= REGDB_E_READREGDB
;
966 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
967 if (res
!= ERROR_SUCCESS
)
969 ERR("RegQueryValueW failed with error %d\n", res
);
970 hr
= REGDB_E_READREGDB
;
973 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
979 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
980 if (res
!= ERROR_SUCCESS
)
982 ERR("RegQueryValueW failed with error %d\n", res
);
983 hr
= REGDB_E_READREGDB
;
984 CoTaskMemFree(pwszOLEVERB
);
988 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
989 pwszMenuFlags
= wcschr(pwszOLEVERB
, ',');
992 hr
= OLEOBJ_E_INVALIDVERB
;
993 CoTaskMemFree(pwszOLEVERB
);
996 /* nul terminate the name string and advance to first character */
997 *pwszMenuFlags
= '\0';
999 pwszAttribs
= wcschr(pwszMenuFlags
, ',');
1002 hr
= OLEOBJ_E_INVALIDVERB
;
1003 CoTaskMemFree(pwszOLEVERB
);
1006 /* nul terminate the menu string and advance to first character */
1007 *pwszAttribs
= '\0';
1010 /* fill out structure for this verb */
1011 rgelt
->lVerb
= wcstol(wszSubKey
, NULL
, 10);
1012 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
1013 rgelt
->fuFlags
= wcstol(pwszMenuFlags
, NULL
, 10);
1014 rgelt
->grfAttribs
= wcstol(pwszAttribs
, NULL
, 10);
1023 static HRESULT WINAPI
EnumOLEVERB_Skip(
1024 IEnumOLEVERB
*iface
, ULONG celt
)
1026 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1028 TRACE("(%d)\n", celt
);
1030 This
->index
+= celt
;
1034 static HRESULT WINAPI
EnumOLEVERB_Reset(
1035 IEnumOLEVERB
*iface
)
1037 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1045 static HRESULT WINAPI
EnumOLEVERB_Clone(
1046 IEnumOLEVERB
*iface
,
1047 IEnumOLEVERB
**ppenum
)
1049 EnumOLEVERB
*This
= impl_from_IEnumOLEVERB(iface
);
1051 TRACE("(%p)\n", ppenum
);
1052 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1053 return HRESULT_FROM_WIN32(GetLastError());
1054 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
1057 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
1059 EnumOLEVERB_QueryInterface
,
1061 EnumOLEVERB_Release
,
1068 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
1070 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
1073 RegCloseKey(hkeyVerb
);
1074 return E_OUTOFMEMORY
;
1076 This
->IEnumOLEVERB_iface
.lpVtbl
= &EnumOLEVERB_VTable
;
1078 This
->index
= index
;
1079 This
->hkeyVerb
= hkeyVerb
;
1080 *ppenum
= &This
->IEnumOLEVERB_iface
;
1084 /***********************************************************************
1085 * OleRegEnumVerbs [OLE32.@]
1087 * Enumerates verbs associated with a class stored in the registry.
1090 * clsid [I] Class ID to enumerate the verbs for.
1091 * ppenum [O] Enumerator.
1095 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1096 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1097 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1098 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1100 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1106 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1108 res
= COM_OpenKeyForCLSID(clsid
, L
"Verb", KEY_READ
, &hkeyVerb
);
1111 if (res
== REGDB_E_CLASSNOTREG
)
1112 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1113 else if (res
== REGDB_E_KEYMISSING
)
1114 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1116 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1117 debugstr_guid(clsid
), res
);
1121 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1122 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1123 if (res
!= ERROR_SUCCESS
)
1125 ERR("failed to get subkey count with error %d\n", GetLastError());
1126 return REGDB_E_READREGDB
;
1131 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1132 RegCloseKey(hkeyVerb
);
1133 return OLEOBJ_E_NOVERBS
;
1136 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1139 /******************************************************************************
1140 * OleSetContainedObject [OLE32.@]
1142 HRESULT WINAPI
OleSetContainedObject(
1146 IRunnableObject
* runnable
= NULL
;
1149 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1151 hres
= IUnknown_QueryInterface(pUnknown
,
1152 &IID_IRunnableObject
,
1155 if (SUCCEEDED(hres
))
1157 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1159 IRunnableObject_Release(runnable
);
1167 /******************************************************************************
1170 * Set the OLE object to the running state.
1173 * pUnknown [I] OLE object to run.
1177 * Failure: Any HRESULT code.
1179 HRESULT WINAPI DECLSPEC_HOTPATCH
OleRun(LPUNKNOWN pUnknown
)
1181 IRunnableObject
*runable
;
1184 TRACE("(%p)\n", pUnknown
);
1186 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1188 return S_OK
; /* Appears to return no error. */
1190 hres
= IRunnableObject_Run(runable
, NULL
);
1191 IRunnableObject_Release(runable
);
1195 /******************************************************************************
1198 HRESULT WINAPI
OleLoad(
1201 LPOLECLIENTSITE pClientSite
,
1204 IPersistStorage
* persistStorage
= NULL
;
1206 IOleObject
* pOleObject
= NULL
;
1207 STATSTG storageInfo
;
1210 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1215 * TODO, Conversion ... OleDoAutoConvert
1219 * Get the class ID for the object.
1221 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1226 * Now, try and create the handler for the object
1228 hres
= CoCreateInstance(&storageInfo
.clsid
,
1230 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1235 * If that fails, as it will most times, load the default
1240 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1247 * If we couldn't find a handler... this is bad. Abort the whole thing.
1254 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1255 if (SUCCEEDED(hres
))
1258 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1263 * Initialize the object with its IPersistStorage interface.
1265 hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (void**)&persistStorage
);
1266 if (SUCCEEDED(hres
))
1268 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1270 IPersistStorage_Release(persistStorage
);
1271 persistStorage
= NULL
;
1274 if (SUCCEEDED(hres
) && pClientSite
)
1276 * Inform the new object of its client site.
1278 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1281 * Cleanup interfaces used internally
1284 IOleObject_Release(pOleObject
);
1286 if (SUCCEEDED(hres
))
1290 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1291 if (SUCCEEDED(hres1
))
1293 FIXME("handle OLE link\n");
1294 IOleLink_Release(pOleLink
);
1300 IUnknown_Release(pUnk
);
1309 /***********************************************************************
1312 HRESULT WINAPI
OleSave(
1313 LPPERSISTSTORAGE pPS
,
1320 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1323 * First, we transfer the class ID (if available)
1325 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1327 if (SUCCEEDED(hres
))
1329 WriteClassStg(pStg
, &objectClass
);
1333 * Then, we ask the object to save itself to the
1334 * storage. If it is successful, we commit the storage.
1336 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1338 if (SUCCEEDED(hres
))
1340 IStorage_Commit(pStg
,
1348 /******************************************************************************
1349 * OleLockRunning [OLE32.@]
1351 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1353 IRunnableObject
* runnable
= NULL
;
1356 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1358 hres
= IUnknown_QueryInterface(pUnknown
,
1359 &IID_IRunnableObject
,
1362 if (SUCCEEDED(hres
))
1364 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1366 IRunnableObject_Release(runnable
);
1375 /**************************************************************************
1376 * Internal methods to manage the shared OLE menu in response to the
1377 * OLE***MenuDescriptor API
1381 * OLEMenu_Initialize()
1383 * Initializes the OLEMENU data structures.
1385 static void OLEMenu_Initialize(void)
1390 * OLEMenu_UnInitialize()
1392 * Releases the OLEMENU data structures.
1394 static void OLEMenu_UnInitialize(void)
1398 /*************************************************************************
1399 * OLEMenu_InstallHooks
1400 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1402 * RETURNS: TRUE if message hooks were successfully installed
1405 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1407 OleMenuHookItem
*pHookItem
;
1409 /* Create an entry for the hook table */
1410 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1411 sizeof(OleMenuHookItem
)) ) )
1414 pHookItem
->tid
= tid
;
1415 pHookItem
->hHeap
= GetProcessHeap();
1416 pHookItem
->CallWndProc_hHook
= NULL
;
1418 /* Install a thread scope message hook for WH_GETMESSAGE */
1419 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1420 0, GetCurrentThreadId() );
1421 if ( !pHookItem
->GetMsg_hHook
)
1424 /* Install a thread scope message hook for WH_CALLWNDPROC */
1425 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1426 0, GetCurrentThreadId() );
1427 if ( !pHookItem
->CallWndProc_hHook
)
1430 /* Insert the hook table entry */
1431 pHookItem
->next
= hook_list
;
1432 hook_list
= pHookItem
;
1437 /* Unhook any hooks */
1438 if ( pHookItem
->GetMsg_hHook
)
1439 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1440 if ( pHookItem
->CallWndProc_hHook
)
1441 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1442 /* Release the hook table entry */
1443 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1448 /*************************************************************************
1449 * OLEMenu_UnInstallHooks
1450 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1452 * RETURNS: TRUE if message hooks were successfully installed
1455 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1457 OleMenuHookItem
*pHookItem
= NULL
;
1458 OleMenuHookItem
**ppHook
= &hook_list
;
1462 if ((*ppHook
)->tid
== tid
)
1464 pHookItem
= *ppHook
;
1465 *ppHook
= pHookItem
->next
;
1468 ppHook
= &(*ppHook
)->next
;
1470 if (!pHookItem
) return FALSE
;
1472 /* Uninstall the hooks installed for this thread */
1473 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1475 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1478 /* Release the hook table entry */
1479 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1484 /* Release the hook table entry */
1485 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1490 /*************************************************************************
1491 * OLEMenu_IsHookInstalled
1492 * Tests if OLEMenu hooks have been installed for a thread
1494 * RETURNS: The pointer and index of the hook table entry for the tid
1495 * NULL and -1 for the index if no hooks were installed for this thread
1497 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1499 OleMenuHookItem
*pHookItem
;
1501 /* Do a simple linear search for an entry whose tid matches ours.
1502 * We really need a map but efficiency is not a concern here. */
1503 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1505 if ( tid
== pHookItem
->tid
)
1512 /***********************************************************************
1513 * OLEMenu_FindMainMenuIndex
1515 * Used by OLEMenu API to find the top level group a menu item belongs to.
1516 * On success pnPos contains the index of the item in the top level menu group
1518 * RETURNS: TRUE if the ID was found, FALSE on failure
1520 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1524 nItems
= GetMenuItemCount( hMainMenu
);
1526 for (i
= 0; i
< nItems
; i
++)
1530 /* Is the current item a submenu? */
1531 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1533 /* If the handle is the same we're done */
1534 if ( hsubmenu
== hPopupMenu
)
1540 /* Recursively search without updating pnPos */
1541 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1553 /***********************************************************************
1554 * OLEMenu_SetIsServerMenu
1556 * Checks whether a popup menu belongs to a shared menu group which is
1557 * owned by the server, and sets the menu descriptor state accordingly.
1558 * All menu messages from these groups should be routed to the server.
1560 * RETURNS: TRUE if the popup menu is part of a server owned group
1561 * FALSE if the popup menu is part of a container owned group
1563 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1565 UINT nPos
= 0, nWidth
, i
;
1567 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1569 /* Don't bother searching if the popup is the combined menu itself */
1570 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1573 /* Find the menu item index in the shared OLE menu that this item belongs to */
1574 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1577 /* The group widths array has counts for the number of elements
1578 * in the groups File, Edit, Container, Object, Window, Help.
1579 * The Edit, Object & Help groups belong to the server object
1580 * and the other three belong to the container.
1581 * Loop through the group widths and locate the group we are a member of.
1583 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1585 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1586 if ( nPos
< nWidth
)
1588 /* Odd elements are server menu widths */
1589 pOleMenuDescriptor
->bIsServerItem
= i
%2;
1594 return pOleMenuDescriptor
->bIsServerItem
;
1597 /*************************************************************************
1598 * OLEMenu_CallWndProc
1599 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1600 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1602 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1605 HOLEMENU hOleMenu
= 0;
1606 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1607 OleMenuHookItem
*pHookItem
= NULL
;
1610 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1612 /* Check if we're being asked to process the message */
1613 if ( HC_ACTION
!= code
)
1616 /* Retrieve the current message being dispatched from lParam */
1617 pMsg
= (LPCWPSTRUCT
)lParam
;
1619 /* Check if the message is destined for a window we are interested in:
1620 * If the window has an OLEMenu property we may need to dispatch
1621 * the menu message to its active objects window instead. */
1623 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1627 /* Get the menu descriptor */
1628 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1629 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1632 /* Process menu messages */
1633 switch( pMsg
->message
)
1637 /* Reset the menu descriptor state */
1638 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1640 /* Send this message to the server as well */
1641 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1642 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1646 case WM_INITMENUPOPUP
:
1648 /* Save the state for whether this is a server owned menu */
1649 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1655 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1656 if ( fuFlags
& MF_SYSMENU
)
1659 /* Save the state for whether this is a server owned popup menu */
1660 else if ( fuFlags
& MF_POPUP
)
1661 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1668 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1669 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1670 goto NEXTHOOK
; /* Not a menu message */
1679 /* If the message was for the server dispatch it accordingly */
1680 if ( pOleMenuDescriptor
->bIsServerItem
)
1682 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1683 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1687 if ( pOleMenuDescriptor
)
1688 GlobalUnlock( hOleMenu
);
1690 /* Lookup the hook item for the current thread */
1691 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1693 /* This should never fail!! */
1694 WARN("could not retrieve hHook for current thread!\n" );
1698 /* Pass on the message to the next hooker */
1699 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1702 /*************************************************************************
1703 * OLEMenu_GetMsgProc
1704 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1705 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1707 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1710 HOLEMENU hOleMenu
= 0;
1711 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1712 OleMenuHookItem
*pHookItem
= NULL
;
1715 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1717 /* Check if we're being asked to process a messages */
1718 if ( HC_ACTION
!= code
)
1721 /* Retrieve the current message being dispatched from lParam */
1722 pMsg
= (LPMSG
)lParam
;
1724 /* Check if the message is destined for a window we are interested in:
1725 * If the window has an OLEMenu property we may need to dispatch
1726 * the menu message to its active objects window instead. */
1728 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1732 /* Process menu messages */
1733 switch( pMsg
->message
)
1737 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1739 goto NEXTHOOK
; /* Not a menu message */
1746 /* Get the menu descriptor */
1747 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1748 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1751 /* If the message was for the server dispatch it accordingly */
1752 if ( pOleMenuDescriptor
->bIsServerItem
)
1754 /* Change the hWnd in the message to the active objects hWnd.
1755 * The message loop which reads this message will automatically
1756 * dispatch it to the embedded objects window. */
1757 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1761 if ( pOleMenuDescriptor
)
1762 GlobalUnlock( hOleMenu
);
1764 /* Lookup the hook item for the current thread */
1765 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1767 /* This should never fail!! */
1768 WARN("could not retrieve hHook for current thread!\n" );
1772 /* Pass on the message to the next hooker */
1773 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1776 /***********************************************************************
1777 * OleCreateMenuDescriptor [OLE32.@]
1778 * Creates an OLE menu descriptor for OLE to use when dispatching
1779 * menu messages and commands.
1782 * hmenuCombined - Handle to the objects combined menu
1783 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1786 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1787 HMENU hmenuCombined
,
1788 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1791 OleMenuDescriptor
*pOleMenuDescriptor
;
1794 if ( !hmenuCombined
|| !lpMenuWidths
)
1797 /* Create an OLE menu descriptor */
1798 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1799 sizeof(OleMenuDescriptor
) ) ) )
1802 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1803 if ( !pOleMenuDescriptor
)
1806 /* Initialize menu group widths and hmenu */
1807 for ( i
= 0; i
< 6; i
++ )
1808 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1810 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1811 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1812 GlobalUnlock( hOleMenu
);
1817 /***********************************************************************
1818 * OleDestroyMenuDescriptor [OLE32.@]
1819 * Destroy the shared menu descriptor
1821 HRESULT WINAPI
OleDestroyMenuDescriptor(
1822 HOLEMENU hmenuDescriptor
)
1824 if ( hmenuDescriptor
)
1825 GlobalFree( hmenuDescriptor
);
1829 /***********************************************************************
1830 * OleSetMenuDescriptor [OLE32.@]
1831 * Installs or removes OLE dispatching code for the containers frame window.
1834 * hOleMenu Handle to composite menu descriptor
1835 * hwndFrame Handle to containers frame window
1836 * hwndActiveObject Handle to objects in-place activation window
1837 * lpFrame Pointer to IOleInPlaceFrame on containers window
1838 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1841 * S_OK - menu installed correctly
1842 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1845 * The lpFrame and lpActiveObject parameters are currently ignored
1846 * OLE should install context sensitive help F1 filtering for the app when
1847 * these are non null.
1849 HRESULT WINAPI
OleSetMenuDescriptor(
1852 HWND hwndActiveObject
,
1853 LPOLEINPLACEFRAME lpFrame
,
1854 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1856 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1859 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1860 return E_INVALIDARG
;
1862 if ( lpFrame
|| lpActiveObject
)
1864 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1872 /* Set up a message hook to intercept the containers frame window messages.
1873 * The message filter is responsible for dispatching menu messages from the
1874 * shared menu which are intended for the object.
1877 if ( hOleMenu
) /* Want to install dispatching code */
1879 /* If OLEMenu hooks are already installed for this thread, fail
1880 * Note: This effectively means that OleSetMenuDescriptor cannot
1881 * be called twice in succession on the same frame window
1882 * without first calling it with a null hOleMenu to uninstall
1884 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1887 /* Get the menu descriptor */
1888 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1889 if ( !pOleMenuDescriptor
)
1890 return E_UNEXPECTED
;
1892 /* Update the menu descriptor */
1893 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1894 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1896 GlobalUnlock( hOleMenu
);
1897 pOleMenuDescriptor
= NULL
;
1899 /* Add a menu descriptor windows property to the frame window */
1900 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1902 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1903 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1906 else /* Want to uninstall dispatching code */
1908 /* Uninstall the hooks */
1909 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1912 /* Remove the menu descriptor property from the frame window */
1913 RemovePropW( hwndFrame
, prop_olemenuW
);
1919 /******************************************************************************
1920 * IsAccelerator [OLE32.@]
1921 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1923 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1928 if(!lpMsg
) return FALSE
;
1931 WARN_(accel
)("NULL accel handle\n");
1934 if((lpMsg
->message
!= WM_KEYDOWN
&&
1935 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1936 lpMsg
->message
!= WM_SYSCHAR
&&
1937 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1938 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1939 if (NULL
== lpAccelTbl
)
1943 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1945 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1946 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1950 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1951 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1952 hAccel
, cAccelEntries
,
1953 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1954 for(i
= 0; i
< cAccelEntries
; i
++)
1956 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1959 if(lpMsg
->message
== WM_CHAR
)
1961 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1963 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1969 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1972 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1973 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1974 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1975 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1976 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1977 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1978 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1982 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1984 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1985 { /* ^^ ALT pressed */
1986 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
1994 WARN_(accel
)("couldn't translate accelerator key\n");
1995 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1999 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
2000 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
2004 /***********************************************************************
2005 * ReleaseStgMedium [OLE32.@]
2007 void WINAPI
ReleaseStgMedium(
2010 if (!pmedium
) return;
2012 switch (pmedium
->tymed
)
2016 if ( (pmedium
->pUnkForRelease
==0) &&
2017 (pmedium
->u
.hGlobal
!=0) )
2018 GlobalFree(pmedium
->u
.hGlobal
);
2023 if (pmedium
->u
.lpszFileName
!=0)
2025 if (pmedium
->pUnkForRelease
==0)
2027 DeleteFileW(pmedium
->u
.lpszFileName
);
2030 CoTaskMemFree(pmedium
->u
.lpszFileName
);
2036 if (pmedium
->u
.pstm
!=0)
2038 IStream_Release(pmedium
->u
.pstm
);
2042 case TYMED_ISTORAGE
:
2044 if (pmedium
->u
.pstg
!=0)
2046 IStorage_Release(pmedium
->u
.pstg
);
2052 if ( (pmedium
->pUnkForRelease
==0) &&
2053 (pmedium
->u
.hBitmap
!=0) )
2054 DeleteObject(pmedium
->u
.hBitmap
);
2059 if ( (pmedium
->pUnkForRelease
==0) &&
2060 (pmedium
->u
.hMetaFilePict
!=0) )
2062 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
2063 DeleteMetaFile(pMP
->hMF
);
2064 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
2065 GlobalFree(pmedium
->u
.hMetaFilePict
);
2071 if ( (pmedium
->pUnkForRelease
==0) &&
2072 (pmedium
->u
.hEnhMetaFile
!=0) )
2074 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2082 pmedium
->tymed
=TYMED_NULL
;
2085 * After cleaning up, the unknown is released
2087 if (pmedium
->pUnkForRelease
!=0)
2089 IUnknown_Release(pmedium
->pUnkForRelease
);
2090 pmedium
->pUnkForRelease
= 0;
2095 * OLEDD_Initialize()
2097 * Initializes the OLE drag and drop data structures.
2099 static void OLEDD_Initialize(void)
2103 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2104 wndClass
.style
= CS_GLOBALCLASS
;
2105 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2106 wndClass
.cbClsExtra
= 0;
2107 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2108 wndClass
.hCursor
= 0;
2109 wndClass
.hbrBackground
= 0;
2110 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2112 RegisterClassW (&wndClass
);
2116 * OLEDD_DragTrackerWindowProc()
2118 * This method is the WindowProcedure of the drag n drop tracking
2119 * window. During a drag n Drop operation, an invisible window is created
2120 * to receive the user input and act upon it. This procedure is in charge
2124 #define DRAG_TIMER_ID 1
2126 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2136 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2138 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2139 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2148 case WM_LBUTTONDOWN
:
2149 case WM_MBUTTONDOWN
:
2150 case WM_RBUTTONDOWN
:
2152 TrackerWindowInfo
*trackerInfo
= (TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0);
2153 if (trackerInfo
->trackingDone
) break;
2154 OLEDD_TrackStateChange(trackerInfo
);
2159 KillTimer(hwnd
, DRAG_TIMER_ID
);
2165 * This is a window proc after all. Let's call the default.
2167 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2170 static void drag_enter( TrackerWindowInfo
*info
, HWND new_target
)
2174 info
->curTargetHWND
= new_target
;
2176 while (new_target
&& !is_droptarget( new_target
))
2177 new_target
= GetParent( new_target
);
2179 info
->curDragTarget
= get_droptarget_pointer( new_target
);
2181 if (info
->curDragTarget
)
2183 *info
->pdwEffect
= info
->dwOKEffect
;
2184 hr
= IDropTarget_DragEnter( info
->curDragTarget
, info
->dataObject
,
2185 info
->dwKeyState
, info
->curMousePos
,
2187 *info
->pdwEffect
&= info
->dwOKEffect
;
2189 /* failed DragEnter() means invalid target */
2192 IDropTarget_Release( info
->curDragTarget
);
2193 info
->curDragTarget
= NULL
;
2194 info
->curTargetHWND
= NULL
;
2199 static void drag_end( TrackerWindowInfo
*info
)
2203 info
->trackingDone
= TRUE
;
2206 if (info
->curDragTarget
)
2208 if (info
->returnValue
== DRAGDROP_S_DROP
&&
2209 *info
->pdwEffect
!= DROPEFFECT_NONE
)
2211 *info
->pdwEffect
= info
->dwOKEffect
;
2212 hr
= IDropTarget_Drop( info
->curDragTarget
, info
->dataObject
, info
->dwKeyState
,
2213 info
->curMousePos
, info
->pdwEffect
);
2214 *info
->pdwEffect
&= info
->dwOKEffect
;
2217 info
->returnValue
= hr
;
2221 IDropTarget_DragLeave( info
->curDragTarget
);
2222 *info
->pdwEffect
= DROPEFFECT_NONE
;
2224 IDropTarget_Release( info
->curDragTarget
);
2225 info
->curDragTarget
= NULL
;
2228 *info
->pdwEffect
= DROPEFFECT_NONE
;
2231 static HRESULT
give_feedback( TrackerWindowInfo
*info
)
2237 if (info
->curDragTarget
== NULL
)
2238 *info
->pdwEffect
= DROPEFFECT_NONE
;
2240 hr
= IDropSource_GiveFeedback( info
->dropSource
, *info
->pdwEffect
);
2242 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2244 if (*info
->pdwEffect
& DROPEFFECT_MOVE
)
2246 else if (*info
->pdwEffect
& DROPEFFECT_COPY
)
2248 else if (*info
->pdwEffect
& DROPEFFECT_LINK
)
2251 res
= CURSOR_NODROP
;
2253 cur
= LoadCursorW( hProxyDll
, MAKEINTRESOURCEW( res
) );
2261 * OLEDD_TrackStateChange()
2263 * This method is invoked while a drag and drop operation is in effect.
2266 * trackerInfo - Pointer to the structure identifying the
2267 * drag & drop operation that is currently
2270 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2272 HWND hwndNewTarget
= 0;
2276 * This method may be called from QueryContinueDrag again,
2277 * (i.e. by running message loop) so avoid recursive call chain.
2279 if (trackerInfo
->inTrackCall
) return;
2280 trackerInfo
->inTrackCall
= TRUE
;
2283 * Get the handle of the window under the mouse
2285 pt
.x
= trackerInfo
->curMousePos
.x
;
2286 pt
.y
= trackerInfo
->curMousePos
.y
;
2287 hwndNewTarget
= WindowFromPoint(pt
);
2289 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(trackerInfo
->dropSource
,
2290 trackerInfo
->escPressed
,
2291 trackerInfo
->dwKeyState
);
2293 if (trackerInfo
->curTargetHWND
!= hwndNewTarget
&&
2294 (trackerInfo
->returnValue
== S_OK
||
2295 trackerInfo
->returnValue
== DRAGDROP_S_DROP
))
2297 if (trackerInfo
->curDragTarget
)
2299 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2300 IDropTarget_Release(trackerInfo
->curDragTarget
);
2301 trackerInfo
->curDragTarget
= NULL
;
2302 trackerInfo
->curTargetHWND
= NULL
;
2306 drag_enter( trackerInfo
, hwndNewTarget
);
2308 give_feedback( trackerInfo
);
2312 if (trackerInfo
->returnValue
== S_OK
)
2314 if (trackerInfo
->curDragTarget
)
2316 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2317 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2318 trackerInfo
->dwKeyState
,
2319 trackerInfo
->curMousePos
,
2320 trackerInfo
->pdwEffect
);
2321 *trackerInfo
->pdwEffect
&= trackerInfo
->dwOKEffect
;
2323 give_feedback( trackerInfo
);
2326 drag_end( trackerInfo
);
2328 trackerInfo
->inTrackCall
= FALSE
;
2332 * OLEDD_GetButtonState()
2334 * This method will use the current state of the keyboard to build
2335 * a button state mask equivalent to the one passed in the
2336 * WM_MOUSEMOVE wParam.
2338 static DWORD
OLEDD_GetButtonState(void)
2340 BYTE keyboardState
[256];
2343 GetKeyboardState(keyboardState
);
2345 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2346 keyMask
|= MK_SHIFT
;
2348 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2349 keyMask
|= MK_CONTROL
;
2351 if ( (keyboardState
[VK_MENU
] & 0x80) !=0)
2354 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2355 keyMask
|= MK_LBUTTON
;
2357 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2358 keyMask
|= MK_RBUTTON
;
2360 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2361 keyMask
|= MK_MBUTTON
;
2367 * OLEDD_GetButtonState()
2369 * This method will read the default value of the registry key in
2370 * parameter and extract a DWORD value from it. The registry key value
2371 * can be in a string key or a DWORD key.
2374 * regKey - Key to read the default value from
2375 * pdwValue - Pointer to the location where the DWORD
2376 * value is returned. This value is not modified
2377 * if the value is not found.
2380 static void OLEUTL_ReadRegistryDWORDValue(
2385 DWORD cbData
= sizeof(buffer
);
2389 lres
= RegQueryValueExW(regKey
, L
"", NULL
, &dwKeyType
, (BYTE
*)buffer
, &cbData
);
2391 if (lres
==ERROR_SUCCESS
)
2396 *pdwValue
= *(DWORD
*)buffer
;
2401 *pdwValue
= wcstoul(buffer
, NULL
, 10);
2407 /******************************************************************************
2410 * The operation of this function is documented literally in the WinAPI
2411 * documentation to involve a QueryInterface for the IViewObject interface,
2412 * followed by a call to IViewObject::Draw.
2414 HRESULT WINAPI
OleDraw(
2421 IViewObject
*viewobject
;
2423 if (!pUnk
) return E_INVALIDARG
;
2425 hres
= IUnknown_QueryInterface(pUnk
,
2427 (void**)&viewobject
);
2428 if (SUCCEEDED(hres
))
2430 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, (RECTL
*)rect
, 0, 0, 0);
2431 IViewObject_Release(viewobject
);
2435 return DV_E_NOIVIEWOBJECT
;
2438 /***********************************************************************
2439 * OleTranslateAccelerator [OLE32.@]
2441 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2442 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2446 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2448 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2449 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2454 /******************************************************************************
2455 * OleCreate [OLE32.@]
2458 HRESULT WINAPI
OleCreate(
2462 LPFORMATETC pFormatEtc
,
2463 LPOLECLIENTSITE pClientSite
,
2468 IUnknown
* pUnk
= NULL
;
2469 IOleObject
*pOleObject
= NULL
;
2471 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2472 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2474 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2476 if (SUCCEEDED(hres
))
2477 hres
= IStorage_SetClass(pStg
, rclsid
);
2479 if (pClientSite
&& SUCCEEDED(hres
))
2481 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2482 if (SUCCEEDED(hres
))
2485 IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2489 if (SUCCEEDED(hres
))
2491 IPersistStorage
* pPS
;
2492 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2494 TRACE("trying to set stg %p\n", pStg
);
2495 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2496 TRACE("-- result 0x%08x\n", hres
);
2497 IPersistStorage_Release(pPS
);
2501 if (pClientSite
&& SUCCEEDED(hres
))
2503 TRACE("trying to set clientsite %p\n", pClientSite
);
2504 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2505 TRACE("-- result 0x%08x\n", hres
);
2509 IOleObject_Release(pOleObject
);
2511 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2514 hres
= OleRun(pUnk
);
2515 if (SUCCEEDED(hres
))
2517 IOleCache
*pOleCache
;
2519 if (SUCCEEDED(IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
)))
2522 if (renderopt
== OLERENDER_DRAW
&& !pFormatEtc
) {
2526 pfe
.dwAspect
= DVASPECT_CONTENT
;
2528 pfe
.tymed
= TYMED_NULL
;
2529 hres
= IOleCache_Cache(pOleCache
, &pfe
, ADVF_PRIMEFIRST
, &dwConnection
);
2532 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2533 IOleCache_Release(pOleCache
);
2538 if (FAILED(hres
) && pUnk
)
2540 IUnknown_Release(pUnk
);
2546 TRACE("-- %p\n", pUnk
);
2550 /******************************************************************************
2551 * OleGetAutoConvert [OLE32.@]
2553 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2556 WCHAR buf
[CHARS_IN_GUID
];
2560 res
= COM_OpenKeyForCLSID(clsidOld
, L
"AutoConvertTo", KEY_READ
, &hkey
);
2565 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2567 res
= REGDB_E_KEYMISSING
;
2570 res
= CLSIDFromString(buf
, pClsidNew
);
2572 if (hkey
) RegCloseKey(hkey
);
2576 /******************************************************************************
2577 * OleSetAutoConvert [OLE32.@]
2579 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2582 WCHAR szClsidNew
[CHARS_IN_GUID
];
2585 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2587 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2590 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2591 if (RegSetValueW(hkey
, L
"AutoConvertTo", REG_SZ
, szClsidNew
, (lstrlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2593 res
= REGDB_E_WRITEREGDB
;
2598 if (hkey
) RegCloseKey(hkey
);
2602 /******************************************************************************
2603 * OleDoAutoConvert [OLE32.@]
2605 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2607 WCHAR
*user_type_old
, *user_type_new
;
2613 TRACE("(%p, %p)\n", pStg
, pClsidNew
);
2615 *pClsidNew
= CLSID_NULL
;
2617 return E_INVALIDARG
;
2618 hr
= IStorage_Stat(pStg
, &stat
, STATFLAG_NONAME
);
2622 *pClsidNew
= stat
.clsid
;
2623 hr
= OleGetAutoConvert(&stat
.clsid
, &clsid
);
2627 hr
= IStorage_SetClass(pStg
, &clsid
);
2631 hr
= ReadFmtUserTypeStg(pStg
, &cf
, &user_type_old
);
2634 user_type_new
= NULL
;
2637 hr
= OleRegGetUserType(&clsid
, USERCLASSTYPE_FULL
, &user_type_new
);
2639 user_type_new
= NULL
;
2641 hr
= WriteFmtUserTypeStg(pStg
, cf
, user_type_new
);
2642 CoTaskMemFree(user_type_new
);
2645 CoTaskMemFree(user_type_old
);
2646 IStorage_SetClass(pStg
, &stat
.clsid
);
2650 hr
= SetConvertStg(pStg
, TRUE
);
2653 WriteFmtUserTypeStg(pStg
, cf
, user_type_old
);
2654 IStorage_SetClass(pStg
, &stat
.clsid
);
2658 CoTaskMemFree(user_type_old
);
2662 /******************************************************************************
2663 * OleIsRunning [OLE32.@]
2665 BOOL WINAPI
OleIsRunning(LPOLEOBJECT object
)
2667 IRunnableObject
*pRunnable
;
2671 TRACE("(%p)\n", object
);
2673 if (!object
) return FALSE
;
2675 hr
= IOleObject_QueryInterface(object
, &IID_IRunnableObject
, (void **)&pRunnable
);
2678 running
= IRunnableObject_IsRunning(pRunnable
);
2679 IRunnableObject_Release(pRunnable
);
2683 /***********************************************************************
2684 * OleNoteObjectVisible [OLE32.@]
2686 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2688 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2689 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2692 /***********************************************************************
2693 * PropSysAllocString [OLE32.@]
2695 * Forward to oleaut32.
2697 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2699 return SysAllocString(str
);
2702 /***********************************************************************
2703 * PropSysFreeString [OLE32.@]
2705 * Forward to oleaut32.
2707 void WINAPI
PropSysFreeString(LPOLESTR str
)