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 tagDropTargetNode
63 IDropTarget
* dropTarget
;
67 typedef struct tagTrackerWindowInfo
69 IDataObject
* dataObject
;
70 IDropSource
* dropSource
;
77 HWND curTargetHWND
; /* window the mouse is hovering over */
78 HWND curDragTargetHWND
; /* might be a ancestor of curTargetHWND */
79 IDropTarget
* curDragTarget
;
80 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
81 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
84 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
86 HWND hwndFrame
; /* The containers frame window */
87 HWND hwndActiveObject
; /* The active objects window */
88 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
89 HMENU hmenuCombined
; /* The combined menu */
90 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
93 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
95 DWORD tid
; /* Thread Id */
96 HANDLE hHeap
; /* Heap this is allocated from */
97 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
98 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
99 struct tagOleMenuHookItem
*next
;
102 static OleMenuHookItem
*hook_list
;
105 * This is the lock count on the OLE library. It is controlled by the
106 * OLEInitialize/OLEUninitialize methods.
108 static LONG OLE_moduleLockCount
= 0;
111 * Name of our registered window class.
113 static const WCHAR OLEDD_DRAGTRACKERCLASS
[] =
114 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
117 * Name of menu descriptor property.
119 static const WCHAR prop_olemenuW
[] =
120 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
122 static const WCHAR clsidfmtW
[] =
123 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
124 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
125 '%','0','2','x','%','0','2','x','}','\\',0};
127 static const WCHAR emptyW
[] = { 0 };
130 * This is the head of the Drop target container.
132 static struct list targetListHead
= LIST_INIT(targetListHead
);
134 /******************************************************************************
135 * These are the prototypes of miscellaneous utility methods
137 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
139 /******************************************************************************
140 * These are the prototypes of the utility methods used to manage a shared menu
142 static void OLEMenu_Initialize(void);
143 static void OLEMenu_UnInitialize(void);
144 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
145 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
146 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
147 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
148 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
149 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
150 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
152 /******************************************************************************
153 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
155 extern void OLEClipbrd_UnInitialize(void);
156 extern void OLEClipbrd_Initialize(void);
158 /******************************************************************************
159 * These are the prototypes of the utility methods used for OLE Drag n Drop
161 static void OLEDD_Initialize(void);
162 static DropTargetNode
* OLEDD_FindDropTarget(
164 static void OLEDD_FreeDropTarget(DropTargetNode
*, BOOL
);
165 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
170 static void OLEDD_TrackMouseMove(
171 TrackerWindowInfo
* trackerInfo
);
172 static void OLEDD_TrackStateChange(
173 TrackerWindowInfo
* trackerInfo
);
174 static DWORD
OLEDD_GetButtonState(void);
177 /******************************************************************************
178 * OleBuildVersion [OLE32.@]
180 DWORD WINAPI
OleBuildVersion(void)
182 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
183 return (rmm
<<16)+rup
;
186 /***********************************************************************
187 * OleInitialize (OLE32.@)
189 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
193 TRACE("(%p)\n", reserved
);
196 * The first duty of the OleInitialize is to initialize the COM libraries.
198 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
201 * If the CoInitializeEx call failed, the OLE libraries can't be
207 if (!COM_CurrentInfo()->ole_inits
)
211 * Then, it has to initialize the OLE specific modules.
215 * Object linking and Embedding
216 * In-place activation
218 if (!COM_CurrentInfo()->ole_inits
++ &&
219 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
222 * Initialize the libraries.
224 TRACE("() - Initializing the OLE libraries\n");
229 OLEClipbrd_Initialize();
239 OLEMenu_Initialize();
245 /******************************************************************************
246 * OleUninitialize [OLE32.@]
248 void WINAPI
OleUninitialize(void)
253 * If we hit the bottom of the lock stack, free the libraries.
255 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
258 * Actually free the libraries.
260 TRACE("() - Freeing the last reference count\n");
265 OLEClipbrd_UnInitialize();
270 OLEMenu_UnInitialize();
274 * Then, uninitialize the COM libraries.
279 /******************************************************************************
280 * OleInitializeWOW [OLE32.@]
282 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
283 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
287 /***********************************************************************
288 * RegisterDragDrop (OLE32.@)
290 HRESULT WINAPI
RegisterDragDrop(
292 LPDROPTARGET pDropTarget
)
294 DropTargetNode
* dropTargetInfo
;
296 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
298 if (!COM_CurrentApt())
300 ERR("COM not initialized\n");
301 return E_OUTOFMEMORY
;
309 ERR("invalid hwnd %p\n", hwnd
);
310 return DRAGDROP_E_INVALIDHWND
;
314 * First, check if the window is already registered.
316 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
318 if (dropTargetInfo
!=NULL
)
319 return DRAGDROP_E_ALREADYREGISTERED
;
322 * If it's not there, we can add it. We first create a node for it.
324 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
326 if (dropTargetInfo
==NULL
)
327 return E_OUTOFMEMORY
;
329 dropTargetInfo
->hwndTarget
= hwnd
;
332 * Don't forget that this is an interface pointer, need to nail it down since
333 * we keep a copy of it.
335 IDropTarget_AddRef(pDropTarget
);
336 dropTargetInfo
->dropTarget
= pDropTarget
;
338 list_add_tail(&targetListHead
, &dropTargetInfo
->entry
);
343 /***********************************************************************
344 * RevokeDragDrop (OLE32.@)
346 HRESULT WINAPI
RevokeDragDrop(
349 DropTargetNode
* dropTargetInfo
;
351 TRACE("(%p)\n", hwnd
);
355 ERR("invalid hwnd %p\n", hwnd
);
356 return DRAGDROP_E_INVALIDHWND
;
360 * First, check if the window is already registered.
362 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
365 * If it ain't in there, it's an error.
367 if (dropTargetInfo
==NULL
)
368 return DRAGDROP_E_NOTREGISTERED
;
370 OLEDD_FreeDropTarget(dropTargetInfo
, TRUE
);
375 /***********************************************************************
376 * OleRegGetUserType (OLE32.@)
378 * This implementation of OleRegGetUserType ignores the dwFormOfType
379 * parameter and always returns the full name of the object. This is
380 * not too bad since this is the case for many objects because of the
381 * way they are registered.
383 HRESULT WINAPI
OleRegGetUserType(
386 LPOLESTR
* pszUserType
)
395 * Initialize the out parameter.
400 * Build the key name we're looking for
402 sprintfW( keyName
, clsidfmtW
,
403 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
404 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
405 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
407 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwFormOfType
, pszUserType
);
410 * Open the class id Key
412 hres
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
416 if (hres
!= ERROR_SUCCESS
)
417 return REGDB_E_CLASSNOTREG
;
420 * Retrieve the size of the name string.
424 hres
= RegQueryValueExW(clsidKey
,
431 if (hres
!=ERROR_SUCCESS
)
433 RegCloseKey(clsidKey
);
434 return REGDB_E_READREGDB
;
438 * Allocate a buffer for the registry value.
440 *pszUserType
= CoTaskMemAlloc(cbData
);
442 if (*pszUserType
==NULL
)
444 RegCloseKey(clsidKey
);
445 return E_OUTOFMEMORY
;
448 hres
= RegQueryValueExW(clsidKey
,
452 (LPBYTE
) *pszUserType
,
455 RegCloseKey(clsidKey
);
457 if (hres
!= ERROR_SUCCESS
)
459 CoTaskMemFree(*pszUserType
);
462 return REGDB_E_READREGDB
;
468 /***********************************************************************
469 * DoDragDrop [OLE32.@]
471 HRESULT WINAPI
DoDragDrop (
472 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
473 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
474 DWORD dwOKEffect
, /* [in] effects allowed by the source */
475 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
477 static const WCHAR trackerW
[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
478 TrackerWindowInfo trackerInfo
;
479 HWND hwndTrackWindow
;
482 TRACE("(%p, %p, %d, %p)\n", pDataObject
, pDropSource
, dwOKEffect
, pdwEffect
);
484 if (!pDataObject
|| !pDropSource
|| !pdwEffect
)
488 * Setup the drag n drop tracking window.
491 trackerInfo
.dataObject
= pDataObject
;
492 trackerInfo
.dropSource
= pDropSource
;
493 trackerInfo
.dwOKEffect
= dwOKEffect
;
494 trackerInfo
.pdwEffect
= pdwEffect
;
495 trackerInfo
.trackingDone
= FALSE
;
496 trackerInfo
.escPressed
= FALSE
;
497 trackerInfo
.curDragTargetHWND
= 0;
498 trackerInfo
.curTargetHWND
= 0;
499 trackerInfo
.curDragTarget
= 0;
501 hwndTrackWindow
= CreateWindowW(OLEDD_DRAGTRACKERCLASS
, trackerW
,
502 WS_POPUP
, CW_USEDEFAULT
, CW_USEDEFAULT
,
503 CW_USEDEFAULT
, CW_USEDEFAULT
, 0, 0, 0,
509 * Capture the mouse input
511 SetCapture(hwndTrackWindow
);
516 * Pump messages. All mouse input should go to the capture window.
518 while (!trackerInfo
.trackingDone
&& GetMessageW(&msg
, 0, 0, 0) )
520 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
521 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
522 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
524 if ( (msg
.message
>= WM_KEYFIRST
) &&
525 (msg
.message
<= WM_KEYLAST
) )
528 * When keyboard messages are sent to windows on this thread, we
529 * want to ignore notify the drop source that the state changed.
530 * in the case of the Escape key, we also notify the drop source
531 * we give it a special meaning.
533 if ( (msg
.message
==WM_KEYDOWN
) &&
534 (msg
.wParam
==VK_ESCAPE
) )
536 trackerInfo
.escPressed
= TRUE
;
540 * Notify the drop source.
542 OLEDD_TrackStateChange(&trackerInfo
);
547 * Dispatch the messages only when it's not a keyboard message.
549 DispatchMessageW(&msg
);
553 /* re-post the quit message to outer message loop */
554 if (msg
.message
== WM_QUIT
)
555 PostQuitMessage(msg
.wParam
);
557 * Destroy the temporary window.
559 DestroyWindow(hwndTrackWindow
);
561 return trackerInfo
.returnValue
;
567 /***********************************************************************
568 * OleQueryLinkFromData [OLE32.@]
570 HRESULT WINAPI
OleQueryLinkFromData(
571 IDataObject
* pSrcDataObject
)
573 FIXME("(%p),stub!\n", pSrcDataObject
);
577 /***********************************************************************
578 * OleRegGetMiscStatus [OLE32.@]
580 HRESULT WINAPI
OleRegGetMiscStatus(
585 static const WCHAR miscstatusW
[] = {'M','i','s','c','S','t','a','t','u','s',0};
586 static const WCHAR dfmtW
[] = {'%','d',0};
594 * Initialize the out parameter.
599 * Build the key name we're looking for
601 sprintfW( keyName
, clsidfmtW
,
602 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
603 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
604 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
606 TRACE("(%s, %d, %p)\n", debugstr_w(keyName
), dwAspect
, pdwStatus
);
609 * Open the class id Key
611 result
= RegOpenKeyW(HKEY_CLASSES_ROOT
,
615 if (result
!= ERROR_SUCCESS
)
616 return REGDB_E_CLASSNOTREG
;
621 result
= RegOpenKeyW(clsidKey
,
626 if (result
!= ERROR_SUCCESS
)
628 RegCloseKey(clsidKey
);
629 return REGDB_E_READREGDB
;
633 * Read the default value
635 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
638 * Open the key specific to the requested aspect.
640 sprintfW(keyName
, dfmtW
, dwAspect
);
642 result
= RegOpenKeyW(miscStatusKey
,
646 if (result
== ERROR_SUCCESS
)
648 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
649 RegCloseKey(aspectKey
);
655 RegCloseKey(miscStatusKey
);
656 RegCloseKey(clsidKey
);
661 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
665 const IEnumOLEVERBVtbl
*lpvtbl
;
672 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
673 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
675 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
676 if (IsEqualIID(riid
, &IID_IUnknown
) ||
677 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
679 IUnknown_AddRef(iface
);
683 return E_NOINTERFACE
;
686 static ULONG WINAPI
EnumOLEVERB_AddRef(
689 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
691 return InterlockedIncrement(&This
->ref
);
694 static ULONG WINAPI
EnumOLEVERB_Release(
697 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
698 LONG refs
= InterlockedDecrement(&This
->ref
);
702 RegCloseKey(This
->hkeyVerb
);
703 HeapFree(GetProcessHeap(), 0, This
);
708 static HRESULT WINAPI
EnumOLEVERB_Next(
709 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
712 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
715 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
720 for (; celt
; celt
--, rgelt
++)
725 LPWSTR pwszMenuFlags
;
727 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
728 if (res
== ERROR_NO_MORE_ITEMS
)
733 else if (res
!= ERROR_SUCCESS
)
735 ERR("RegEnumKeyW failed with error %d\n", res
);
736 hr
= REGDB_E_READREGDB
;
739 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
740 if (res
!= ERROR_SUCCESS
)
742 ERR("RegQueryValueW failed with error %d\n", res
);
743 hr
= REGDB_E_READREGDB
;
746 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
752 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
753 if (res
!= ERROR_SUCCESS
)
755 ERR("RegQueryValueW failed with error %d\n", res
);
756 hr
= REGDB_E_READREGDB
;
757 CoTaskMemFree(pwszOLEVERB
);
761 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
762 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
765 hr
= OLEOBJ_E_INVALIDVERB
;
766 CoTaskMemFree(pwszOLEVERB
);
769 /* nul terminate the name string and advance to first character */
770 *pwszMenuFlags
= '\0';
772 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
775 hr
= OLEOBJ_E_INVALIDVERB
;
776 CoTaskMemFree(pwszOLEVERB
);
779 /* nul terminate the menu string and advance to first character */
783 /* fill out structure for this verb */
784 rgelt
->lVerb
= atolW(wszSubKey
);
785 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
786 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
787 rgelt
->grfAttribs
= atolW(pwszAttribs
);
796 static HRESULT WINAPI
EnumOLEVERB_Skip(
797 IEnumOLEVERB
*iface
, ULONG celt
)
799 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
801 TRACE("(%d)\n", celt
);
807 static HRESULT WINAPI
EnumOLEVERB_Reset(
810 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
818 static HRESULT WINAPI
EnumOLEVERB_Clone(
820 IEnumOLEVERB
**ppenum
)
822 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
824 TRACE("(%p)\n", ppenum
);
825 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
826 return HRESULT_FROM_WIN32(GetLastError());
827 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
830 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
832 EnumOLEVERB_QueryInterface
,
841 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
843 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
846 RegCloseKey(hkeyVerb
);
847 return E_OUTOFMEMORY
;
849 This
->lpvtbl
= &EnumOLEVERB_VTable
;
852 This
->hkeyVerb
= hkeyVerb
;
853 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
857 /***********************************************************************
858 * OleRegEnumVerbs [OLE32.@]
860 * Enumerates verbs associated with a class stored in the registry.
863 * clsid [I] Class ID to enumerate the verbs for.
864 * ppenum [O] Enumerator.
868 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
869 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
870 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
871 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
873 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
878 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
880 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
882 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
885 if (res
== REGDB_E_CLASSNOTREG
)
886 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
887 else if (res
== REGDB_E_KEYMISSING
)
888 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
890 ERR("failed to open Verbs key for CLSID %s with error %d\n",
891 debugstr_guid(clsid
), res
);
895 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
896 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
897 if (res
!= ERROR_SUCCESS
)
899 ERR("failed to get subkey count with error %d\n", GetLastError());
900 return REGDB_E_READREGDB
;
905 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
906 RegCloseKey(hkeyVerb
);
907 return OLEOBJ_E_NOVERBS
;
910 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
913 /******************************************************************************
914 * OleSetContainedObject [OLE32.@]
916 HRESULT WINAPI
OleSetContainedObject(
920 IRunnableObject
* runnable
= NULL
;
923 TRACE("(%p,%x)\n", pUnknown
, fContained
);
925 hres
= IUnknown_QueryInterface(pUnknown
,
926 &IID_IRunnableObject
,
931 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
933 IRunnableObject_Release(runnable
);
941 /******************************************************************************
944 * Set the OLE object to the running state.
947 * pUnknown [I] OLE object to run.
951 * Failure: Any HRESULT code.
953 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
955 IRunnableObject
*runable
;
958 TRACE("(%p)\n", pUnknown
);
960 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
962 return S_OK
; /* Appears to return no error. */
964 hres
= IRunnableObject_Run(runable
, NULL
);
965 IRunnableObject_Release(runable
);
969 /******************************************************************************
972 HRESULT WINAPI
OleLoad(
975 LPOLECLIENTSITE pClientSite
,
978 IPersistStorage
* persistStorage
= NULL
;
980 IOleObject
* pOleObject
= NULL
;
984 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
989 * TODO, Conversion ... OleDoAutoConvert
993 * Get the class ID for the object.
995 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
998 * Now, try and create the handler for the object
1000 hres
= CoCreateInstance(&storageInfo
.clsid
,
1002 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1007 * If that fails, as it will most times, load the default
1012 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1019 * If we couldn't find a handler... this is bad. Abort the whole thing.
1026 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1027 if (SUCCEEDED(hres
))
1030 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1034 if (SUCCEEDED(hres
))
1036 * Initialize the object with it's IPersistStorage interface.
1038 hres
= IOleObject_QueryInterface(pUnk
,
1039 &IID_IPersistStorage
,
1040 (void**)&persistStorage
);
1042 if (SUCCEEDED(hres
))
1044 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1046 IPersistStorage_Release(persistStorage
);
1047 persistStorage
= NULL
;
1050 if (SUCCEEDED(hres
) && pClientSite
)
1052 * Inform the new object of it's client site.
1054 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1057 * Cleanup interfaces used internally
1060 IOleObject_Release(pOleObject
);
1062 if (SUCCEEDED(hres
))
1066 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1067 if (SUCCEEDED(hres1
))
1069 FIXME("handle OLE link\n");
1070 IOleLink_Release(pOleLink
);
1076 IUnknown_Release(pUnk
);
1085 /***********************************************************************
1088 HRESULT WINAPI
OleSave(
1089 LPPERSISTSTORAGE pPS
,
1096 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1099 * First, we transfer the class ID (if available)
1101 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1103 if (SUCCEEDED(hres
))
1105 WriteClassStg(pStg
, &objectClass
);
1109 * Then, we ask the object to save itself to the
1110 * storage. If it is successful, we commit the storage.
1112 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1114 if (SUCCEEDED(hres
))
1116 IStorage_Commit(pStg
,
1124 /******************************************************************************
1125 * OleLockRunning [OLE32.@]
1127 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1129 IRunnableObject
* runnable
= NULL
;
1132 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1134 hres
= IUnknown_QueryInterface(pUnknown
,
1135 &IID_IRunnableObject
,
1138 if (SUCCEEDED(hres
))
1140 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1142 IRunnableObject_Release(runnable
);
1151 /**************************************************************************
1152 * Internal methods to manage the shared OLE menu in response to the
1153 * OLE***MenuDescriptor API
1157 * OLEMenu_Initialize()
1159 * Initializes the OLEMENU data structures.
1161 static void OLEMenu_Initialize(void)
1166 * OLEMenu_UnInitialize()
1168 * Releases the OLEMENU data structures.
1170 static void OLEMenu_UnInitialize(void)
1174 /*************************************************************************
1175 * OLEMenu_InstallHooks
1176 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1178 * RETURNS: TRUE if message hooks were successfully installed
1181 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1183 OleMenuHookItem
*pHookItem
;
1185 /* Create an entry for the hook table */
1186 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1187 sizeof(OleMenuHookItem
)) ) )
1190 pHookItem
->tid
= tid
;
1191 pHookItem
->hHeap
= GetProcessHeap();
1192 pHookItem
->CallWndProc_hHook
= NULL
;
1194 /* Install a thread scope message hook for WH_GETMESSAGE */
1195 pHookItem
->GetMsg_hHook
= SetWindowsHookExW( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1196 0, GetCurrentThreadId() );
1197 if ( !pHookItem
->GetMsg_hHook
)
1200 /* Install a thread scope message hook for WH_CALLWNDPROC */
1201 pHookItem
->CallWndProc_hHook
= SetWindowsHookExW( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1202 0, GetCurrentThreadId() );
1203 if ( !pHookItem
->CallWndProc_hHook
)
1206 /* Insert the hook table entry */
1207 pHookItem
->next
= hook_list
;
1208 hook_list
= pHookItem
;
1213 /* Unhook any hooks */
1214 if ( pHookItem
->GetMsg_hHook
)
1215 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1216 if ( pHookItem
->CallWndProc_hHook
)
1217 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1218 /* Release the hook table entry */
1219 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1224 /*************************************************************************
1225 * OLEMenu_UnInstallHooks
1226 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1228 * RETURNS: TRUE if message hooks were successfully installed
1231 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1233 OleMenuHookItem
*pHookItem
= NULL
;
1234 OleMenuHookItem
**ppHook
= &hook_list
;
1238 if ((*ppHook
)->tid
== tid
)
1240 pHookItem
= *ppHook
;
1241 *ppHook
= pHookItem
->next
;
1244 ppHook
= &(*ppHook
)->next
;
1246 if (!pHookItem
) return FALSE
;
1248 /* Uninstall the hooks installed for this thread */
1249 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1251 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1254 /* Release the hook table entry */
1255 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1260 /* Release the hook table entry */
1261 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1266 /*************************************************************************
1267 * OLEMenu_IsHookInstalled
1268 * Tests if OLEMenu hooks have been installed for a thread
1270 * RETURNS: The pointer and index of the hook table entry for the tid
1271 * NULL and -1 for the index if no hooks were installed for this thread
1273 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1275 OleMenuHookItem
*pHookItem
;
1277 /* Do a simple linear search for an entry whose tid matches ours.
1278 * We really need a map but efficiency is not a concern here. */
1279 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1281 if ( tid
== pHookItem
->tid
)
1288 /***********************************************************************
1289 * OLEMenu_FindMainMenuIndex
1291 * Used by OLEMenu API to find the top level group a menu item belongs to.
1292 * On success pnPos contains the index of the item in the top level menu group
1294 * RETURNS: TRUE if the ID was found, FALSE on failure
1296 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1300 nItems
= GetMenuItemCount( hMainMenu
);
1302 for (i
= 0; i
< nItems
; i
++)
1306 /* Is the current item a submenu? */
1307 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1309 /* If the handle is the same we're done */
1310 if ( hsubmenu
== hPopupMenu
)
1316 /* Recursively search without updating pnPos */
1317 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1329 /***********************************************************************
1330 * OLEMenu_SetIsServerMenu
1332 * Checks whether a popup menu belongs to a shared menu group which is
1333 * owned by the server, and sets the menu descriptor state accordingly.
1334 * All menu messages from these groups should be routed to the server.
1336 * RETURNS: TRUE if the popup menu is part of a server owned group
1337 * FALSE if the popup menu is part of a container owned group
1339 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1341 UINT nPos
= 0, nWidth
, i
;
1343 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1345 /* Don't bother searching if the popup is the combined menu itself */
1346 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1349 /* Find the menu item index in the shared OLE menu that this item belongs to */
1350 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1353 /* The group widths array has counts for the number of elements
1354 * in the groups File, Edit, Container, Object, Window, Help.
1355 * The Edit, Object & Help groups belong to the server object
1356 * and the other three belong to the container.
1357 * Loop through the group widths and locate the group we are a member of.
1359 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1361 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1362 if ( nPos
< nWidth
)
1364 /* Odd elements are server menu widths */
1365 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1370 return pOleMenuDescriptor
->bIsServerItem
;
1373 /*************************************************************************
1374 * OLEMenu_CallWndProc
1375 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1376 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1378 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1381 HOLEMENU hOleMenu
= 0;
1382 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1383 OleMenuHookItem
*pHookItem
= NULL
;
1386 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1388 /* Check if we're being asked to process the message */
1389 if ( HC_ACTION
!= code
)
1392 /* Retrieve the current message being dispatched from lParam */
1393 pMsg
= (LPCWPSTRUCT
)lParam
;
1395 /* Check if the message is destined for a window we are interested in:
1396 * If the window has an OLEMenu property we may need to dispatch
1397 * the menu message to its active objects window instead. */
1399 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1403 /* Get the menu descriptor */
1404 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1405 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1408 /* Process menu messages */
1409 switch( pMsg
->message
)
1413 /* Reset the menu descriptor state */
1414 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1416 /* Send this message to the server as well */
1417 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1418 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1422 case WM_INITMENUPOPUP
:
1424 /* Save the state for whether this is a server owned menu */
1425 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1431 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1432 if ( fuFlags
& MF_SYSMENU
)
1435 /* Save the state for whether this is a server owned popup menu */
1436 else if ( fuFlags
& MF_POPUP
)
1437 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1444 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1445 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1446 goto NEXTHOOK
; /* Not a menu message */
1455 /* If the message was for the server dispatch it accordingly */
1456 if ( pOleMenuDescriptor
->bIsServerItem
)
1458 SendMessageW( pOleMenuDescriptor
->hwndActiveObject
,
1459 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1463 if ( pOleMenuDescriptor
)
1464 GlobalUnlock( hOleMenu
);
1466 /* Lookup the hook item for the current thread */
1467 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1469 /* This should never fail!! */
1470 WARN("could not retrieve hHook for current thread!\n" );
1474 /* Pass on the message to the next hooker */
1475 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1478 /*************************************************************************
1479 * OLEMenu_GetMsgProc
1480 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1481 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1483 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1486 HOLEMENU hOleMenu
= 0;
1487 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1488 OleMenuHookItem
*pHookItem
= NULL
;
1491 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1493 /* Check if we're being asked to process a messages */
1494 if ( HC_ACTION
!= code
)
1497 /* Retrieve the current message being dispatched from lParam */
1498 pMsg
= (LPMSG
)lParam
;
1500 /* Check if the message is destined for a window we are interested in:
1501 * If the window has an OLEMenu property we may need to dispatch
1502 * the menu message to its active objects window instead. */
1504 hOleMenu
= GetPropW( pMsg
->hwnd
, prop_olemenuW
);
1508 /* Process menu messages */
1509 switch( pMsg
->message
)
1513 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1515 goto NEXTHOOK
; /* Not a menu message */
1522 /* Get the menu descriptor */
1523 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1524 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1527 /* If the message was for the server dispatch it accordingly */
1528 if ( pOleMenuDescriptor
->bIsServerItem
)
1530 /* Change the hWnd in the message to the active objects hWnd.
1531 * The message loop which reads this message will automatically
1532 * dispatch it to the embedded objects window. */
1533 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1537 if ( pOleMenuDescriptor
)
1538 GlobalUnlock( hOleMenu
);
1540 /* Lookup the hook item for the current thread */
1541 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1543 /* This should never fail!! */
1544 WARN("could not retrieve hHook for current thread!\n" );
1548 /* Pass on the message to the next hooker */
1549 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1552 /***********************************************************************
1553 * OleCreateMenuDescriptor [OLE32.@]
1554 * Creates an OLE menu descriptor for OLE to use when dispatching
1555 * menu messages and commands.
1558 * hmenuCombined - Handle to the objects combined menu
1559 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1562 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1563 HMENU hmenuCombined
,
1564 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1567 OleMenuDescriptor
*pOleMenuDescriptor
;
1570 if ( !hmenuCombined
|| !lpMenuWidths
)
1573 /* Create an OLE menu descriptor */
1574 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1575 sizeof(OleMenuDescriptor
) ) ) )
1578 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1579 if ( !pOleMenuDescriptor
)
1582 /* Initialize menu group widths and hmenu */
1583 for ( i
= 0; i
< 6; i
++ )
1584 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1586 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1587 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1588 GlobalUnlock( hOleMenu
);
1593 /***********************************************************************
1594 * OleDestroyMenuDescriptor [OLE32.@]
1595 * Destroy the shared menu descriptor
1597 HRESULT WINAPI
OleDestroyMenuDescriptor(
1598 HOLEMENU hmenuDescriptor
)
1600 if ( hmenuDescriptor
)
1601 GlobalFree( hmenuDescriptor
);
1605 /***********************************************************************
1606 * OleSetMenuDescriptor [OLE32.@]
1607 * Installs or removes OLE dispatching code for the containers frame window.
1610 * hOleMenu Handle to composite menu descriptor
1611 * hwndFrame Handle to containers frame window
1612 * hwndActiveObject Handle to objects in-place activation window
1613 * lpFrame Pointer to IOleInPlaceFrame on containers window
1614 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1617 * S_OK - menu installed correctly
1618 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1621 * The lpFrame and lpActiveObject parameters are currently ignored
1622 * OLE should install context sensitive help F1 filtering for the app when
1623 * these are non null.
1625 HRESULT WINAPI
OleSetMenuDescriptor(
1628 HWND hwndActiveObject
,
1629 LPOLEINPLACEFRAME lpFrame
,
1630 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1632 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1635 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1636 return E_INVALIDARG
;
1638 if ( lpFrame
|| lpActiveObject
)
1640 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1648 /* Set up a message hook to intercept the containers frame window messages.
1649 * The message filter is responsible for dispatching menu messages from the
1650 * shared menu which are intended for the object.
1653 if ( hOleMenu
) /* Want to install dispatching code */
1655 /* If OLEMenu hooks are already installed for this thread, fail
1656 * Note: This effectively means that OleSetMenuDescriptor cannot
1657 * be called twice in succession on the same frame window
1658 * without first calling it with a null hOleMenu to uninstall */
1659 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1662 /* Get the menu descriptor */
1663 pOleMenuDescriptor
= GlobalLock( hOleMenu
);
1664 if ( !pOleMenuDescriptor
)
1665 return E_UNEXPECTED
;
1667 /* Update the menu descriptor */
1668 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1669 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1671 GlobalUnlock( hOleMenu
);
1672 pOleMenuDescriptor
= NULL
;
1674 /* Add a menu descriptor windows property to the frame window */
1675 SetPropW( hwndFrame
, prop_olemenuW
, hOleMenu
);
1677 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1678 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1681 else /* Want to uninstall dispatching code */
1683 /* Uninstall the hooks */
1684 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1687 /* Remove the menu descriptor property from the frame window */
1688 RemovePropW( hwndFrame
, prop_olemenuW
);
1694 /******************************************************************************
1695 * IsAccelerator [OLE32.@]
1696 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1698 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1703 if(!lpMsg
) return FALSE
;
1706 WARN_(accel
)("NULL accel handle\n");
1709 if((lpMsg
->message
!= WM_KEYDOWN
&&
1710 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1711 lpMsg
->message
!= WM_SYSCHAR
&&
1712 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1713 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1714 if (NULL
== lpAccelTbl
)
1718 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1720 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1721 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1725 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1726 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1727 hAccel
, cAccelEntries
,
1728 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1729 for(i
= 0; i
< cAccelEntries
; i
++)
1731 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1734 if(lpMsg
->message
== WM_CHAR
)
1736 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1738 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1744 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1747 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1748 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1749 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1750 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1751 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1752 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1753 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1757 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1759 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1760 { /* ^^ ALT pressed */
1761 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
1769 WARN_(accel
)("couldn't translate accelerator key\n");
1770 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1774 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1775 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1779 /***********************************************************************
1780 * ReleaseStgMedium [OLE32.@]
1782 void WINAPI
ReleaseStgMedium(
1785 switch (pmedium
->tymed
)
1789 if ( (pmedium
->pUnkForRelease
==0) &&
1790 (pmedium
->u
.hGlobal
!=0) )
1791 GlobalFree(pmedium
->u
.hGlobal
);
1796 if (pmedium
->u
.lpszFileName
!=0)
1798 if (pmedium
->pUnkForRelease
==0)
1800 DeleteFileW(pmedium
->u
.lpszFileName
);
1803 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1809 if (pmedium
->u
.pstm
!=0)
1811 IStream_Release(pmedium
->u
.pstm
);
1815 case TYMED_ISTORAGE
:
1817 if (pmedium
->u
.pstg
!=0)
1819 IStorage_Release(pmedium
->u
.pstg
);
1825 if ( (pmedium
->pUnkForRelease
==0) &&
1826 (pmedium
->u
.hBitmap
!=0) )
1827 DeleteObject(pmedium
->u
.hBitmap
);
1832 if ( (pmedium
->pUnkForRelease
==0) &&
1833 (pmedium
->u
.hMetaFilePict
!=0) )
1835 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1836 DeleteMetaFile(pMP
->hMF
);
1837 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1838 GlobalFree(pmedium
->u
.hMetaFilePict
);
1844 if ( (pmedium
->pUnkForRelease
==0) &&
1845 (pmedium
->u
.hEnhMetaFile
!=0) )
1847 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1855 pmedium
->tymed
=TYMED_NULL
;
1858 * After cleaning up, the unknown is released
1860 if (pmedium
->pUnkForRelease
!=0)
1862 IUnknown_Release(pmedium
->pUnkForRelease
);
1863 pmedium
->pUnkForRelease
= 0;
1868 * OLEDD_Initialize()
1870 * Initializes the OLE drag and drop data structures.
1872 static void OLEDD_Initialize(void)
1876 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1877 wndClass
.style
= CS_GLOBALCLASS
;
1878 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1879 wndClass
.cbClsExtra
= 0;
1880 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1881 wndClass
.hCursor
= 0;
1882 wndClass
.hbrBackground
= 0;
1883 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1885 RegisterClassW (&wndClass
);
1889 * OLEDD_FreeDropTarget()
1891 * Frees the drag and drop data structure
1893 static void OLEDD_FreeDropTarget(DropTargetNode
*dropTargetInfo
, BOOL release_drop_target
)
1895 list_remove(&dropTargetInfo
->entry
);
1896 if (release_drop_target
) IDropTarget_Release(dropTargetInfo
->dropTarget
);
1897 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
1901 * OLEDD_UnInitialize()
1903 * Releases the OLE drag and drop data structures.
1905 void OLEDD_UnInitialize(void)
1908 * Simply empty the list.
1910 while (!list_empty(&targetListHead
))
1912 DropTargetNode
* curNode
= LIST_ENTRY(list_head(&targetListHead
), DropTargetNode
, entry
);
1913 OLEDD_FreeDropTarget(curNode
, FALSE
);
1918 * OLEDD_FindDropTarget()
1920 * Finds information about the drop target.
1922 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1924 DropTargetNode
* curNode
;
1927 * Iterate the list to find the HWND value.
1929 LIST_FOR_EACH_ENTRY(curNode
, &targetListHead
, DropTargetNode
, entry
)
1930 if (hwndOfTarget
==curNode
->hwndTarget
)
1934 * If we get here, the item is not in the list
1940 * OLEDD_DragTrackerWindowProc()
1942 * This method is the WindowProcedure of the drag n drop tracking
1943 * window. During a drag n Drop operation, an invisible window is created
1944 * to receive the user input and act upon it. This procedure is in charge
1948 #define DRAG_TIMER_ID 1
1950 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1960 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1962 SetWindowLongPtrW(hwnd
, 0, (LONG_PTR
)createStruct
->lpCreateParams
);
1963 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
1970 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
1976 case WM_LBUTTONDOWN
:
1977 case WM_MBUTTONDOWN
:
1978 case WM_RBUTTONDOWN
:
1980 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongPtrA(hwnd
, 0));
1985 KillTimer(hwnd
, DRAG_TIMER_ID
);
1991 * This is a window proc after all. Let's call the default.
1993 return DefWindowProcW (hwnd
, uMsg
, wParam
, lParam
);
1997 * OLEDD_TrackMouseMove()
1999 * This method is invoked while a drag and drop operation is in effect.
2000 * it will generate the appropriate callbacks in the drop source
2001 * and drop target. It will also provide the expected feedback to
2005 * trackerInfo - Pointer to the structure identifying the
2006 * drag & drop operation that is currently
2009 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2011 HWND hwndNewTarget
= 0;
2016 * Get the handle of the window under the mouse
2018 pt
.x
= trackerInfo
->curMousePos
.x
;
2019 pt
.y
= trackerInfo
->curMousePos
.y
;
2020 hwndNewTarget
= WindowFromPoint(pt
);
2023 * Every time, we re-initialize the effects passed to the
2024 * IDropTarget to the effects allowed by the source.
2026 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2029 * If we are hovering over the same target as before, send the
2030 * DragOver notification
2032 if ( (trackerInfo
->curDragTarget
!= 0) &&
2033 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2035 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2036 trackerInfo
->dwKeyState
,
2037 trackerInfo
->curMousePos
,
2038 trackerInfo
->pdwEffect
);
2042 DropTargetNode
* newDropTargetNode
= 0;
2045 * If we changed window, we have to notify our old target and check for
2048 if (trackerInfo
->curDragTarget
!=0)
2050 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2054 * Make sure we're hovering over a window.
2056 if (hwndNewTarget
!=0)
2059 * Find-out if there is a drag target under the mouse
2061 HWND nexttar
= hwndNewTarget
;
2062 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2065 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2066 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2067 if(nexttar
) hwndNewTarget
= nexttar
;
2069 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2070 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2073 * If there is, notify it that we just dragged-in
2075 if (trackerInfo
->curDragTarget
)
2077 hr
= IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2078 trackerInfo
->dataObject
,
2079 trackerInfo
->dwKeyState
,
2080 trackerInfo
->curMousePos
,
2081 trackerInfo
->pdwEffect
);
2083 /* failed DragEnter() means invalid target */
2086 trackerInfo
->curDragTargetHWND
= 0;
2087 trackerInfo
->curTargetHWND
= 0;
2088 trackerInfo
->curDragTarget
= 0;
2095 * The mouse is not over a window so we don't track anything.
2097 trackerInfo
->curDragTargetHWND
= 0;
2098 trackerInfo
->curTargetHWND
= 0;
2099 trackerInfo
->curDragTarget
= 0;
2104 * Now that we have done that, we have to tell the source to give
2105 * us feedback on the work being done by the target. If we don't
2106 * have a target, simulate no effect.
2108 if (trackerInfo
->curDragTarget
==0)
2110 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2113 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2114 *trackerInfo
->pdwEffect
);
2117 * When we ask for feedback from the drop source, sometimes it will
2118 * do all the necessary work and sometimes it will not handle it
2119 * when that's the case, we must display the standard drag and drop
2122 if (hr
== DRAGDROP_S_USEDEFAULTCURSORS
)
2126 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2128 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(1));
2130 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2132 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(2));
2134 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2136 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(3));
2140 hCur
= LoadCursorW(hProxyDll
, MAKEINTRESOURCEW(0));
2148 * OLEDD_TrackStateChange()
2150 * This method is invoked while a drag and drop operation is in effect.
2151 * It is used to notify the drop target/drop source callbacks when
2152 * the state of the keyboard or mouse button change.
2155 * trackerInfo - Pointer to the structure identifying the
2156 * drag & drop operation that is currently
2159 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2162 * Ask the drop source what to do with the operation.
2164 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2165 trackerInfo
->dropSource
,
2166 trackerInfo
->escPressed
,
2167 trackerInfo
->dwKeyState
);
2170 * All the return valued will stop the operation except the S_OK
2173 if (trackerInfo
->returnValue
!=S_OK
)
2176 * Make sure the message loop in DoDragDrop stops
2178 trackerInfo
->trackingDone
= TRUE
;
2181 * Release the mouse in case the drop target decides to show a popup
2182 * or a menu or something.
2187 * If we end-up over a target, drop the object in the target or
2188 * inform the target that the operation was cancelled.
2190 if (trackerInfo
->curDragTarget
)
2192 switch (trackerInfo
->returnValue
)
2195 * If the source wants us to complete the operation, we tell
2196 * the drop target that we just dropped the object in it.
2198 case DRAGDROP_S_DROP
:
2199 if (*trackerInfo
->pdwEffect
!= DROPEFFECT_NONE
)
2200 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2201 trackerInfo
->dataObject
,
2202 trackerInfo
->dwKeyState
,
2203 trackerInfo
->curMousePos
,
2204 trackerInfo
->pdwEffect
);
2206 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2210 * If the source told us that we should cancel, fool the drop
2211 * target by telling it that the mouse left it's window.
2212 * Also set the drop effect to "NONE" in case the application
2213 * ignores the result of DoDragDrop.
2215 case DRAGDROP_S_CANCEL
:
2216 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2217 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2225 * OLEDD_GetButtonState()
2227 * This method will use the current state of the keyboard to build
2228 * a button state mask equivalent to the one passed in the
2229 * WM_MOUSEMOVE wParam.
2231 static DWORD
OLEDD_GetButtonState(void)
2233 BYTE keyboardState
[256];
2236 GetKeyboardState(keyboardState
);
2238 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2239 keyMask
|= MK_SHIFT
;
2241 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2242 keyMask
|= MK_CONTROL
;
2244 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2245 keyMask
|= MK_LBUTTON
;
2247 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2248 keyMask
|= MK_RBUTTON
;
2250 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2251 keyMask
|= MK_MBUTTON
;
2257 * OLEDD_GetButtonState()
2259 * This method will read the default value of the registry key in
2260 * parameter and extract a DWORD value from it. The registry key value
2261 * can be in a string key or a DWORD key.
2264 * regKey - Key to read the default value from
2265 * pdwValue - Pointer to the location where the DWORD
2266 * value is returned. This value is not modified
2267 * if the value is not found.
2270 static void OLEUTL_ReadRegistryDWORDValue(
2275 DWORD cbData
= sizeof(buffer
);
2279 lres
= RegQueryValueExW(regKey
,
2286 if (lres
==ERROR_SUCCESS
)
2291 *pdwValue
= *(DWORD
*)buffer
;
2296 *pdwValue
= (DWORD
)strtoulW(buffer
, NULL
, 10);
2302 /******************************************************************************
2305 * The operation of this function is documented literally in the WinAPI
2306 * documentation to involve a QueryInterface for the IViewObject interface,
2307 * followed by a call to IViewObject::Draw.
2309 HRESULT WINAPI
OleDraw(
2316 IViewObject
*viewobject
;
2318 hres
= IUnknown_QueryInterface(pUnk
,
2320 (void**)&viewobject
);
2322 if (SUCCEEDED(hres
))
2326 rectl
.left
= lprcBounds
->left
;
2327 rectl
.right
= lprcBounds
->right
;
2328 rectl
.top
= lprcBounds
->top
;
2329 rectl
.bottom
= lprcBounds
->bottom
;
2330 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2332 IViewObject_Release(viewobject
);
2337 return DV_E_NOIVIEWOBJECT
;
2341 /***********************************************************************
2342 * OleTranslateAccelerator [OLE32.@]
2344 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2345 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2349 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2351 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2352 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2357 /******************************************************************************
2358 * OleCreate [OLE32.@]
2361 HRESULT WINAPI
OleCreate(
2365 LPFORMATETC pFormatEtc
,
2366 LPOLECLIENTSITE pClientSite
,
2371 IUnknown
* pUnk
= NULL
;
2372 IOleObject
*pOleObject
= NULL
;
2374 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2375 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2377 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2379 if (SUCCEEDED(hres
))
2380 hres
= IStorage_SetClass(pStg
, rclsid
);
2382 if (pClientSite
&& SUCCEEDED(hres
))
2384 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2385 if (SUCCEEDED(hres
))
2388 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2392 if (SUCCEEDED(hres
))
2394 IPersistStorage
* pPS
;
2395 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2397 TRACE("trying to set stg %p\n", pStg
);
2398 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2399 TRACE("-- result 0x%08x\n", hres
);
2400 IPersistStorage_Release(pPS
);
2404 if (pClientSite
&& SUCCEEDED(hres
))
2406 TRACE("trying to set clientsite %p\n", pClientSite
);
2407 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2408 TRACE("-- result 0x%08x\n", hres
);
2412 IOleObject_Release(pOleObject
);
2414 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2417 IRunnableObject
*pRunnable
;
2418 IOleCache
*pOleCache
;
2421 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2422 if (SUCCEEDED(hres2
))
2424 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2425 IRunnableObject_Release(pRunnable
);
2428 if (SUCCEEDED(hres
))
2430 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2431 if (SUCCEEDED(hres2
))
2434 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2435 IOleCache_Release(pOleCache
);
2440 if (FAILED(hres
) && pUnk
)
2442 IUnknown_Release(pUnk
);
2448 TRACE("-- %p\n", pUnk
);
2452 /******************************************************************************
2453 * OleGetAutoConvert [OLE32.@]
2455 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2457 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2459 WCHAR buf
[CHARS_IN_GUID
];
2463 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2468 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2470 res
= REGDB_E_KEYMISSING
;
2473 res
= CLSIDFromString(buf
, pClsidNew
);
2475 if (hkey
) RegCloseKey(hkey
);
2479 /******************************************************************************
2480 * OleSetAutoConvert [OLE32.@]
2482 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2484 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2486 WCHAR szClsidNew
[CHARS_IN_GUID
];
2489 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2491 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2494 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2495 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2497 res
= REGDB_E_WRITEREGDB
;
2502 if (hkey
) RegCloseKey(hkey
);
2506 /******************************************************************************
2507 * OleDoAutoConvert [OLE32.@]
2509 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2511 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2515 /******************************************************************************
2516 * OleIsRunning [OLE32.@]
2518 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2520 IRunnableObject
*pRunnable
;
2524 TRACE("(%p)\n", pObject
);
2526 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2529 running
= IRunnableObject_IsRunning(pRunnable
);
2530 IRunnableObject_Release(pRunnable
);
2534 /***********************************************************************
2535 * OleNoteObjectVisible [OLE32.@]
2537 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2539 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2540 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2544 /***********************************************************************
2545 * OLE_FreeClipDataArray [internal]
2548 * frees the data associated with an array of CLIPDATAs
2550 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2553 for (i
= 0; i
< count
; i
++)
2554 if (pClipDataArray
[i
].pClipData
)
2555 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2558 /***********************************************************************
2559 * PropSysAllocString [OLE32.@]
2561 * Basically a copy of SysAllocStringLen.
2563 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2567 WCHAR
* stringBuffer
;
2572 len
= lstrlenW(str
);
2574 * Find the length of the buffer passed-in, in bytes.
2576 bufferSize
= len
* sizeof (WCHAR
);
2579 * Allocate a new buffer to hold the string.
2580 * Don't forget to keep an empty spot at the beginning of the
2581 * buffer for the character count and an extra character at the
2584 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2585 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2588 * If the memory allocation failed, return a null pointer.
2594 * Copy the length of the string in the placeholder.
2596 *newBuffer
= bufferSize
;
2599 * Skip the byte count.
2603 memcpy(newBuffer
, str
, bufferSize
);
2606 * Make sure that there is a nul character at the end of the
2609 stringBuffer
= (WCHAR
*)newBuffer
;
2610 stringBuffer
[len
] = '\0';
2612 return stringBuffer
;
2615 /***********************************************************************
2616 * PropSysFreeString [OLE32.@]
2618 * Copy of SysFreeString.
2620 void WINAPI
PropSysFreeString(LPOLESTR str
)
2622 DWORD
* bufferPointer
;
2624 /* NULL is a valid parameter */
2628 * We have to be careful when we free a BSTR pointer, it points to
2629 * the beginning of the string but it skips the byte count contained
2630 * before the string.
2632 bufferPointer
= (DWORD
*)str
;
2637 * Free the memory from its "real" origin.
2639 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2642 /******************************************************************************
2643 * Check if a PROPVARIANT's type is valid.
2645 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2672 case VT_STREAMED_OBJECT
:
2673 case VT_STORED_OBJECT
:
2674 case VT_BLOB_OBJECT
:
2677 case VT_I2
|VT_VECTOR
:
2678 case VT_I4
|VT_VECTOR
:
2679 case VT_R4
|VT_VECTOR
:
2680 case VT_R8
|VT_VECTOR
:
2681 case VT_CY
|VT_VECTOR
:
2682 case VT_DATE
|VT_VECTOR
:
2683 case VT_BSTR
|VT_VECTOR
:
2684 case VT_ERROR
|VT_VECTOR
:
2685 case VT_BOOL
|VT_VECTOR
:
2686 case VT_VARIANT
|VT_VECTOR
:
2687 case VT_UI1
|VT_VECTOR
:
2688 case VT_UI2
|VT_VECTOR
:
2689 case VT_UI4
|VT_VECTOR
:
2690 case VT_I8
|VT_VECTOR
:
2691 case VT_UI8
|VT_VECTOR
:
2692 case VT_LPSTR
|VT_VECTOR
:
2693 case VT_LPWSTR
|VT_VECTOR
:
2694 case VT_FILETIME
|VT_VECTOR
:
2695 case VT_CF
|VT_VECTOR
:
2696 case VT_CLSID
|VT_VECTOR
:
2699 WARN("Bad type %d\n", vt
);
2700 return STG_E_INVALIDPARAMETER
;
2703 /***********************************************************************
2704 * PropVariantClear [OLE32.@]
2706 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2710 TRACE("(%p)\n", pvar
);
2715 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2740 case VT_STREAMED_OBJECT
:
2742 case VT_STORED_OBJECT
:
2743 if (pvar
->u
.pStream
)
2744 IUnknown_Release(pvar
->u
.pStream
);
2749 /* pick an arbitrary typed pointer - we don't care about the type
2750 * as we are just freeing it */
2751 CoTaskMemFree(pvar
->u
.puuid
);
2754 case VT_BLOB_OBJECT
:
2755 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2758 if (pvar
->u
.bstrVal
)
2759 PropSysFreeString(pvar
->u
.bstrVal
);
2762 if (pvar
->u
.pclipdata
)
2764 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2765 CoTaskMemFree(pvar
->u
.pclipdata
);
2769 if (pvar
->vt
& VT_VECTOR
)
2773 switch (pvar
->vt
& ~VT_VECTOR
)
2776 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2779 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2782 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2783 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2786 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2787 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2790 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2791 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2794 if (pvar
->vt
& ~VT_VECTOR
)
2796 /* pick an arbitrary VT_VECTOR structure - they all have the same
2798 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2802 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2805 ZeroMemory(pvar
, sizeof(*pvar
));
2810 /***********************************************************************
2811 * PropVariantCopy [OLE32.@]
2813 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2814 const PROPVARIANT
*pvarSrc
) /* [in] */
2819 TRACE("(%p, %p vt %04x)\n", pvarDest
, pvarSrc
, pvarSrc
->vt
);
2821 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2825 /* this will deal with most cases */
2826 *pvarDest
= *pvarSrc
;
2850 case VT_STREAMED_OBJECT
:
2852 case VT_STORED_OBJECT
:
2853 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2856 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2857 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
2860 len
= strlen(pvarSrc
->u
.pszVal
);
2861 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2862 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2865 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2866 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2867 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2870 case VT_BLOB_OBJECT
:
2871 if (pvarSrc
->u
.blob
.pBlobData
)
2873 len
= pvarSrc
->u
.blob
.cbSize
;
2874 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2875 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2879 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2882 if (pvarSrc
->u
.pclipdata
)
2884 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2885 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
2886 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
2887 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
2888 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2889 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2893 if (pvarSrc
->vt
& VT_VECTOR
)
2898 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2900 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2901 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2902 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
2903 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
2904 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
2905 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
2906 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
2907 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
2908 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
2909 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
2910 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
2911 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
2912 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
2913 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
2914 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
2915 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
2916 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
2917 case VT_BSTR
: elemSize
= sizeof(pvarSrc
->u
.bstrVal
); break;
2918 case VT_LPSTR
: elemSize
= sizeof(pvarSrc
->u
.pszVal
); break;
2919 case VT_LPWSTR
: elemSize
= sizeof(pvarSrc
->u
.pwszVal
); break;
2920 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
2923 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
2924 return E_INVALIDARG
;
2926 len
= pvarSrc
->u
.capropvar
.cElems
;
2927 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
2928 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
2930 for (i
= 0; i
< len
; i
++)
2931 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
2933 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
2935 FIXME("Copy clipformats\n");
2937 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
2939 for (i
= 0; i
< len
; i
++)
2940 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
2942 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
2945 for (i
= 0; i
< len
; i
++)
2947 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
2948 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2949 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2950 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2953 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
2956 for (i
= 0; i
< len
; i
++)
2958 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
2960 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2961 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2962 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2966 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
2969 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
2975 /***********************************************************************
2976 * FreePropVariantArray [OLE32.@]
2978 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
2979 PROPVARIANT
*rgvars
) /* [in/out] */
2983 TRACE("(%u, %p)\n", cVariants
, rgvars
);
2986 return E_INVALIDARG
;
2988 for(i
= 0; i
< cVariants
; i
++)
2989 PropVariantClear(&rgvars
[i
]);
2994 /******************************************************************************
2995 * DllDebugObjectRPCHook (OLE32.@)
2996 * turns on and off internal debugging, pointer is only used on macintosh
2999 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)