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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
49 #include "wine/list.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
54 WINE_DECLARE_DEBUG_CHANNEL(accel
);
56 /******************************************************************************
57 * These are static/global variables and internal data structures that the
58 * OLE module uses to maintain it's state.
60 typedef struct tagTrackerWindowInfo
62 IDataObject
* dataObject
;
63 IDropSource
* dropSource
;
70 HWND curTargetHWND
; /* window the mouse is hovering over */
71 HWND curDragTargetHWND
; /* might be a ancestor of curTargetHWND */
72 IDropTarget
* curDragTarget
;
73 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
74 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
77 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
79 HWND hwndFrame
; /* The containers frame window */
80 HWND hwndActiveObject
; /* The active objects window */
81 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
82 HMENU hmenuCombined
; /* The combined menu */
83 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
86 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
88 DWORD tid
; /* Thread Id */
89 HANDLE hHeap
; /* Heap this is allocated from */
90 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
91 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
92 struct tagOleMenuHookItem
*next
;
95 static OleMenuHookItem
*hook_list
;
98 * This is the lock count on the OLE library. It is controlled by the
99 * OLEInitialize/OLEUninitialize methods.
101 static LONG OLE_moduleLockCount
= 0;
104 * Name of our registered window class.
106 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
107 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
110 * Name of menu descriptor property.
112 static const WCHAR prop_olemenuW
[] =
113 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
115 /* property to store IDropTarget pointer */
116 static const WCHAR prop_oledroptarget
[] =
117 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
119 /* property to store Marshalled IDropTarget pointer */
120 static const WCHAR prop_marshalleddroptarget
[] =
121 {'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};
123 static const WCHAR clsidfmtW
[] =
124 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
125 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
126 '%','0','2','x','%','0','2','x','}','\\',0};
128 static const WCHAR emptyW
[] = { 0 };
130 /******************************************************************************
131 * These are the prototypes of miscellaneous utility methods
133 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
135 /******************************************************************************
136 * These are the prototypes of the utility methods used to manage a shared menu
138 static void OLEMenu_Initialize(void);
139 static void OLEMenu_UnInitialize(void);
140 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
141 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
142 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
143 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
144 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
145 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
146 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
148 /******************************************************************************
149 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
151 extern void OLEClipbrd_UnInitialize(void);
152 extern void OLEClipbrd_Initialize(void);
154 /******************************************************************************
155 * These are the prototypes of the utility methods used for OLE Drag n Drop
157 static void OLEDD_Initialize(void);
158 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
159 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
);
160 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
);
161 static DWORD
OLEDD_GetButtonState(void);
163 /******************************************************************************
164 * OleBuildVersion [OLE32.@]
166 DWORD WINAPI
OleBuildVersion(void)
168 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
169 return (rmm
<<16)+rup
;
172 /***********************************************************************
173 * OleInitialize (OLE32.@)
175 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
179 TRACE("(%p)\n", reserved
);
182 * The first duty of the OleInitialize is to initialize the COM libraries.
184 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
187 * If the CoInitializeEx call failed, the OLE libraries can't be
193 if (!COM_CurrentInfo()->ole_inits
)
197 * Then, it has to initialize the OLE specific modules.
201 * Object linking and Embedding
202 * In-place activation
204 if (!COM_CurrentInfo()->ole_inits
++ &&
205 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
208 * Initialize the libraries.
210 TRACE("() - Initializing the OLE libraries\n");
215 OLEClipbrd_Initialize();
225 OLEMenu_Initialize();
231 /******************************************************************************
232 * OleUninitialize [OLE32.@]
234 void WINAPI
OleUninitialize(void)
239 * If we hit the bottom of the lock stack, free the libraries.
241 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
244 * Actually free the libraries.
246 TRACE("() - Freeing the last reference count\n");
251 OLEClipbrd_UnInitialize();
256 OLEMenu_UnInitialize();
260 * Then, uninitialize the COM libraries.
265 /******************************************************************************
266 * OleInitializeWOW [OLE32.@]
268 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
269 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
273 /*************************************************************
274 * get_droptarget_handle
276 * Retrieve a handle to the map containing the marshalled IDropTarget.
277 * This handle belongs to the process that called RegisterDragDrop.
278 * See get_droptarget_local_handle().
280 static inline HANDLE
get_droptarget_handle(HWND hwnd
)
282 return GetPropW(hwnd
, prop_marshalleddroptarget
);
285 /*************************************************************
288 * Is the window a droptarget.
290 static inline BOOL
is_droptarget(HWND hwnd
)
292 return get_droptarget_handle(hwnd
) ? TRUE
: FALSE
;
295 /*************************************************************
296 * get_droptarget_local_handle
298 * Retrieve a handle to the map containing the marshalled IDropTarget.
299 * The handle should be closed when finished with.
301 static HANDLE
get_droptarget_local_handle(HWND hwnd
)
303 HANDLE handle
, local_handle
= 0;
305 handle
= get_droptarget_handle(hwnd
);
312 GetWindowThreadProcessId(hwnd
, &pid
);
313 process
= OpenProcess(PROCESS_DUP_HANDLE
, FALSE
, pid
);
316 DuplicateHandle(process
, handle
, GetCurrentProcess(), &local_handle
, 0, FALSE
, DUPLICATE_SAME_ACCESS
);
317 CloseHandle(process
);
323 /***********************************************************************
324 * create_map_from_stream
326 * Helper for RegisterDragDrop. Creates a file mapping object
327 * with the contents of the provided stream. The stream must
328 * be a global memory backed stream.
330 static HRESULT
create_map_from_stream(IStream
*stream
, HANDLE
*map
)
337 hr
= GetHGlobalFromStream(stream
, &hmem
);
338 if(FAILED(hr
)) return hr
;
340 size
= GlobalSize(hmem
);
341 *map
= CreateFileMappingW(INVALID_HANDLE_VALUE
, NULL
, PAGE_READWRITE
, 0, size
, NULL
);
342 if(!*map
) return E_OUTOFMEMORY
;
344 data
= MapViewOfFile(*map
, FILE_MAP_WRITE
, 0, 0, size
);
345 memcpy(data
, GlobalLock(hmem
), size
);
347 UnmapViewOfFile(data
);
351 /***********************************************************************
352 * create_stream_from_map
354 * Creates a stream from the provided map.
356 static HRESULT
create_stream_from_map(HANDLE map
, IStream
**stream
)
358 HRESULT hr
= E_OUTOFMEMORY
;
361 MEMORY_BASIC_INFORMATION info
;
363 data
= MapViewOfFile(map
, FILE_MAP_READ
, 0, 0, 0);
366 VirtualQuery(data
, &info
, sizeof(info
));
367 TRACE("size %d\n", (int)info
.RegionSize
);
369 hmem
= GlobalAlloc(GMEM_MOVEABLE
, info
.RegionSize
);
372 memcpy(GlobalLock(hmem
), data
, info
.RegionSize
);
374 hr
= CreateStreamOnHGlobal(hmem
, TRUE
, stream
);
376 UnmapViewOfFile(data
);
380 /***********************************************************************
381 * get_droptarget_pointer
383 * Retrieves the marshalled IDropTarget from the window.
385 static IDropTarget
* get_droptarget_pointer(HWND hwnd
)
387 IDropTarget
*droptarget
= NULL
;
391 map
= get_droptarget_local_handle(hwnd
);
392 if(!map
) return NULL
;
394 if(SUCCEEDED(create_stream_from_map(map
, &stream
)))
396 CoUnmarshalInterface(stream
, &IID_IDropTarget
, (void**)&droptarget
);
397 IStream_Release(stream
);
403 /***********************************************************************
404 * RegisterDragDrop (OLE32.@)
406 HRESULT WINAPI
RegisterDragDrop(HWND hwnd
, LPDROPTARGET pDropTarget
)
414 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
416 if (!COM_CurrentApt())
418 ERR("COM not initialized\n");
419 return E_OUTOFMEMORY
;
427 ERR("invalid hwnd %p\n", hwnd
);
428 return DRAGDROP_E_INVALIDHWND
;
431 /* block register for other processes windows */
432 GetWindowThreadProcessId(hwnd
, &pid
);
433 if (pid
!= GetCurrentProcessId())
435 FIXME("register for another process windows is disabled\n");
436 return DRAGDROP_E_INVALIDHWND
;
439 /* check if the window is already registered */
440 if (is_droptarget(hwnd
))
441 return DRAGDROP_E_ALREADYREGISTERED
;
444 * Marshal the drop target pointer into a shared memory map and
445 * store the map's handle in a Wine specific window prop. We also
446 * store the drop target pointer itself in the
447 * "OleDropTargetInterface" prop for compatibility with Windows.
450 hr
= CreateStreamOnHGlobal(NULL
, TRUE
, &stream
);
451 if(FAILED(hr
)) return hr
;
453 hr
= IDropTarget_QueryInterface(pDropTarget
, &IID_IUnknown
, (void**)&unk
);
456 IStream_Release(stream
);
459 hr
= CoMarshalInterface(stream
, &IID_IDropTarget
, unk
, MSHCTX_LOCAL
, NULL
, MSHLFLAGS_TABLESTRONG
);
460 IUnknown_Release(unk
);
464 hr
= create_map_from_stream(stream
, &map
);
467 IDropTarget_AddRef(pDropTarget
);
468 SetPropW(hwnd
, prop_oledroptarget
, pDropTarget
);
469 SetPropW(hwnd
, prop_marshalleddroptarget
, map
);
475 IStream_Seek(stream
, zero
, STREAM_SEEK_SET
, NULL
);
476 CoReleaseMarshalData(stream
);
479 IStream_Release(stream
);
484 /***********************************************************************
485 * RevokeDragDrop (OLE32.@)
487 HRESULT WINAPI
RevokeDragDrop(HWND hwnd
)
491 IDropTarget
*drop_target
;
494 TRACE("(%p)\n", hwnd
);
498 ERR("invalid hwnd %p\n", hwnd
);
499 return DRAGDROP_E_INVALIDHWND
;
502 /* no registration data */
503 if (!(map
= get_droptarget_handle(hwnd
)))
504 return DRAGDROP_E_NOTREGISTERED
;
506 drop_target
= GetPropW(hwnd
, prop_oledroptarget
);
507 if(drop_target
) IDropTarget_Release(drop_target
);
509 RemovePropW(hwnd
, prop_oledroptarget
);
510 RemovePropW(hwnd
, prop_marshalleddroptarget
);
512 hr
= create_stream_from_map(map
, &stream
);
515 CoReleaseMarshalData(stream
);
516 IStream_Release(stream
);
523 /***********************************************************************
524 * OleRegGetUserType (OLE32.@)
526 * This implementation of OleRegGetUserType ignores the dwFormOfType
527 * parameter and always returns the full name of the object. This is
528 * not too bad since this is the case for many objects because of the
529 * way they are registered.
531 HRESULT WINAPI
OleRegGetUserType(
534 LPOLESTR
* pszUserType
)
543 * Initialize the out parameter.
548 * Build the key name we're looking for
550 sprintfW( keyName
, clsidfmtW
,
551 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
552 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
553 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
555 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwFormOfType
, pszUserType
);
558 * Open the class id Key
560 hres
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
564 if (hres
!= ERROR_SUCCESS
)
565 return REGDB_E_CLASSNOTREG
;
568 * Retrieve the size of the name string.
572 hres
= RegQueryValueExW(clsidKey
,
579 if (hres
!=ERROR_SUCCESS
)
581 RegCloseKey(clsidKey
);
582 return REGDB_E_READREGDB
;
586 * Allocate a buffer for the registry value.
588 *pszUserType
= CoTaskMemAlloc(cbData
);
590 if (*pszUserType
==NULL
)
592 RegCloseKey(clsidKey
);
593 return E_OUTOFMEMORY
;
596 hres
= RegQueryValueExW(clsidKey
,
600 (LPBYTE
) *pszUserType
,
603 RegCloseKey(clsidKey
);
605 if (hres
!= ERROR_SUCCESS
)
607 CoTaskMemFree(*pszUserType
);
610 return REGDB_E_READREGDB
;
616 /***********************************************************************
617 * DoDragDrop [OLE32.@]
619 HRESULT WINAPI
DoDragDrop (
620 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
621 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
622 DWORD dwOKEffect
, /* [in] effects allowed by the source */
623 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
625 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
626 TrackerWindowInfo trackerInfo
;
627 HWND hwndTrackWindow
;
630 TRACE("(%p, %p, %d, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
632 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
636 * Setup the drag n drop tracking window.
639 trackerInfo
.dataObject
= pDataObject
;
640 trackerInfo
.dropSource
= pDropSource
;
641 trackerInfo
.dwOKEffect
= dwOKEffect
;
642 trackerInfo
.pdwEffect
= pdwEffect
;
643 trackerInfo
.trackingDone
= FALSE
;
644 trackerInfo
.escPressed
= FALSE
;
645 trackerInfo
.curDragTargetHWND
= 0;
646 trackerInfo
.curTargetHWND
= 0;
647 trackerInfo
.curDragTarget
= 0;
649 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
650 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
651 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
657 * Capture the mouse input
659 SetCapture(hwndTrackWindow
);
664 * Pump messages. All mouse input should go to the capture window.
666 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
668 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
669 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
670 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
672 if ( (msg
.message
>= WM_KEYFIRST
) &&
673 (msg
.message
<= WM_KEYLAST
) )
676 * When keyboard messages are sent to windows on this thread, we
677 * want to ignore notify the drop source that the state changed.
678 * in the case of the Escape key, we also notify the drop source
679 * we give it a special meaning.
681 if ( (msg
.message
==WM_KEYDOWN
) &&
682 (msg
.wParam
==VK_ESCAPE
) )
684 trackerInfo
.escPressed
= TRUE
;
688 * Notify the drop source.
690 OLEDD_TrackStateChange(&trackerInfo
);
695 * Dispatch the messages only when it's not a keyboard message.
697 DispatchMessageW(&msg
);
701 /* re-post the quit message to outer message loop */
702 if (msg
.message
== WM_QUIT
)
703 PostQuitMessage(msg
.wParam
);
705 * Destroy the temporary window.
707 DestroyWindow(hwndTrackWindow
);
709 return trackerInfo
.returnValue
;
715 /***********************************************************************
716 * OleQueryLinkFromData [OLE32.@]
718 HRESULT WINAPI
OleQueryLinkFromData(
719 IDataObject
* pSrcDataObject
)
721 FIXME("(%p),stub!\n", pSrcDataObject
);
725 /***********************************************************************
726 * OleRegGetMiscStatus [OLE32.@]
728 HRESULT WINAPI
OleRegGetMiscStatus(
733 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
734 static const WCHAR dfmtW
[] = {'%','d',0};
742 * Initialize the out parameter.
747 * Build the key name we're looking for
749 sprintfW( keyName
, clsidfmtW
,
750 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
751 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
752 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
754 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwAspect
, pdwStatus
);
757 * Open the class id Key
759 result
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
763 if (result
!= ERROR_SUCCESS
)
764 return REGDB_E_CLASSNOTREG
;
769 result
= RegOpenKeyW(clsidKey
,
774 if (result
!= ERROR_SUCCESS
)
776 RegCloseKey(clsidKey
);
777 return REGDB_E_READREGDB
;
781 * Read the default value
783 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
786 * Open the key specific to the requested aspect.
788 sprintfW(keyName
, dfmtW
, dwAspect
);
790 result
= RegOpenKeyW(miscStatusKey
,
794 if (result
== ERROR_SUCCESS
)
796 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
797 RegCloseKey(aspectKey
);
803 RegCloseKey(miscStatusKey
);
804 RegCloseKey(clsidKey
);
809 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
813 const IEnumOLEVERBVtbl
*lpvtbl
;
820 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
821 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
823 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
824 if (IsEqualIID(riid
, &IID_IUnknown
) ||
825 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
827 IUnknown_AddRef(iface
);
831 return E_NOINTERFACE
;
834 static ULONG WINAPI
EnumOLEVERB_AddRef(
837 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
839 return InterlockedIncrement(&This
->ref
);
842 static ULONG WINAPI
EnumOLEVERB_Release(
845 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
846 LONG refs
= InterlockedDecrement(&This
->ref
);
850 RegCloseKey(This
->hkeyVerb
);
851 HeapFree(GetProcessHeap(), 0, This
);
856 static HRESULT WINAPI
EnumOLEVERB_Next(
857 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
860 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
863 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
868 for (; celt
; celt
--, rgelt
++)
873 LPWSTR pwszMenuFlags
;
875 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
876 if (res
== ERROR_NO_MORE_ITEMS
)
881 else if (res
!= ERROR_SUCCESS
)
883 ERR("RegEnumKeyW failed with error %d\n", res
);
884 hr
= REGDB_E_READREGDB
;
887 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
888 if (res
!= ERROR_SUCCESS
)
890 ERR("RegQueryValueW failed with error %d\n", res
);
891 hr
= REGDB_E_READREGDB
;
894 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
900 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
901 if (res
!= ERROR_SUCCESS
)
903 ERR("RegQueryValueW failed with error %d\n", res
);
904 hr
= REGDB_E_READREGDB
;
905 CoTaskMemFree(pwszOLEVERB
);
909 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
910 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
913 hr
= OLEOBJ_E_INVALIDVERB
;
914 CoTaskMemFree(pwszOLEVERB
);
917 /* nul terminate the name string and advance to first character */
918 *pwszMenuFlags
= '\0';
920 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
923 hr
= OLEOBJ_E_INVALIDVERB
;
924 CoTaskMemFree(pwszOLEVERB
);
927 /* nul terminate the menu string and advance to first character */
931 /* fill out structure for this verb */
932 rgelt
->lVerb
= atolW(wszSubKey
);
933 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
934 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
935 rgelt
->grfAttribs
= atolW(pwszAttribs
);
944 static HRESULT WINAPI
EnumOLEVERB_Skip(
945 IEnumOLEVERB
*iface
, ULONG celt
)
947 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
949 TRACE("(%d)\n", celt
);
955 static HRESULT WINAPI
EnumOLEVERB_Reset(
958 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
966 static HRESULT WINAPI
EnumOLEVERB_Clone(
968 IEnumOLEVERB
**ppenum
)
970 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
972 TRACE("(%p)\n", ppenum
);
973 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
974 return HRESULT_FROM_WIN32(GetLastError());
975 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
978 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
980 EnumOLEVERB_QueryInterface
,
989 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
991 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
994 RegCloseKey(hkeyVerb
);
995 return E_OUTOFMEMORY
;
997 This
->lpvtbl
= &EnumOLEVERB_VTable
;
1000 This
->hkeyVerb
= hkeyVerb
;
1001 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
1005 /***********************************************************************
1006 * OleRegEnumVerbs [OLE32.@]
1008 * Enumerates verbs associated with a class stored in the registry.
1011 * clsid [I] Class ID to enumerate the verbs for.
1012 * ppenum [O] Enumerator.
1016 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1017 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1018 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1019 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1021 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
1026 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
1028 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
1030 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
1033 if (res
== REGDB_E_CLASSNOTREG
)
1034 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
1035 else if (res
== REGDB_E_KEYMISSING
)
1036 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
1038 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1039 debugstr_guid(clsid
), res
);
1043 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
1044 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
1045 if (res
!= ERROR_SUCCESS
)
1047 ERR("failed to get subkey count with error %d\n", GetLastError());
1048 return REGDB_E_READREGDB
;
1053 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
1054 RegCloseKey(hkeyVerb
);
1055 return OLEOBJ_E_NOVERBS
;
1058 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
1061 /******************************************************************************
1062 * OleSetContainedObject [OLE32.@]
1064 HRESULT WINAPI
OleSetContainedObject(
1068 IRunnableObject
* runnable
= NULL
;
1071 TRACE("(%p,%x)\n", pUnknown
, fContained
);
1073 hres
= IUnknown_QueryInterface(pUnknown
,
1074 &IID_IRunnableObject
,
1077 if (SUCCEEDED(hres
))
1079 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
1081 IRunnableObject_Release(runnable
);
1089 /******************************************************************************
1092 * Set the OLE object to the running state.
1095 * pUnknown [I] OLE object to run.
1099 * Failure: Any HRESULT code.
1101 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
1103 IRunnableObject
*runable
;
1106 TRACE("(%p)\n", pUnknown
);
1108 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
1110 return S_OK
; /* Appears to return no error. */
1112 hres
= IRunnableObject_Run(runable
, NULL
);
1113 IRunnableObject_Release(runable
);
1117 /******************************************************************************
1120 HRESULT WINAPI
OleLoad(
1123 LPOLECLIENTSITE pClientSite
,
1126 IPersistStorage
* persistStorage
= NULL
;
1128 IOleObject
* pOleObject
= NULL
;
1129 STATSTG storageInfo
;
1132 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
1137 * TODO, Conversion ... OleDoAutoConvert
1141 * Get the class ID for the object.
1143 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1146 * Now, try and create the handler for the object
1148 hres
= CoCreateInstance(&storageInfo
.clsid
,
1150 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1155 * If that fails, as it will most times, load the default
1160 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1167 * If we couldn't find a handler... this is bad. Abort the whole thing.
1174 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1175 if (SUCCEEDED(hres
))
1178 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1182 if (SUCCEEDED(hres
))
1184 * Initialize the object with it's IPersistStorage interface.
1186 hres
= IOleObject_QueryInterface(pUnk
,
1187 &IID_IPersistStorage
,
1188 (void**)&persistStorage
);
1190 if (SUCCEEDED(hres
))
1192 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1194 IPersistStorage_Release(persistStorage
);
1195 persistStorage
= NULL
;
1198 if (SUCCEEDED(hres
) && pClientSite
)
1200 * Inform the new object of it's client site.
1202 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1205 * Cleanup interfaces used internally
1208 IOleObject_Release(pOleObject
);
1210 if (SUCCEEDED(hres
))
1214 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1215 if (SUCCEEDED(hres1
))
1217 FIXME("handle OLE link\n");
1218 IOleLink_Release(pOleLink
);
1224 IUnknown_Release(pUnk
);
1233 /***********************************************************************
1236 HRESULT WINAPI
OleSave(
1237 LPPERSISTSTORAGE pPS
,
1244 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1247 * First, we transfer the class ID (if available)
1249 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1251 if (SUCCEEDED(hres
))
1253 WriteClassStg(pStg
, &objectClass
);
1257 * Then, we ask the object to save itself to the
1258 * storage. If it is successful, we commit the storage.
1260 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1262 if (SUCCEEDED(hres
))
1264 IStorage_Commit(pStg
,
1272 /******************************************************************************
1273 * OleLockRunning [OLE32.@]
1275 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1277 IRunnableObject
* runnable
= NULL
;
1280 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1282 hres
= IUnknown_QueryInterface(pUnknown
,
1283 &IID_IRunnableObject
,
1286 if (SUCCEEDED(hres
))
1288 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1290 IRunnableObject_Release(runnable
);
1299 /**************************************************************************
1300 * Internal methods to manage the shared OLE menu in response to the
1301 * OLE***MenuDescriptor API
1305 * OLEMenu_Initialize()
1307 * Initializes the OLEMENU data structures.
1309 static void OLEMenu_Initialize(void)
1314 * OLEMenu_UnInitialize()
1316 * Releases the OLEMENU data structures.
1318 static void OLEMenu_UnInitialize(void)
1322 /*************************************************************************
1323 * OLEMenu_InstallHooks
1324 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1326 * RETURNS: TRUE if message hooks were successfully installed
1329 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1331 OleMenuHookItem
*pHookItem
;
1333 /* Create an entry for the hook table */
1334 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1335 sizeof(OleMenuHookItem
)) ) )
1338 pHookItem
->tid
= tid
;
1339 pHookItem
->hHeap
= GetProcessHeap();
1340 pHookItem
->CallWndProc_hHook
= NULL
;
1342 /* Install a thread scope message hook for WH_GETMESSAGE */
1343 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1344 0, GetCurrentThreadId() );
1345 if ( !pHookItem
->GetMsg_hHook
)
1348 /* Install a thread scope message hook for WH_CALLWNDPROC */
1349 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1350 0, GetCurrentThreadId() );
1351 if ( !pHookItem
->CallWndProc_hHook
)
1354 /* Insert the hook table entry */
1355 pHookItem
->next
= hook_list
;
1356 hook_list
= pHookItem
;
1361 /* Unhook any hooks */
1362 if ( pHookItem
->GetMsg_hHook
)
1363 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1364 if ( pHookItem
->CallWndProc_hHook
)
1365 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1366 /* Release the hook table entry */
1367 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1372 /*************************************************************************
1373 * OLEMenu_UnInstallHooks
1374 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1376 * RETURNS: TRUE if message hooks were successfully installed
1379 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1381 OleMenuHookItem
*pHookItem
= NULL
;
1382 OleMenuHookItem
**ppHook
= &hook_list
;
1386 if ((*ppHook
)->tid
== tid
)
1388 pHookItem
= *ppHook
;
1389 *ppHook
= pHookItem
->next
;
1392 ppHook
= &(*ppHook
)->next
;
1394 if (!pHookItem
) return FALSE
;
1396 /* Uninstall the hooks installed for this thread */
1397 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1399 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1402 /* Release the hook table entry */
1403 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1408 /* Release the hook table entry */
1409 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1414 /*************************************************************************
1415 * OLEMenu_IsHookInstalled
1416 * Tests if OLEMenu hooks have been installed for a thread
1418 * RETURNS: The pointer and index of the hook table entry for the tid
1419 * NULL and -1 for the index if no hooks were installed for this thread
1421 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1423 OleMenuHookItem
*pHookItem
;
1425 /* Do a simple linear search for an entry whose tid matches ours.
1426 * We really need a map but efficiency is not a concern here. */
1427 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1429 if ( tid
== pHookItem
->tid
)
1436 /***********************************************************************
1437 * OLEMenu_FindMainMenuIndex
1439 * Used by OLEMenu API to find the top level group a menu item belongs to.
1440 * On success pnPos contains the index of the item in the top level menu group
1442 * RETURNS: TRUE if the ID was found, FALSE on failure
1444 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1448 nItems
= GetMenuItemCount( hMainMenu
);
1450 for (i
= 0; i
< nItems
; i
++)
1454 /* Is the current item a submenu? */
1455 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1457 /* If the handle is the same we're done */
1458 if ( hsubmenu
== hPopupMenu
)
1464 /* Recursively search without updating pnPos */
1465 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1477 /***********************************************************************
1478 * OLEMenu_SetIsServerMenu
1480 * Checks whether a popup menu belongs to a shared menu group which is
1481 * owned by the server, and sets the menu descriptor state accordingly.
1482 * All menu messages from these groups should be routed to the server.
1484 * RETURNS: TRUE if the popup menu is part of a server owned group
1485 * FALSE if the popup menu is part of a container owned group
1487 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1489 UINT nPos
= 0, nWidth
, i
;
1491 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1493 /* Don't bother searching if the popup is the combined menu itself */
1494 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1497 /* Find the menu item index in the shared OLE menu that this item belongs to */
1498 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1501 /* The group widths array has counts for the number of elements
1502 * in the groups File, Edit, Container, Object, Window, Help.
1503 * The Edit, Object & Help groups belong to the server object
1504 * and the other three belong to the container.
1505 * Loop through the group widths and locate the group we are a member of.
1507 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1509 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1510 if ( nPos
< nWidth
)
1512 /* Odd elements are server menu widths */
1513 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1518 return pOleMenuDescriptor
->bIsServerItem
;
1521 /*************************************************************************
1522 * OLEMenu_CallWndProc
1523 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1524 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1526 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1529 HOLEMENU hOleMenu
= 0;
1530 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1531 OleMenuHookItem
*pHookItem
= NULL
;
1534 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1536 /* Check if we're being asked to process the message */
1537 if ( HC_ACTION
!= code
)
1540 /* Retrieve the current message being dispatched from lParam */
1541 pMsg
= (LPCWPSTRUCT
)lParam
;
1543 /* Check if the message is destined for a window we are interested in:
1544 * If the window has an OLEMenu property we may need to dispatch
1545 * the menu message to its active objects window instead. */
1547 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1551 /* Get the menu descriptor */
1552 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1553 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1556 /* Process menu messages */
1557 switch( pMsg
->message
)
1561 /* Reset the menu descriptor state */
1562 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1564 /* Send this message to the server as well */
1565 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1566 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1570 case WM_INITMENUPOPUP
:
1572 /* Save the state for whether this is a server owned menu */
1573 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1579 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1580 if ( fuFlags
& MF_SYSMENU
)
1583 /* Save the state for whether this is a server owned popup menu */
1584 else if ( fuFlags
& MF_POPUP
)
1585 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1592 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1593 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1594 goto NEXTHOOK
; /* Not a menu message */
1603 /* If the message was for the server dispatch it accordingly */
1604 if ( pOleMenuDescriptor
->bIsServerItem
)
1606 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1607 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1611 if ( pOleMenuDescriptor
)
1612 GlobalUnlock( hOleMenu
);
1614 /* Lookup the hook item for the current thread */
1615 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1617 /* This should never fail!! */
1618 WARN("could not retrieve hHook for current thread!\n" );
1622 /* Pass on the message to the next hooker */
1623 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1626 /*************************************************************************
1627 * OLEMenu_GetMsgProc
1628 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1629 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1631 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1634 HOLEMENU hOleMenu
= 0;
1635 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1636 OleMenuHookItem
*pHookItem
= NULL
;
1639 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1641 /* Check if we're being asked to process a messages */
1642 if ( HC_ACTION
!= code
)
1645 /* Retrieve the current message being dispatched from lParam */
1646 pMsg
= (LPMSG
)lParam
;
1648 /* Check if the message is destined for a window we are interested in:
1649 * If the window has an OLEMenu property we may need to dispatch
1650 * the menu message to its active objects window instead. */
1652 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1656 /* Process menu messages */
1657 switch( pMsg
->message
)
1661 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1663 goto NEXTHOOK
; /* Not a menu message */
1670 /* Get the menu descriptor */
1671 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1672 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1675 /* If the message was for the server dispatch it accordingly */
1676 if ( pOleMenuDescriptor
->bIsServerItem
)
1678 /* Change the hWnd in the message to the active objects hWnd.
1679 * The message loop which reads this message will automatically
1680 * dispatch it to the embedded objects window. */
1681 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1685 if ( pOleMenuDescriptor
)
1686 GlobalUnlock( hOleMenu
);
1688 /* Lookup the hook item for the current thread */
1689 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1691 /* This should never fail!! */
1692 WARN("could not retrieve hHook for current thread!\n" );
1696 /* Pass on the message to the next hooker */
1697 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1700 /***********************************************************************
1701 * OleCreateMenuDescriptor [OLE32.@]
1702 * Creates an OLE menu descriptor for OLE to use when dispatching
1703 * menu messages and commands.
1706 * hmenuCombined - Handle to the objects combined menu
1707 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1710 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1711 HMENU hmenuCombined
,
1712 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1715 OleMenuDescriptor
*pOleMenuDescriptor
;
1718 if ( !hmenuCombined
|| !lpMenuWidths
)
1721 /* Create an OLE menu descriptor */
1722 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1723 sizeof(OleMenuDescriptor
) ) ) )
1726 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1727 if ( !pOleMenuDescriptor
)
1730 /* Initialize menu group widths and hmenu */
1731 for ( i
= 0; i
< 6; i
++ )
1732 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1734 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1735 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1736 GlobalUnlock( hOleMenu
);
1741 /***********************************************************************
1742 * OleDestroyMenuDescriptor [OLE32.@]
1743 * Destroy the shared menu descriptor
1745 HRESULT WINAPI
OleDestroyMenuDescriptor(
1746 HOLEMENU hmenuDescriptor
)
1748 if ( hmenuDescriptor
)
1749 GlobalFree( hmenuDescriptor
);
1753 /***********************************************************************
1754 * OleSetMenuDescriptor [OLE32.@]
1755 * Installs or removes OLE dispatching code for the containers frame window.
1758 * hOleMenu Handle to composite menu descriptor
1759 * hwndFrame Handle to containers frame window
1760 * hwndActiveObject Handle to objects in-place activation window
1761 * lpFrame Pointer to IOleInPlaceFrame on containers window
1762 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1765 * S_OK - menu installed correctly
1766 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1769 * The lpFrame and lpActiveObject parameters are currently ignored
1770 * OLE should install context sensitive help F1 filtering for the app when
1771 * these are non null.
1773 HRESULT WINAPI
OleSetMenuDescriptor(
1776 HWND hwndActiveObject
,
1777 LPOLEINPLACEFRAME lpFrame
,
1778 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1780 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1783 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1784 return E_INVALIDARG
;
1786 if ( lpFrame
|| lpActiveObject
)
1788 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1796 /* Set up a message hook to intercept the containers frame window messages.
1797 * The message filter is responsible for dispatching menu messages from the
1798 * shared menu which are intended for the object.
1801 if ( hOleMenu
) /* Want to install dispatching code */
1803 /* If OLEMenu hooks are already installed for this thread, fail
1804 * Note: This effectively means that OleSetMenuDescriptor cannot
1805 * be called twice in succession on the same frame window
1806 * without first calling it with a null hOleMenu to uninstall */
1807 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1810 /* Get the menu descriptor */
1811 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1812 if ( !pOleMenuDescriptor
)
1813 return E_UNEXPECTED
;
1815 /* Update the menu descriptor */
1816 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1817 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1819 GlobalUnlock( hOleMenu
);
1820 pOleMenuDescriptor
= NULL
;
1822 /* Add a menu descriptor windows property to the frame window */
1823 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1825 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1826 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1829 else /* Want to uninstall dispatching code */
1831 /* Uninstall the hooks */
1832 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1835 /* Remove the menu descriptor property from the frame window */
1836 RemovePropW( hwndFrame
, prop_olemenuW
);
1842 /******************************************************************************
1843 * IsAccelerator [OLE32.@]
1844 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1846 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1851 if(!lpMsg
) return FALSE
;
1854 WARN_(accel
)("NULL accel handle\n");
1857 if((lpMsg
->message
!= WM_KEYDOWN
&&
1858 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1859 lpMsg
->message
!= WM_SYSCHAR
&&
1860 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1861 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1862 if (NULL
== lpAccelTbl
)
1866 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1868 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1869 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1873 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1874 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1875 hAccel
, cAccelEntries
,
1876 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1877 for(i
= 0; i
< cAccelEntries
; i
++)
1879 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1882 if(lpMsg
->message
== WM_CHAR
)
1884 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1886 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1892 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1895 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1896 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1897 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1898 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1899 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1900 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1901 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1905 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1907 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1908 { /* ^^ ALT pressed */
1909 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
1917 WARN_(accel
)("couldn't translate accelerator key\n");
1918 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1922 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1923 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1927 /***********************************************************************
1928 * ReleaseStgMedium [OLE32.@]
1930 void WINAPI
ReleaseStgMedium(
1933 switch (pmedium
->tymed
)
1937 if ( (pmedium
->pUnkForRelease
==0) &&
1938 (pmedium
->u
.hGlobal
!=0) )
1939 GlobalFree(pmedium
->u
.hGlobal
);
1944 if (pmedium
->u
.lpszFileName
!=0)
1946 if (pmedium
->pUnkForRelease
==0)
1948 DeleteFileW(pmedium
->u
.lpszFileName
);
1951 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1957 if (pmedium
->u
.pstm
!=0)
1959 IStream_Release(pmedium
->u
.pstm
);
1963 case TYMED_ISTORAGE
:
1965 if (pmedium
->u
.pstg
!=0)
1967 IStorage_Release(pmedium
->u
.pstg
);
1973 if ( (pmedium
->pUnkForRelease
==0) &&
1974 (pmedium
->u
.hBitmap
!=0) )
1975 DeleteObject(pmedium
->u
.hBitmap
);
1980 if ( (pmedium
->pUnkForRelease
==0) &&
1981 (pmedium
->u
.hMetaFilePict
!=0) )
1983 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1984 DeleteMetaFile(pMP
->hMF
);
1985 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1986 GlobalFree(pmedium
->u
.hMetaFilePict
);
1992 if ( (pmedium
->pUnkForRelease
==0) &&
1993 (pmedium
->u
.hEnhMetaFile
!=0) )
1995 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
2003 pmedium
->tymed
=TYMED_NULL
;
2006 * After cleaning up, the unknown is released
2008 if (pmedium
->pUnkForRelease
!=0)
2010 IUnknown_Release(pmedium
->pUnkForRelease
);
2011 pmedium
->pUnkForRelease
= 0;
2016 * OLEDD_Initialize()
2018 * Initializes the OLE drag and drop data structures.
2020 static void OLEDD_Initialize(void)
2024 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2025 wndClass
.style
= CS_GLOBALCLASS
;
2026 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
2027 wndClass
.cbClsExtra
= 0;
2028 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
2029 wndClass
.hCursor
= 0;
2030 wndClass
.hbrBackground
= 0;
2031 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
2033 RegisterClassW (&wndClass
);
2037 * OLEDD_DragTrackerWindowProc()
2039 * This method is the WindowProcedure of the drag n drop tracking
2040 * window. During a drag n Drop operation, an invisible window is created
2041 * to receive the user input and act upon it. This procedure is in charge
2045 #define DRAG_TIMER_ID 1
2047 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2057 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2059 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
2060 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
2067 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
2073 case WM_LBUTTONDOWN
:
2074 case WM_MBUTTONDOWN
:
2075 case WM_RBUTTONDOWN
:
2077 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
2082 KillTimer(hwnd
, DRAG_TIMER_ID
);
2088 * This is a window proc after all. Let's call the default.
2090 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
2094 * OLEDD_TrackMouseMove()
2096 * This method is invoked while a drag and drop operation is in effect.
2097 * it will generate the appropriate callbacks in the drop source
2098 * and drop target. It will also provide the expected feedback to
2102 * trackerInfo - Pointer to the structure identifying the
2103 * drag & drop operation that is currently
2106 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2108 HWND hwndNewTarget
= 0;
2113 * Get the handle of the window under the mouse
2115 pt
.x
= trackerInfo
->curMousePos
.x
;
2116 pt
.y
= trackerInfo
->curMousePos
.y
;
2117 hwndNewTarget
= WindowFromPoint(pt
);
2120 * Every time, we re-initialize the effects passed to the
2121 * IDropTarget to the effects allowed by the source.
2123 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2126 * If we are hovering over the same target as before, send the
2127 * DragOver notification
2129 if ( (trackerInfo
->curDragTarget
!= 0) &&
2130 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2132 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2133 trackerInfo
->dwKeyState
,
2134 trackerInfo
->curMousePos
,
2135 trackerInfo
->pdwEffect
);
2140 * If we changed window, we have to notify our old target and check for
2143 if (trackerInfo
->curDragTarget
)
2144 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2147 * Make sure we're hovering over a window.
2152 * Find-out if there is a drag target under the mouse
2154 HWND next_target_wnd
= hwndNewTarget
;
2156 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2158 while (next_target_wnd
&& !is_droptarget(next_target_wnd
))
2159 next_target_wnd
= GetParent(next_target_wnd
);
2161 if (next_target_wnd
) hwndNewTarget
= next_target_wnd
;
2163 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2164 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2165 trackerInfo
->curDragTarget
= get_droptarget_pointer(hwndNewTarget
);
2168 * If there is, notify it that we just dragged-in
2170 if (trackerInfo
->curDragTarget
)
2172 hr
= IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2173 trackerInfo
->dataObject
,
2174 trackerInfo
->dwKeyState
,
2175 trackerInfo
->curMousePos
,
2176 trackerInfo
->pdwEffect
);
2178 /* failed DragEnter() means invalid target */
2181 trackerInfo
->curDragTargetHWND
= 0;
2182 trackerInfo
->curTargetHWND
= 0;
2183 IDropTarget_Release(trackerInfo
->curDragTarget
);
2184 trackerInfo
->curDragTarget
= 0;
2191 * The mouse is not over a window so we don't track anything.
2193 trackerInfo
->curDragTargetHWND
= 0;
2194 trackerInfo
->curTargetHWND
= 0;
2195 if(trackerInfo
->curDragTarget
) IDropTarget_Release(trackerInfo
->curDragTarget
);
2196 trackerInfo
->curDragTarget
= 0;
2201 * Now that we have done that, we have to tell the source to give
2202 * us feedback on the work being done by the target. If we don't
2203 * have a target, simulate no effect.
2205 if (trackerInfo
->curDragTarget
==0)
2207 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2210 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2211 *trackerInfo
->pdwEffect
);
2214 * When we ask for feedback from the drop source, sometimes it will
2215 * do all the necessary work and sometimes it will not handle it
2216 * when that's the case, we must display the standard drag and drop
2219 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2223 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2225 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(1));
2227 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2229 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(2));
2231 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2233 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(3));
2237 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(0));
2245 * OLEDD_TrackStateChange()
2247 * This method is invoked while a drag and drop operation is in effect.
2248 * It is used to notify the drop target/drop source callbacks when
2249 * the state of the keyboard or mouse button change.
2252 * trackerInfo - Pointer to the structure identifying the
2253 * drag & drop operation that is currently
2256 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2259 * Ask the drop source what to do with the operation.
2261 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2262 trackerInfo
->dropSource
,
2263 trackerInfo
->escPressed
,
2264 trackerInfo
->dwKeyState
);
2267 * All the return valued will stop the operation except the S_OK
2270 if (trackerInfo
->returnValue
!=S_OK
)
2273 * Make sure the message loop in DoDragDrop stops
2275 trackerInfo
->trackingDone
= TRUE
;
2278 * Release the mouse in case the drop target decides to show a popup
2279 * or a menu or something.
2284 * If we end-up over a target, drop the object in the target or
2285 * inform the target that the operation was cancelled.
2287 if (trackerInfo
->curDragTarget
)
2289 switch (trackerInfo
->returnValue
)
2292 * If the source wants us to complete the operation, we tell
2293 * the drop target that we just dropped the object in it.
2295 case DRAGDROP_S_DROP
:
2296 if (*trackerInfo
->pdwEffect
!= DROPEFFECT_NONE
)
2297 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2298 trackerInfo
->dataObject
,
2299 trackerInfo
->dwKeyState
,
2300 trackerInfo
->curMousePos
,
2301 trackerInfo
->pdwEffect
);
2303 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2307 * If the source told us that we should cancel, fool the drop
2308 * target by telling it that the mouse left it's window.
2309 * Also set the drop effect to "NONE" in case the application
2310 * ignores the result of DoDragDrop.
2312 case DRAGDROP_S_CANCEL
:
2313 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2314 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2322 * OLEDD_GetButtonState()
2324 * This method will use the current state of the keyboard to build
2325 * a button state mask equivalent to the one passed in the
2326 * WM_MOUSEMOVE wParam.
2328 static DWORD
OLEDD_GetButtonState(void)
2330 BYTE keyboardState
[256];
2333 GetKeyboardState(keyboardState
);
2335 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2336 keyMask
|= MK_SHIFT
;
2338 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2339 keyMask
|= MK_CONTROL
;
2341 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2342 keyMask
|= MK_LBUTTON
;
2344 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2345 keyMask
|= MK_RBUTTON
;
2347 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2348 keyMask
|= MK_MBUTTON
;
2354 * OLEDD_GetButtonState()
2356 * This method will read the default value of the registry key in
2357 * parameter and extract a DWORD value from it. The registry key value
2358 * can be in a string key or a DWORD key.
2361 * regKey - Key to read the default value from
2362 * pdwValue - Pointer to the location where the DWORD
2363 * value is returned. This value is not modified
2364 * if the value is not found.
2367 static void OLEUTL_ReadRegistryDWORDValue(
2372 DWORD cbData
= sizeof(buffer
);
2376 lres
= RegQueryValueExW(regKey
,
2383 if (lres
==ERROR_SUCCESS
)
2388 *pdwValue
= *(DWORD
*)buffer
;
2393 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2399 /******************************************************************************
2402 * The operation of this function is documented literally in the WinAPI
2403 * documentation to involve a QueryInterface for the IViewObject interface,
2404 * followed by a call to IViewObject::Draw.
2406 HRESULT WINAPI
OleDraw(
2413 IViewObject
*viewobject
;
2415 hres
= IUnknown_QueryInterface(pUnk
,
2417 (void**)&viewobject
);
2419 if (SUCCEEDED(hres
))
2423 rectl
.left
= lprcBounds
->left
;
2424 rectl
.right
= lprcBounds
->right
;
2425 rectl
.top
= lprcBounds
->top
;
2426 rectl
.bottom
= lprcBounds
->bottom
;
2427 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2429 IViewObject_Release(viewobject
);
2434 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 hres
= 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 IRunnableObject
*pRunnable
;
2515 IOleCache
*pOleCache
;
2518 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2519 if (SUCCEEDED(hres2
))
2521 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2522 IRunnableObject_Release(pRunnable
);
2525 if (SUCCEEDED(hres
))
2527 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2528 if (SUCCEEDED(hres2
))
2531 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2532 IOleCache_Release(pOleCache
);
2537 if (FAILED(hres
) && pUnk
)
2539 IUnknown_Release(pUnk
);
2545 TRACE("-- %p\n", pUnk
);
2549 /******************************************************************************
2550 * OleGetAutoConvert [OLE32.@]
2552 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2554 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2556 WCHAR buf
[CHARS_IN_GUID
];
2560 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, 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
)
2581 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2583 WCHAR szClsidNew
[CHARS_IN_GUID
];
2586 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2588 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2591 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2592 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2594 res
= REGDB_E_WRITEREGDB
;
2599 if (hkey
) RegCloseKey(hkey
);
2603 /******************************************************************************
2604 * OleDoAutoConvert [OLE32.@]
2606 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2608 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2612 /******************************************************************************
2613 * OleIsRunning [OLE32.@]
2615 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2617 IRunnableObject
*pRunnable
;
2621 TRACE("(%p)\n", pObject
);
2623 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2626 running
= IRunnableObject_IsRunning(pRunnable
);
2627 IRunnableObject_Release(pRunnable
);
2631 /***********************************************************************
2632 * OleNoteObjectVisible [OLE32.@]
2634 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2636 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2637 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2641 /***********************************************************************
2642 * OLE_FreeClipDataArray [internal]
2645 * frees the data associated with an array of CLIPDATAs
2647 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2650 for (i
= 0; i
< count
; i
++)
2651 if (pClipDataArray
[i
].pClipData
)
2652 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2655 /***********************************************************************
2656 * PropSysAllocString [OLE32.@]
2658 * Basically a copy of SysAllocStringLen.
2660 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2664 WCHAR
* stringBuffer
;
2669 len
= lstrlenW(str
);
2671 * Find the length of the buffer passed-in, in bytes.
2673 bufferSize
= len
* sizeof (WCHAR
);
2676 * Allocate a new buffer to hold the string.
2677 * Don't forget to keep an empty spot at the beginning of the
2678 * buffer for the character count and an extra character at the
2681 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2682 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2685 * If the memory allocation failed, return a null pointer.
2691 * Copy the length of the string in the placeholder.
2693 *newBuffer
= bufferSize
;
2696 * Skip the byte count.
2700 memcpy(newBuffer
, str
, bufferSize
);
2703 * Make sure that there is a nul character at the end of the
2706 stringBuffer
= (WCHAR
*)newBuffer
;
2707 stringBuffer
[len
] = '\0';
2709 return stringBuffer
;
2712 /***********************************************************************
2713 * PropSysFreeString [OLE32.@]
2715 * Copy of SysFreeString.
2717 void WINAPI
PropSysFreeString(LPOLESTR str
)
2719 DWORD
* bufferPointer
;
2721 /* NULL is a valid parameter */
2725 * We have to be careful when we free a BSTR pointer, it points to
2726 * the beginning of the string but it skips the byte count contained
2727 * before the string.
2729 bufferPointer
= (DWORD
*)str
;
2734 * Free the memory from its "real" origin.
2736 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2739 /******************************************************************************
2740 * Check if a PROPVARIANT's type is valid.
2742 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2769 case VT_STREAMED_OBJECT
:
2770 case VT_STORED_OBJECT
:
2771 case VT_BLOB_OBJECT
:
2774 case VT_I2
|VT_VECTOR
:
2775 case VT_I4
|VT_VECTOR
:
2776 case VT_R4
|VT_VECTOR
:
2777 case VT_R8
|VT_VECTOR
:
2778 case VT_CY
|VT_VECTOR
:
2779 case VT_DATE
|VT_VECTOR
:
2780 case VT_BSTR
|VT_VECTOR
:
2781 case VT_ERROR
|VT_VECTOR
:
2782 case VT_BOOL
|VT_VECTOR
:
2783 case VT_VARIANT
|VT_VECTOR
:
2784 case VT_UI1
|VT_VECTOR
:
2785 case VT_UI2
|VT_VECTOR
:
2786 case VT_UI4
|VT_VECTOR
:
2787 case VT_I8
|VT_VECTOR
:
2788 case VT_UI8
|VT_VECTOR
:
2789 case VT_LPSTR
|VT_VECTOR
:
2790 case VT_LPWSTR
|VT_VECTOR
:
2791 case VT_FILETIME
|VT_VECTOR
:
2792 case VT_CF
|VT_VECTOR
:
2793 case VT_CLSID
|VT_VECTOR
:
2796 WARN("Bad type %d\n", vt
);
2797 return STG_E_INVALIDPARAMETER
;
2800 /***********************************************************************
2801 * PropVariantClear [OLE32.@]
2803 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2807 TRACE("(%p)\n", pvar
);
2812 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2837 case VT_STREAMED_OBJECT
:
2839 case VT_STORED_OBJECT
:
2840 if (pvar
->u
.pStream
)
2841 IUnknown_Release(pvar
->u
.pStream
);
2846 /* pick an arbitrary typed pointer - we don't care about the type
2847 * as we are just freeing it */
2848 CoTaskMemFree(pvar
->u
.puuid
);
2851 case VT_BLOB_OBJECT
:
2852 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2855 if (pvar
->u
.bstrVal
)
2856 PropSysFreeString(pvar
->u
.bstrVal
);
2859 if (pvar
->u
.pclipdata
)
2861 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2862 CoTaskMemFree(pvar
->u
.pclipdata
);
2866 if (pvar
->vt
& VT_VECTOR
)
2870 switch (pvar
->vt
& ~VT_VECTOR
)
2873 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2876 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2879 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2880 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2883 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2884 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2887 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2888 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2891 if (pvar
->vt
& ~VT_VECTOR
)
2893 /* pick an arbitrary VT_VECTOR structure - they all have the same
2895 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2899 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2902 ZeroMemory(pvar
, sizeof(*pvar
));
2907 /***********************************************************************
2908 * PropVariantCopy [OLE32.@]
2910 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2911 const PROPVARIANT
*pvarSrc
) /* [in] */
2916 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
2918 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2922 /* this will deal with most cases */
2923 *pvarDest
= *pvarSrc
;
2947 case VT_STREAMED_OBJECT
:
2949 case VT_STORED_OBJECT
:
2950 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2953 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2954 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
2957 len
= strlen(pvarSrc
->u
.pszVal
);
2958 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2959 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2962 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2963 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2964 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2967 case VT_BLOB_OBJECT
:
2968 if (pvarSrc
->u
.blob
.pBlobData
)
2970 len
= pvarSrc
->u
.blob
.cbSize
;
2971 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2972 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2976 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2979 if (pvarSrc
->u
.pclipdata
)
2981 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2982 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
2983 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
2984 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
2985 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2986 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2990 if (pvarSrc
->vt
& VT_VECTOR
)
2995 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2997 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2998 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2999 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
3000 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
3001 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
3002 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
3003 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
3004 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
3005 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
3006 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
3007 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
3008 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
3009 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
3010 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
3011 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
3012 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
3013 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
3014 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
3015 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
3016 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
3017 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
3020 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
3021 return E_INVALIDARG
;
3023 len
= pvarSrc
->u
.capropvar
.cElems
;
3024 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
3025 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
3027 for (i
= 0; i
< len
; i
++)
3028 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
3030 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
3032 FIXME("Copy clipformats\n");
3034 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
3036 for (i
= 0; i
< len
; i
++)
3037 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
3039 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
3042 for (i
= 0; i
< len
; i
++)
3044 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
3045 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3046 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3047 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3050 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
3053 for (i
= 0; i
< len
; i
++)
3055 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
3057 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
3058 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
3059 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
3063 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
3066 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
3072 /***********************************************************************
3073 * FreePropVariantArray [OLE32.@]
3075 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
3076 PROPVARIANT
*rgvars
) /* [in/out] */
3080 TRACE("(%u, %p)\n", cVariants
, rgvars
);
3083 return E_INVALIDARG
;
3085 for(i
= 0; i
< cVariants
; i
++)
3086 PropVariantClear(&rgvars
[i
]);
3091 /******************************************************************************
3092 * DllDebugObjectRPCHook (OLE32.@)
3093 * turns on and off internal debugging, pointer is only used on macintosh
3096 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)