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 char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
116 * This is the head of the Drop target container.
118 static struct list targetListHead = LIST_INIT(targetListHead);
120 /******************************************************************************
121 * These are the prototypes of miscellaneous utility methods
123 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
125 /******************************************************************************
126 * These are the prototypes of the utility methods used to manage a shared menu
128 static void OLEMenu_Initialize(void);
129 static void OLEMenu_UnInitialize(void);
130 static BOOL OLEMenu_InstallHooks( DWORD tid );
131 static BOOL OLEMenu_UnInstallHooks( DWORD tid );
132 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
133 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
134 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
135 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
136 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
138 /******************************************************************************
139 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
141 extern void OLEClipbrd_UnInitialize(void);
142 extern void OLEClipbrd_Initialize(void);
144 /******************************************************************************
145 * These are the prototypes of the utility methods used for OLE Drag n Drop
147 static void OLEDD_Initialize(void);
148 static DropTargetNode* OLEDD_FindDropTarget(
150 static void OLEDD_FreeDropTarget(DropTargetNode*, BOOL);
151 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
156 static void OLEDD_TrackMouseMove(
157 TrackerWindowInfo* trackerInfo);
158 static void OLEDD_TrackStateChange(
159 TrackerWindowInfo* trackerInfo);
160 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
194 * Then, it has to initialize the OLE specific modules.
198 * Object linking and Embedding
199 * In-place activation
201 if (!COM_CurrentInfo()->ole_inits++ &&
202 InterlockedIncrement(&OLE_moduleLockCount) == 1)
205 * Initialize the libraries.
207 TRACE("() - Initializing the OLE libraries\n");
212 OLEClipbrd_Initialize();
222 OLEMenu_Initialize();
228 /******************************************************************************
229 * OleUninitialize [OLE32.@]
231 void WINAPI OleUninitialize(void)
236 * If we hit the bottom of the lock stack, free the libraries.
238 if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
241 * Actually free the libraries.
243 TRACE("() - Freeing the last reference count\n");
248 OLEClipbrd_UnInitialize();
253 OLEMenu_UnInitialize();
257 * Then, uninitialize the COM libraries.
262 /******************************************************************************
263 * OleInitializeWOW [OLE32.@]
265 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
266 FIXME("(0x%08x, 0x%08x),stub!\n",x, y);
270 /***********************************************************************
271 * RegisterDragDrop (OLE32.@)
273 HRESULT WINAPI RegisterDragDrop(
275 LPDROPTARGET pDropTarget)
277 DropTargetNode* dropTargetInfo;
279 TRACE("(%p,%p)\n", hwnd, pDropTarget);
281 if (!COM_CurrentApt())
283 ERR("COM not initialized\n");
284 return E_OUTOFMEMORY;
292 ERR("invalid hwnd %p\n", hwnd);
293 return DRAGDROP_E_INVALIDHWND;
297 * First, check if the window is already registered.
299 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
301 if (dropTargetInfo!=NULL)
302 return DRAGDROP_E_ALREADYREGISTERED;
305 * If it's not there, we can add it. We first create a node for it.
307 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
309 if (dropTargetInfo==NULL)
310 return E_OUTOFMEMORY;
312 dropTargetInfo->hwndTarget = hwnd;
315 * Don't forget that this is an interface pointer, need to nail it down since
316 * we keep a copy of it.
318 IDropTarget_AddRef(pDropTarget);
319 dropTargetInfo->dropTarget = pDropTarget;
321 list_add_tail(&targetListHead, &dropTargetInfo->entry);
326 /***********************************************************************
327 * RevokeDragDrop (OLE32.@)
329 HRESULT WINAPI RevokeDragDrop(
332 DropTargetNode* dropTargetInfo;
334 TRACE("(%p)\n", hwnd);
338 ERR("invalid hwnd %p\n", hwnd);
339 return DRAGDROP_E_INVALIDHWND;
343 * First, check if the window is already registered.
345 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
348 * If it ain't in there, it's an error.
350 if (dropTargetInfo==NULL)
351 return DRAGDROP_E_NOTREGISTERED;
353 OLEDD_FreeDropTarget(dropTargetInfo, TRUE);
358 /***********************************************************************
359 * OleRegGetUserType (OLE32.@)
361 * This implementation of OleRegGetUserType ignores the dwFormOfType
362 * parameter and always returns the full name of the object. This is
363 * not too bad since this is the case for many objects because of the
364 * way they are registered.
366 HRESULT WINAPI OleRegGetUserType(
369 LPOLESTR* pszUserType)
379 * Initialize the out parameter.
384 * Build the key name we're looking for
386 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
387 clsid->Data1, clsid->Data2, clsid->Data3,
388 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
389 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
391 TRACE("(%s, %d, %p)\n", keyName, dwFormOfType, pszUserType);
394 * Open the class id Key
396 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
400 if (hres != ERROR_SUCCESS)
401 return REGDB_E_CLASSNOTREG;
404 * Retrieve the size of the name string.
408 hres = RegQueryValueExA(clsidKey,
415 if (hres!=ERROR_SUCCESS)
417 RegCloseKey(clsidKey);
418 return REGDB_E_READREGDB;
422 * Allocate a buffer for the registry value.
424 *pszUserType = CoTaskMemAlloc(cbData*2);
426 if (*pszUserType==NULL)
428 RegCloseKey(clsidKey);
429 return E_OUTOFMEMORY;
432 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
436 RegCloseKey(clsidKey);
437 CoTaskMemFree(*pszUserType);
439 return E_OUTOFMEMORY;
442 hres = RegQueryValueExA(clsidKey,
449 RegCloseKey(clsidKey);
452 if (hres!=ERROR_SUCCESS)
454 CoTaskMemFree(*pszUserType);
457 retVal = REGDB_E_READREGDB;
461 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
464 HeapFree(GetProcessHeap(), 0, buffer);
469 /***********************************************************************
470 * DoDragDrop [OLE32.@]
472 HRESULT WINAPI DoDragDrop (
473 IDataObject *pDataObject, /* [in] ptr to the data obj */
474 IDropSource* pDropSource, /* [in] ptr to the source obj */
475 DWORD dwOKEffect, /* [in] effects allowed by the source */
476 DWORD *pdwEffect) /* [out] ptr to effects of the source */
478 TrackerWindowInfo trackerInfo;
479 HWND hwndTrackWindow;
482 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
485 * Setup the drag n drop tracking window.
487 if (!IsValidInterface((LPUNKNOWN)pDropSource))
490 trackerInfo.dataObject = pDataObject;
491 trackerInfo.dropSource = pDropSource;
492 trackerInfo.dwOKEffect = dwOKEffect;
493 trackerInfo.pdwEffect = pdwEffect;
494 trackerInfo.trackingDone = FALSE;
495 trackerInfo.escPressed = FALSE;
496 trackerInfo.curDragTargetHWND = 0;
497 trackerInfo.curTargetHWND = 0;
498 trackerInfo.curDragTarget = 0;
500 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS, "TrackerWindow",
501 WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
502 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
505 if (hwndTrackWindow!=0)
508 * Capture the mouse input
510 SetCapture(hwndTrackWindow);
515 * Pump messages. All mouse input should go to the capture window.
517 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
519 trackerInfo.curMousePos.x = msg.pt.x;
520 trackerInfo.curMousePos.y = msg.pt.y;
521 trackerInfo.dwKeyState = OLEDD_GetButtonState();
523 if ( (msg.message >= WM_KEYFIRST) &&
524 (msg.message <= WM_KEYLAST) )
527 * When keyboard messages are sent to windows on this thread, we
528 * want to ignore notify the drop source that the state changed.
529 * in the case of the Escape key, we also notify the drop source
530 * we give it a special meaning.
532 if ( (msg.message==WM_KEYDOWN) &&
533 (msg.wParam==VK_ESCAPE) )
535 trackerInfo.escPressed = TRUE;
539 * Notify the drop source.
541 OLEDD_TrackStateChange(&trackerInfo);
546 * Dispatch the messages only when it's not a keyboard message.
548 DispatchMessageA(&msg);
552 /* re-post the quit message to outer message loop */
553 if (msg.message == WM_QUIT)
554 PostQuitMessage(msg.wParam);
556 * Destroy the temporary window.
558 DestroyWindow(hwndTrackWindow);
560 return trackerInfo.returnValue;
566 /***********************************************************************
567 * OleQueryLinkFromData [OLE32.@]
569 HRESULT WINAPI OleQueryLinkFromData(
570 IDataObject* pSrcDataObject)
572 FIXME("(%p),stub!\n", pSrcDataObject);
576 /***********************************************************************
577 * OleRegGetMiscStatus [OLE32.@]
579 HRESULT WINAPI OleRegGetMiscStatus(
591 * Initialize the out parameter.
596 * Build the key name we're looking for
598 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
599 clsid->Data1, clsid->Data2, clsid->Data3,
600 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
601 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
603 TRACE("(%s, %d, %p)\n", keyName, dwAspect, pdwStatus);
606 * Open the class id Key
608 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
612 if (result != ERROR_SUCCESS)
613 return REGDB_E_CLASSNOTREG;
618 result = RegOpenKeyA(clsidKey,
623 if (result != ERROR_SUCCESS)
625 RegCloseKey(clsidKey);
626 return REGDB_E_READREGDB;
630 * Read the default value
632 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
635 * Open the key specific to the requested aspect.
637 sprintf(keyName, "%d", dwAspect);
639 result = RegOpenKeyA(miscStatusKey,
643 if (result == ERROR_SUCCESS)
645 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
646 RegCloseKey(aspectKey);
652 RegCloseKey(miscStatusKey);
653 RegCloseKey(clsidKey);
658 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
662 const IEnumOLEVERBVtbl *lpvtbl;
669 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
670 IEnumOLEVERB *iface, REFIID riid, void **ppv)
672 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
673 if (IsEqualIID(riid, &IID_IUnknown) ||
674 IsEqualIID(riid, &IID_IEnumOLEVERB))
676 IUnknown_AddRef(iface);
680 return E_NOINTERFACE;
683 static ULONG WINAPI EnumOLEVERB_AddRef(
686 EnumOLEVERB *This = (EnumOLEVERB *)iface;
688 return InterlockedIncrement(&This->ref);
691 static ULONG WINAPI EnumOLEVERB_Release(
694 EnumOLEVERB *This = (EnumOLEVERB *)iface;
695 LONG refs = InterlockedDecrement(&This->ref);
699 RegCloseKey(This->hkeyVerb);
700 HeapFree(GetProcessHeap(), 0, This);
705 static HRESULT WINAPI EnumOLEVERB_Next(
706 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
709 EnumOLEVERB *This = (EnumOLEVERB *)iface;
712 TRACE("(%d, %p, %p)\n", celt, rgelt, pceltFetched);
717 for (; celt; celt--, rgelt++)
722 LPWSTR pwszMenuFlags;
724 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
725 if (res == ERROR_NO_MORE_ITEMS)
730 else if (res != ERROR_SUCCESS)
732 ERR("RegEnumKeyW failed with error %d\n", res);
733 hr = REGDB_E_READREGDB;
736 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
737 if (res != ERROR_SUCCESS)
739 ERR("RegQueryValueW failed with error %d\n", res);
740 hr = REGDB_E_READREGDB;
743 pwszOLEVERB = CoTaskMemAlloc(cbData);
749 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
750 if (res != ERROR_SUCCESS)
752 ERR("RegQueryValueW failed with error %d\n", res);
753 hr = REGDB_E_READREGDB;
754 CoTaskMemFree(pwszOLEVERB);
758 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
759 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
762 hr = OLEOBJ_E_INVALIDVERB;
763 CoTaskMemFree(pwszOLEVERB);
766 /* nul terminate the name string and advance to first character */
767 *pwszMenuFlags = '\0';
769 pwszAttribs = strchrW(pwszMenuFlags, ',');
772 hr = OLEOBJ_E_INVALIDVERB;
773 CoTaskMemFree(pwszOLEVERB);
776 /* nul terminate the menu string and advance to first character */
780 /* fill out structure for this verb */
781 rgelt->lVerb = atolW(wszSubKey);
782 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
783 rgelt->fuFlags = atolW(pwszMenuFlags);
784 rgelt->grfAttribs = atolW(pwszAttribs);
793 static HRESULT WINAPI EnumOLEVERB_Skip(
794 IEnumOLEVERB *iface, ULONG celt)
796 EnumOLEVERB *This = (EnumOLEVERB *)iface;
798 TRACE("(%d)\n", celt);
804 static HRESULT WINAPI EnumOLEVERB_Reset(
807 EnumOLEVERB *This = (EnumOLEVERB *)iface;
815 static HRESULT WINAPI EnumOLEVERB_Clone(
817 IEnumOLEVERB **ppenum)
819 EnumOLEVERB *This = (EnumOLEVERB *)iface;
821 TRACE("(%p)\n", ppenum);
822 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
823 return HRESULT_FROM_WIN32(GetLastError());
824 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
827 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
829 EnumOLEVERB_QueryInterface,
838 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
840 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
843 RegCloseKey(hkeyVerb);
844 return E_OUTOFMEMORY;
846 This->lpvtbl = &EnumOLEVERB_VTable;
849 This->hkeyVerb = hkeyVerb;
850 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
854 /***********************************************************************
855 * OleRegEnumVerbs [OLE32.@]
857 * Enumerates verbs associated with a class stored in the registry.
860 * clsid [I] Class ID to enumerate the verbs for.
861 * ppenum [O] Enumerator.
865 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
866 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
867 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
868 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
870 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
875 static const WCHAR wszVerb[] = {'V','e','r','b',0};
877 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
879 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
882 if (res == REGDB_E_CLASSNOTREG)
883 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
884 else if (res == REGDB_E_KEYMISSING)
885 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
887 ERR("failed to open Verbs key for CLSID %s with error %d\n",
888 debugstr_guid(clsid), res);
892 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
893 NULL, NULL, NULL, NULL, NULL, NULL);
894 if (res != ERROR_SUCCESS)
896 ERR("failed to get subkey count with error %d\n", GetLastError());
897 return REGDB_E_READREGDB;
902 WARN("class %s has no verbs\n", debugstr_guid(clsid));
903 RegCloseKey(hkeyVerb);
904 return OLEOBJ_E_NOVERBS;
907 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
910 /******************************************************************************
911 * OleSetContainedObject [OLE32.@]
913 HRESULT WINAPI OleSetContainedObject(
917 IRunnableObject* runnable = NULL;
920 TRACE("(%p,%x)\n", pUnknown, fContained);
922 hres = IUnknown_QueryInterface(pUnknown,
923 &IID_IRunnableObject,
928 hres = IRunnableObject_SetContainedObject(runnable, fContained);
930 IRunnableObject_Release(runnable);
938 /******************************************************************************
941 * Set the OLE object to the running state.
944 * pUnknown [I] OLE object to run.
948 * Failure: Any HRESULT code.
950 HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
952 IRunnableObject *runable;
955 TRACE("(%p)\n", pUnknown);
957 hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
959 return S_OK; /* Appears to return no error. */
961 hres = IRunnableObject_Run(runable, NULL);
962 IRunnableObject_Release(runable);
966 /******************************************************************************
969 HRESULT WINAPI OleLoad(
972 LPOLECLIENTSITE pClientSite,
975 IPersistStorage* persistStorage = NULL;
977 IOleObject* pOleObject = NULL;
981 TRACE("(%p, %s, %p, %p)\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
986 * TODO, Conversion ... OleDoAutoConvert
990 * Get the class ID for the object.
992 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
995 * Now, try and create the handler for the object
997 hres = CoCreateInstance(&storageInfo.clsid,
999 CLSCTX_INPROC_HANDLER|CLSCTX_INPROC_SERVER,
1004 * If that fails, as it will most times, load the default
1009 hres = OleCreateDefaultHandler(&storageInfo.clsid,
1016 * If we couldn't find a handler... this is bad. Abort the whole thing.
1023 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1024 if (SUCCEEDED(hres))
1027 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1031 if (SUCCEEDED(hres))
1033 * Initialize the object with it's IPersistStorage interface.
1035 hres = IOleObject_QueryInterface(pUnk,
1036 &IID_IPersistStorage,
1037 (void**)&persistStorage);
1039 if (SUCCEEDED(hres))
1041 hres = IPersistStorage_Load(persistStorage, pStg);
1043 IPersistStorage_Release(persistStorage);
1044 persistStorage = NULL;
1047 if (SUCCEEDED(hres) && pClientSite)
1049 * Inform the new object of it's client site.
1051 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1054 * Cleanup interfaces used internally
1057 IOleObject_Release(pOleObject);
1059 if (SUCCEEDED(hres))
1063 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1064 if (SUCCEEDED(hres1))
1066 FIXME("handle OLE link\n");
1067 IOleLink_Release(pOleLink);
1073 IUnknown_Release(pUnk);
1082 /***********************************************************************
1085 HRESULT WINAPI OleSave(
1086 LPPERSISTSTORAGE pPS,
1093 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1096 * First, we transfer the class ID (if available)
1098 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1100 if (SUCCEEDED(hres))
1102 WriteClassStg(pStg, &objectClass);
1106 * Then, we ask the object to save itself to the
1107 * storage. If it is successful, we commit the storage.
1109 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1111 if (SUCCEEDED(hres))
1113 IStorage_Commit(pStg,
1121 /******************************************************************************
1122 * OleLockRunning [OLE32.@]
1124 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1126 IRunnableObject* runnable = NULL;
1129 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1131 hres = IUnknown_QueryInterface(pUnknown,
1132 &IID_IRunnableObject,
1135 if (SUCCEEDED(hres))
1137 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1139 IRunnableObject_Release(runnable);
1144 return E_INVALIDARG;
1148 /**************************************************************************
1149 * Internal methods to manage the shared OLE menu in response to the
1150 * OLE***MenuDescriptor API
1154 * OLEMenu_Initialize()
1156 * Initializes the OLEMENU data structures.
1158 static void OLEMenu_Initialize(void)
1163 * OLEMenu_UnInitialize()
1165 * Releases the OLEMENU data structures.
1167 static void OLEMenu_UnInitialize(void)
1171 /*************************************************************************
1172 * OLEMenu_InstallHooks
1173 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1175 * RETURNS: TRUE if message hooks were successfully installed
1178 static BOOL OLEMenu_InstallHooks( DWORD tid )
1180 OleMenuHookItem *pHookItem = NULL;
1182 /* Create an entry for the hook table */
1183 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1184 sizeof(OleMenuHookItem)) ) )
1187 pHookItem->tid = tid;
1188 pHookItem->hHeap = GetProcessHeap();
1190 /* Install a thread scope message hook for WH_GETMESSAGE */
1191 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1192 0, GetCurrentThreadId() );
1193 if ( !pHookItem->GetMsg_hHook )
1196 /* Install a thread scope message hook for WH_CALLWNDPROC */
1197 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1198 0, GetCurrentThreadId() );
1199 if ( !pHookItem->CallWndProc_hHook )
1202 /* Insert the hook table entry */
1203 pHookItem->next = hook_list;
1204 hook_list = pHookItem;
1209 /* Unhook any hooks */
1210 if ( pHookItem->GetMsg_hHook )
1211 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1212 if ( pHookItem->CallWndProc_hHook )
1213 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1214 /* Release the hook table entry */
1215 HeapFree(pHookItem->hHeap, 0, pHookItem );
1220 /*************************************************************************
1221 * OLEMenu_UnInstallHooks
1222 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1224 * RETURNS: TRUE if message hooks were successfully installed
1227 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1229 OleMenuHookItem *pHookItem = NULL;
1230 OleMenuHookItem **ppHook = &hook_list;
1234 if ((*ppHook)->tid == tid)
1236 pHookItem = *ppHook;
1237 *ppHook = pHookItem->next;
1240 ppHook = &(*ppHook)->next;
1242 if (!pHookItem) return FALSE;
1244 /* Uninstall the hooks installed for this thread */
1245 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1247 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1250 /* Release the hook table entry */
1251 HeapFree(pHookItem->hHeap, 0, pHookItem );
1256 /* Release the hook table entry */
1257 HeapFree(pHookItem->hHeap, 0, pHookItem );
1262 /*************************************************************************
1263 * OLEMenu_IsHookInstalled
1264 * Tests if OLEMenu hooks have been installed for a thread
1266 * RETURNS: The pointer and index of the hook table entry for the tid
1267 * NULL and -1 for the index if no hooks were installed for this thread
1269 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1271 OleMenuHookItem *pHookItem = NULL;
1273 /* Do a simple linear search for an entry whose tid matches ours.
1274 * We really need a map but efficiency is not a concern here. */
1275 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1277 if ( tid == pHookItem->tid )
1284 /***********************************************************************
1285 * OLEMenu_FindMainMenuIndex
1287 * Used by OLEMenu API to find the top level group a menu item belongs to.
1288 * On success pnPos contains the index of the item in the top level menu group
1290 * RETURNS: TRUE if the ID was found, FALSE on failure
1292 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1296 nItems = GetMenuItemCount( hMainMenu );
1298 for (i = 0; i < nItems; i++)
1302 /* Is the current item a submenu? */
1303 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1305 /* If the handle is the same we're done */
1306 if ( hsubmenu == hPopupMenu )
1312 /* Recursively search without updating pnPos */
1313 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1325 /***********************************************************************
1326 * OLEMenu_SetIsServerMenu
1328 * Checks whether a popup menu belongs to a shared menu group which is
1329 * owned by the server, and sets the menu descriptor state accordingly.
1330 * All menu messages from these groups should be routed to the server.
1332 * RETURNS: TRUE if the popup menu is part of a server owned group
1333 * FALSE if the popup menu is part of a container owned group
1335 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1337 UINT nPos = 0, nWidth, i;
1339 pOleMenuDescriptor->bIsServerItem = FALSE;
1341 /* Don't bother searching if the popup is the combined menu itself */
1342 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1345 /* Find the menu item index in the shared OLE menu that this item belongs to */
1346 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1349 /* The group widths array has counts for the number of elements
1350 * in the groups File, Edit, Container, Object, Window, Help.
1351 * The Edit, Object & Help groups belong to the server object
1352 * and the other three belong to the container.
1353 * Loop through the group widths and locate the group we are a member of.
1355 for ( i = 0, nWidth = 0; i < 6; i++ )
1357 nWidth += pOleMenuDescriptor->mgw.width[i];
1358 if ( nPos < nWidth )
1360 /* Odd elements are server menu widths */
1361 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1366 return pOleMenuDescriptor->bIsServerItem;
1369 /*************************************************************************
1370 * OLEMenu_CallWndProc
1371 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1372 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1374 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1376 LPCWPSTRUCT pMsg = NULL;
1377 HOLEMENU hOleMenu = 0;
1378 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1379 OleMenuHookItem *pHookItem = NULL;
1382 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1384 /* Check if we're being asked to process the message */
1385 if ( HC_ACTION != code )
1388 /* Retrieve the current message being dispatched from lParam */
1389 pMsg = (LPCWPSTRUCT)lParam;
1391 /* Check if the message is destined for a window we are interested in:
1392 * If the window has an OLEMenu property we may need to dispatch
1393 * the menu message to its active objects window instead. */
1395 hOleMenu = GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1399 /* Get the menu descriptor */
1400 pOleMenuDescriptor = GlobalLock( hOleMenu );
1401 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1404 /* Process menu messages */
1405 switch( pMsg->message )
1409 /* Reset the menu descriptor state */
1410 pOleMenuDescriptor->bIsServerItem = FALSE;
1412 /* Send this message to the server as well */
1413 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1414 pMsg->message, pMsg->wParam, pMsg->lParam );
1418 case WM_INITMENUPOPUP:
1420 /* Save the state for whether this is a server owned menu */
1421 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1427 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1428 if ( fuFlags & MF_SYSMENU )
1431 /* Save the state for whether this is a server owned popup menu */
1432 else if ( fuFlags & MF_POPUP )
1433 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1440 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1441 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1442 goto NEXTHOOK; /* Not a menu message */
1451 /* If the message was for the server dispatch it accordingly */
1452 if ( pOleMenuDescriptor->bIsServerItem )
1454 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1455 pMsg->message, pMsg->wParam, pMsg->lParam );
1459 if ( pOleMenuDescriptor )
1460 GlobalUnlock( hOleMenu );
1462 /* Lookup the hook item for the current thread */
1463 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1465 /* This should never fail!! */
1466 WARN("could not retrieve hHook for current thread!\n" );
1470 /* Pass on the message to the next hooker */
1471 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1474 /*************************************************************************
1475 * OLEMenu_GetMsgProc
1476 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1477 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1479 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1482 HOLEMENU hOleMenu = 0;
1483 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1484 OleMenuHookItem *pHookItem = NULL;
1487 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1489 /* Check if we're being asked to process a messages */
1490 if ( HC_ACTION != code )
1493 /* Retrieve the current message being dispatched from lParam */
1494 pMsg = (LPMSG)lParam;
1496 /* Check if the message is destined for a window we are interested in:
1497 * If the window has an OLEMenu property we may need to dispatch
1498 * the menu message to its active objects window instead. */
1500 hOleMenu = GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1504 /* Process menu messages */
1505 switch( pMsg->message )
1509 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1511 goto NEXTHOOK; /* Not a menu message */
1518 /* Get the menu descriptor */
1519 pOleMenuDescriptor = GlobalLock( hOleMenu );
1520 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1523 /* If the message was for the server dispatch it accordingly */
1524 if ( pOleMenuDescriptor->bIsServerItem )
1526 /* Change the hWnd in the message to the active objects hWnd.
1527 * The message loop which reads this message will automatically
1528 * dispatch it to the embedded objects window. */
1529 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1533 if ( pOleMenuDescriptor )
1534 GlobalUnlock( hOleMenu );
1536 /* Lookup the hook item for the current thread */
1537 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1539 /* This should never fail!! */
1540 WARN("could not retrieve hHook for current thread!\n" );
1544 /* Pass on the message to the next hooker */
1545 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1548 /***********************************************************************
1549 * OleCreateMenuDescriptor [OLE32.@]
1550 * Creates an OLE menu descriptor for OLE to use when dispatching
1551 * menu messages and commands.
1554 * hmenuCombined - Handle to the objects combined menu
1555 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1558 HOLEMENU WINAPI OleCreateMenuDescriptor(
1559 HMENU hmenuCombined,
1560 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1563 OleMenuDescriptor *pOleMenuDescriptor;
1566 if ( !hmenuCombined || !lpMenuWidths )
1569 /* Create an OLE menu descriptor */
1570 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1571 sizeof(OleMenuDescriptor) ) ) )
1574 pOleMenuDescriptor = GlobalLock( hOleMenu );
1575 if ( !pOleMenuDescriptor )
1578 /* Initialize menu group widths and hmenu */
1579 for ( i = 0; i < 6; i++ )
1580 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1582 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1583 pOleMenuDescriptor->bIsServerItem = FALSE;
1584 GlobalUnlock( hOleMenu );
1589 /***********************************************************************
1590 * OleDestroyMenuDescriptor [OLE32.@]
1591 * Destroy the shared menu descriptor
1593 HRESULT WINAPI OleDestroyMenuDescriptor(
1594 HOLEMENU hmenuDescriptor)
1596 if ( hmenuDescriptor )
1597 GlobalFree( hmenuDescriptor );
1601 /***********************************************************************
1602 * OleSetMenuDescriptor [OLE32.@]
1603 * Installs or removes OLE dispatching code for the containers frame window.
1606 * hOleMenu Handle to composite menu descriptor
1607 * hwndFrame Handle to containers frame window
1608 * hwndActiveObject Handle to objects in-place activation window
1609 * lpFrame Pointer to IOleInPlaceFrame on containers window
1610 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1613 * S_OK - menu installed correctly
1614 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1617 * The lpFrame and lpActiveObject parameters are currently ignored
1618 * OLE should install context sensitive help F1 filtering for the app when
1619 * these are non null.
1621 HRESULT WINAPI OleSetMenuDescriptor(
1624 HWND hwndActiveObject,
1625 LPOLEINPLACEFRAME lpFrame,
1626 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1628 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1631 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1632 return E_INVALIDARG;
1634 if ( lpFrame || lpActiveObject )
1636 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1644 /* Set up a message hook to intercept the containers frame window messages.
1645 * The message filter is responsible for dispatching menu messages from the
1646 * shared menu which are intended for the object.
1649 if ( hOleMenu ) /* Want to install dispatching code */
1651 /* If OLEMenu hooks are already installed for this thread, fail
1652 * Note: This effectively means that OleSetMenuDescriptor cannot
1653 * be called twice in succession on the same frame window
1654 * without first calling it with a null hOleMenu to uninstall */
1655 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1658 /* Get the menu descriptor */
1659 pOleMenuDescriptor = GlobalLock( hOleMenu );
1660 if ( !pOleMenuDescriptor )
1661 return E_UNEXPECTED;
1663 /* Update the menu descriptor */
1664 pOleMenuDescriptor->hwndFrame = hwndFrame;
1665 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1667 GlobalUnlock( hOleMenu );
1668 pOleMenuDescriptor = NULL;
1670 /* Add a menu descriptor windows property to the frame window */
1671 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1673 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1674 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1677 else /* Want to uninstall dispatching code */
1679 /* Uninstall the hooks */
1680 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1683 /* Remove the menu descriptor property from the frame window */
1684 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1690 /******************************************************************************
1691 * IsAccelerator [OLE32.@]
1692 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1694 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1699 if(!lpMsg) return FALSE;
1702 WARN_(accel)("NULL accel handle\n");
1705 if((lpMsg->message != WM_KEYDOWN &&
1706 lpMsg->message != WM_SYSKEYDOWN &&
1707 lpMsg->message != WM_SYSCHAR &&
1708 lpMsg->message != WM_CHAR)) return FALSE;
1709 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1710 if (NULL == lpAccelTbl)
1714 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1716 WARN_(accel)("CopyAcceleratorTableW failed\n");
1717 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1721 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1722 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1723 hAccel, cAccelEntries,
1724 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1725 for(i = 0; i < cAccelEntries; i++)
1727 if(lpAccelTbl[i].key != lpMsg->wParam)
1730 if(lpMsg->message == WM_CHAR)
1732 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1734 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg->wParam) & 0xff);
1740 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1743 TRACE_(accel)("found accel for virt_key %04lx (scan %04x)\n",
1744 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1745 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1746 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1747 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1748 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1749 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1753 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1755 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1756 { /* ^^ ALT pressed */
1757 TRACE_(accel)("found accel for Alt-%c\n", LOWORD(lpMsg->wParam) & 0xff);
1765 WARN_(accel)("couldn't translate accelerator key\n");
1766 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1770 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1771 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1775 /***********************************************************************
1776 * ReleaseStgMedium [OLE32.@]
1778 void WINAPI ReleaseStgMedium(
1781 switch (pmedium->tymed)
1785 if ( (pmedium->pUnkForRelease==0) &&
1786 (pmedium->u.hGlobal!=0) )
1787 GlobalFree(pmedium->u.hGlobal);
1792 if (pmedium->u.lpszFileName!=0)
1794 if (pmedium->pUnkForRelease==0)
1796 DeleteFileW(pmedium->u.lpszFileName);
1799 CoTaskMemFree(pmedium->u.lpszFileName);
1805 if (pmedium->u.pstm!=0)
1807 IStream_Release(pmedium->u.pstm);
1811 case TYMED_ISTORAGE:
1813 if (pmedium->u.pstg!=0)
1815 IStorage_Release(pmedium->u.pstg);
1821 if ( (pmedium->pUnkForRelease==0) &&
1822 (pmedium->u.hBitmap!=0) )
1823 DeleteObject(pmedium->u.hBitmap);
1828 if ( (pmedium->pUnkForRelease==0) &&
1829 (pmedium->u.hMetaFilePict!=0) )
1831 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1832 DeleteMetaFile(pMP->hMF);
1833 GlobalUnlock(pmedium->u.hMetaFilePict);
1834 GlobalFree(pmedium->u.hMetaFilePict);
1840 if ( (pmedium->pUnkForRelease==0) &&
1841 (pmedium->u.hEnhMetaFile!=0) )
1843 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1851 pmedium->tymed=TYMED_NULL;
1854 * After cleaning up, the unknown is released
1856 if (pmedium->pUnkForRelease!=0)
1858 IUnknown_Release(pmedium->pUnkForRelease);
1859 pmedium->pUnkForRelease = 0;
1864 * OLEDD_Initialize()
1866 * Initializes the OLE drag and drop data structures.
1868 static void OLEDD_Initialize(void)
1872 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1873 wndClass.style = CS_GLOBALCLASS;
1874 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1875 wndClass.cbClsExtra = 0;
1876 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1877 wndClass.hCursor = 0;
1878 wndClass.hbrBackground = 0;
1879 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1881 RegisterClassA (&wndClass);
1885 * OLEDD_FreeDropTarget()
1887 * Frees the drag and drop data structure
1889 static void OLEDD_FreeDropTarget(DropTargetNode *dropTargetInfo, BOOL release_drop_target)
1891 list_remove(&dropTargetInfo->entry);
1892 if (release_drop_target) IDropTarget_Release(dropTargetInfo->dropTarget);
1893 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
1897 * OLEDD_UnInitialize()
1899 * Releases the OLE drag and drop data structures.
1901 void OLEDD_UnInitialize(void)
1904 * Simply empty the list.
1906 while (!list_empty(&targetListHead))
1908 DropTargetNode* curNode = LIST_ENTRY(list_head(&targetListHead), DropTargetNode, entry);
1909 OLEDD_FreeDropTarget(curNode, FALSE);
1914 * OLEDD_FindDropTarget()
1916 * Finds information about the drop target.
1918 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1920 DropTargetNode* curNode;
1923 * Iterate the list to find the HWND value.
1925 LIST_FOR_EACH_ENTRY(curNode, &targetListHead, DropTargetNode, entry)
1926 if (hwndOfTarget==curNode->hwndTarget)
1930 * If we get here, the item is not in the list
1936 * OLEDD_DragTrackerWindowProc()
1938 * This method is the WindowProcedure of the drag n drop tracking
1939 * window. During a drag n Drop operation, an invisible window is created
1940 * to receive the user input and act upon it. This procedure is in charge
1944 #define DRAG_TIMER_ID 1
1946 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1956 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1958 SetWindowLongPtrA(hwnd, 0, (LONG_PTR)createStruct->lpCreateParams);
1959 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
1966 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1972 case WM_LBUTTONDOWN:
1973 case WM_MBUTTONDOWN:
1974 case WM_RBUTTONDOWN:
1976 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1981 KillTimer(hwnd, DRAG_TIMER_ID);
1987 * This is a window proc after all. Let's call the default.
1989 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1993 * OLEDD_TrackMouseMove()
1995 * This method is invoked while a drag and drop operation is in effect.
1996 * it will generate the appropriate callbacks in the drop source
1997 * and drop target. It will also provide the expected feedback to
2001 * trackerInfo - Pointer to the structure identifying the
2002 * drag & drop operation that is currently
2005 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
2007 HWND hwndNewTarget = 0;
2012 * Get the handle of the window under the mouse
2014 pt.x = trackerInfo->curMousePos.x;
2015 pt.y = trackerInfo->curMousePos.y;
2016 hwndNewTarget = WindowFromPoint(pt);
2019 * Every time, we re-initialize the effects passed to the
2020 * IDropTarget to the effects allowed by the source.
2022 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2025 * If we are hovering over the same target as before, send the
2026 * DragOver notification
2028 if ( (trackerInfo->curDragTarget != 0) &&
2029 (trackerInfo->curTargetHWND == hwndNewTarget) )
2031 IDropTarget_DragOver(trackerInfo->curDragTarget,
2032 trackerInfo->dwKeyState,
2033 trackerInfo->curMousePos,
2034 trackerInfo->pdwEffect);
2038 DropTargetNode* newDropTargetNode = 0;
2041 * If we changed window, we have to notify our old target and check for
2044 if (trackerInfo->curDragTarget!=0)
2046 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2050 * Make sure we're hovering over a window.
2052 if (hwndNewTarget!=0)
2055 * Find-out if there is a drag target under the mouse
2057 HWND nexttar = hwndNewTarget;
2058 trackerInfo->curTargetHWND = hwndNewTarget;
2061 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
2062 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
2063 if(nexttar) hwndNewTarget = nexttar;
2065 trackerInfo->curDragTargetHWND = hwndNewTarget;
2066 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
2069 * If there is, notify it that we just dragged-in
2071 if (trackerInfo->curDragTarget!=0)
2073 IDropTarget_DragEnter(trackerInfo->curDragTarget,
2074 trackerInfo->dataObject,
2075 trackerInfo->dwKeyState,
2076 trackerInfo->curMousePos,
2077 trackerInfo->pdwEffect);
2083 * The mouse is not over a window so we don't track anything.
2085 trackerInfo->curDragTargetHWND = 0;
2086 trackerInfo->curTargetHWND = 0;
2087 trackerInfo->curDragTarget = 0;
2092 * Now that we have done that, we have to tell the source to give
2093 * us feedback on the work being done by the target. If we don't
2094 * have a target, simulate no effect.
2096 if (trackerInfo->curDragTarget==0)
2098 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2101 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2102 *trackerInfo->pdwEffect);
2105 * When we ask for feedback from the drop source, sometimes it will
2106 * do all the necessary work and sometimes it will not handle it
2107 * when that's the case, we must display the standard drag and drop
2110 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2112 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2114 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(1)));
2116 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2118 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(2)));
2120 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2122 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(3)));
2126 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(0)));
2132 * OLEDD_TrackStateChange()
2134 * This method is invoked while a drag and drop operation is in effect.
2135 * It is used to notify the drop target/drop source callbacks when
2136 * the state of the keyboard or mouse button change.
2139 * trackerInfo - Pointer to the structure identifying the
2140 * drag & drop operation that is currently
2143 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2146 * Ask the drop source what to do with the operation.
2148 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2149 trackerInfo->dropSource,
2150 trackerInfo->escPressed,
2151 trackerInfo->dwKeyState);
2154 * All the return valued will stop the operation except the S_OK
2157 if (trackerInfo->returnValue!=S_OK)
2160 * Make sure the message loop in DoDragDrop stops
2162 trackerInfo->trackingDone = TRUE;
2165 * Release the mouse in case the drop target decides to show a popup
2166 * or a menu or something.
2171 * If we end-up over a target, drop the object in the target or
2172 * inform the target that the operation was cancelled.
2174 if (trackerInfo->curDragTarget!=0)
2176 switch (trackerInfo->returnValue)
2179 * If the source wants us to complete the operation, we tell
2180 * the drop target that we just dropped the object in it.
2182 case DRAGDROP_S_DROP:
2184 IDropTarget_Drop(trackerInfo->curDragTarget,
2185 trackerInfo->dataObject,
2186 trackerInfo->dwKeyState,
2187 trackerInfo->curMousePos,
2188 trackerInfo->pdwEffect);
2192 * If the source told us that we should cancel, fool the drop
2193 * target by telling it that the mouse left it's window.
2194 * Also set the drop effect to "NONE" in case the application
2195 * ignores the result of DoDragDrop.
2197 case DRAGDROP_S_CANCEL:
2198 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2199 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2207 * OLEDD_GetButtonState()
2209 * This method will use the current state of the keyboard to build
2210 * a button state mask equivalent to the one passed in the
2211 * WM_MOUSEMOVE wParam.
2213 static DWORD OLEDD_GetButtonState(void)
2215 BYTE keyboardState[256];
2218 GetKeyboardState(keyboardState);
2220 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2221 keyMask |= MK_SHIFT;
2223 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2224 keyMask |= MK_CONTROL;
2226 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2227 keyMask |= MK_LBUTTON;
2229 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2230 keyMask |= MK_RBUTTON;
2232 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2233 keyMask |= MK_MBUTTON;
2239 * OLEDD_GetButtonState()
2241 * This method will read the default value of the registry key in
2242 * parameter and extract a DWORD value from it. The registry key value
2243 * can be in a string key or a DWORD key.
2246 * regKey - Key to read the default value from
2247 * pdwValue - Pointer to the location where the DWORD
2248 * value is returned. This value is not modified
2249 * if the value is not found.
2252 static void OLEUTL_ReadRegistryDWORDValue(
2261 lres = RegQueryValueExA(regKey,
2268 if (lres==ERROR_SUCCESS)
2273 *pdwValue = *(DWORD*)buffer;
2278 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2284 /******************************************************************************
2287 * The operation of this function is documented literally in the WinAPI
2288 * documentation to involve a QueryInterface for the IViewObject interface,
2289 * followed by a call to IViewObject::Draw.
2291 HRESULT WINAPI OleDraw(
2298 IViewObject *viewobject;
2300 hres = IUnknown_QueryInterface(pUnk,
2302 (void**)&viewobject);
2304 if (SUCCEEDED(hres))
2308 rectl.left = lprcBounds->left;
2309 rectl.right = lprcBounds->right;
2310 rectl.top = lprcBounds->top;
2311 rectl.bottom = lprcBounds->bottom;
2312 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2314 IViewObject_Release(viewobject);
2319 return DV_E_NOIVIEWOBJECT;
2323 /***********************************************************************
2324 * OleTranslateAccelerator [OLE32.@]
2326 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2327 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2331 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2333 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2334 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2339 /******************************************************************************
2340 * OleCreate [OLE32.@]
2343 HRESULT WINAPI OleCreate(
2347 LPFORMATETC pFormatEtc,
2348 LPOLECLIENTSITE pClientSite,
2353 IUnknown * pUnk = NULL;
2354 IOleObject *pOleObject = NULL;
2356 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid),
2357 debugstr_guid(riid), renderopt, pFormatEtc, pClientSite, pStg, ppvObj);
2359 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, riid, (LPVOID*)&pUnk);
2361 if (SUCCEEDED(hres))
2362 hres = IStorage_SetClass(pStg, rclsid);
2364 if (pClientSite && SUCCEEDED(hres))
2366 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2367 if (SUCCEEDED(hres))
2370 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2374 if (SUCCEEDED(hres))
2376 IPersistStorage * pPS;
2377 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2379 TRACE("trying to set stg %p\n", pStg);
2380 hres = IPersistStorage_InitNew(pPS, pStg);
2381 TRACE("-- result 0x%08x\n", hres);
2382 IPersistStorage_Release(pPS);
2386 if (pClientSite && SUCCEEDED(hres))
2388 TRACE("trying to set clientsite %p\n", pClientSite);
2389 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2390 TRACE("-- result 0x%08x\n", hres);
2394 IOleObject_Release(pOleObject);
2396 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2399 IRunnableObject *pRunnable;
2400 IOleCache *pOleCache;
2403 hres2 = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2404 if (SUCCEEDED(hres2))
2406 hres = IRunnableObject_Run(pRunnable, NULL);
2407 IRunnableObject_Release(pRunnable);
2410 if (SUCCEEDED(hres))
2412 hres2 = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2413 if (SUCCEEDED(hres2))
2416 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2417 IOleCache_Release(pOleCache);
2422 if (FAILED(hres) && pUnk)
2424 IUnknown_Release(pUnk);
2430 TRACE("-- %p\n", pUnk);
2434 /******************************************************************************
2435 * OleGetAutoConvert [OLE32.@]
2437 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2439 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2441 WCHAR buf[CHARS_IN_GUID];
2445 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2450 if (RegQueryValueW(hkey, NULL, buf, &len))
2452 res = REGDB_E_KEYMISSING;
2455 res = CLSIDFromString(buf, pClsidNew);
2457 if (hkey) RegCloseKey(hkey);
2461 /******************************************************************************
2462 * OleSetAutoConvert [OLE32.@]
2464 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2466 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2468 WCHAR szClsidNew[CHARS_IN_GUID];
2471 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2473 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2476 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2477 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2479 res = REGDB_E_WRITEREGDB;
2484 if (hkey) RegCloseKey(hkey);
2488 /******************************************************************************
2489 * OleDoAutoConvert [OLE32.@]
2491 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2493 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2497 /******************************************************************************
2498 * OleIsRunning [OLE32.@]
2500 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2502 IRunnableObject *pRunnable;
2506 TRACE("(%p)\n", pObject);
2508 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2511 running = IRunnableObject_IsRunning(pRunnable);
2512 IRunnableObject_Release(pRunnable);
2516 /***********************************************************************
2517 * OleNoteObjectVisible [OLE32.@]
2519 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2521 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2522 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2526 /***********************************************************************
2527 * OLE_FreeClipDataArray [internal]
2530 * frees the data associated with an array of CLIPDATAs
2532 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2535 for (i = 0; i < count; i++)
2536 if (pClipDataArray[i].pClipData)
2537 CoTaskMemFree(pClipDataArray[i].pClipData);
2540 /***********************************************************************
2541 * PropSysAllocString [OLE32.@]
2543 * Basically a copy of SysAllocStringLen.
2545 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2549 WCHAR* stringBuffer;
2554 len = lstrlenW(str);
2556 * Find the length of the buffer passed-in, in bytes.
2558 bufferSize = len * sizeof (WCHAR);
2561 * Allocate a new buffer to hold the string.
2562 * Don't forget to keep an empty spot at the beginning of the
2563 * buffer for the character count and an extra character at the
2566 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2567 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2570 * If the memory allocation failed, return a null pointer.
2576 * Copy the length of the string in the placeholder.
2578 *newBuffer = bufferSize;
2581 * Skip the byte count.
2585 memcpy(newBuffer, str, bufferSize);
2588 * Make sure that there is a nul character at the end of the
2591 stringBuffer = (WCHAR*)newBuffer;
2592 stringBuffer[len] = '\0';
2594 return stringBuffer;
2597 /***********************************************************************
2598 * PropSysFreeString [OLE32.@]
2600 * Copy of SysFreeString.
2602 void WINAPI PropSysFreeString(LPOLESTR str)
2604 DWORD* bufferPointer;
2606 /* NULL is a valid parameter */
2610 * We have to be careful when we free a BSTR pointer, it points to
2611 * the beginning of the string but it skips the byte count contained
2612 * before the string.
2614 bufferPointer = (DWORD*)str;
2619 * Free the memory from its "real" origin.
2621 HeapFree(GetProcessHeap(), 0, bufferPointer);
2624 /******************************************************************************
2625 * Check if a PROPVARIANT's type is valid.
2627 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2654 case VT_STREAMED_OBJECT:
2655 case VT_STORED_OBJECT:
2656 case VT_BLOB_OBJECT:
2659 case VT_I2|VT_VECTOR:
2660 case VT_I4|VT_VECTOR:
2661 case VT_R4|VT_VECTOR:
2662 case VT_R8|VT_VECTOR:
2663 case VT_CY|VT_VECTOR:
2664 case VT_DATE|VT_VECTOR:
2665 case VT_BSTR|VT_VECTOR:
2666 case VT_ERROR|VT_VECTOR:
2667 case VT_BOOL|VT_VECTOR:
2668 case VT_VARIANT|VT_VECTOR:
2669 case VT_UI1|VT_VECTOR:
2670 case VT_UI2|VT_VECTOR:
2671 case VT_UI4|VT_VECTOR:
2672 case VT_I8|VT_VECTOR:
2673 case VT_UI8|VT_VECTOR:
2674 case VT_LPSTR|VT_VECTOR:
2675 case VT_LPWSTR|VT_VECTOR:
2676 case VT_FILETIME|VT_VECTOR:
2677 case VT_CF|VT_VECTOR:
2678 case VT_CLSID|VT_VECTOR:
2681 WARN("Bad type %d\n", vt);
2682 return STG_E_INVALIDPARAMETER;
2685 /***********************************************************************
2686 * PropVariantClear [OLE32.@]
2688 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2692 TRACE("(%p)\n", pvar);
2697 hr = PROPVARIANT_ValidateType(pvar->vt);
2722 case VT_STREAMED_OBJECT:
2724 case VT_STORED_OBJECT:
2725 if (pvar->u.pStream)
2726 IUnknown_Release(pvar->u.pStream);
2731 /* pick an arbitrary typed pointer - we don't care about the type
2732 * as we are just freeing it */
2733 CoTaskMemFree(pvar->u.puuid);
2736 case VT_BLOB_OBJECT:
2737 CoTaskMemFree(pvar->u.blob.pBlobData);
2740 if (pvar->u.bstrVal)
2741 PropSysFreeString(pvar->u.bstrVal);
2744 if (pvar->u.pclipdata)
2746 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2747 CoTaskMemFree(pvar->u.pclipdata);
2751 if (pvar->vt & VT_VECTOR)
2755 switch (pvar->vt & ~VT_VECTOR)
2758 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2761 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2764 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2765 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2768 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2769 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2772 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2773 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2776 if (pvar->vt & ~VT_VECTOR)
2778 /* pick an arbitrary VT_VECTOR structure - they all have the same
2780 CoTaskMemFree(pvar->u.capropvar.pElems);
2784 WARN("Invalid/unsupported type %d\n", pvar->vt);
2787 ZeroMemory(pvar, sizeof(*pvar));
2792 /***********************************************************************
2793 * PropVariantCopy [OLE32.@]
2795 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2796 const PROPVARIANT *pvarSrc) /* [in] */
2801 TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt);
2803 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2807 /* this will deal with most cases */
2808 *pvarDest = *pvarSrc;
2832 case VT_STREAMED_OBJECT:
2834 case VT_STORED_OBJECT:
2835 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2838 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2839 *pvarDest->u.puuid = *pvarSrc->u.puuid;
2842 len = strlen(pvarSrc->u.pszVal);
2843 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2844 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2847 len = lstrlenW(pvarSrc->u.pwszVal);
2848 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2849 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2852 case VT_BLOB_OBJECT:
2853 if (pvarSrc->u.blob.pBlobData)
2855 len = pvarSrc->u.blob.cbSize;
2856 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2857 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2861 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2864 if (pvarSrc->u.pclipdata)
2866 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2867 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
2868 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
2869 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
2870 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
2871 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2875 if (pvarSrc->vt & VT_VECTOR)
2880 switch(pvarSrc->vt & ~VT_VECTOR)
2882 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2883 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2884 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2885 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2886 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2887 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2888 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2889 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2890 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2891 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2892 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2893 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2894 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2895 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2896 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2897 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2898 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2899 case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break;
2900 case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break;
2901 case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break;
2902 case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break;
2905 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2906 return E_INVALIDARG;
2908 len = pvarSrc->u.capropvar.cElems;
2909 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2910 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2912 for (i = 0; i < len; i++)
2913 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2915 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2917 FIXME("Copy clipformats\n");
2919 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2921 for (i = 0; i < len; i++)
2922 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2924 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2927 for (i = 0; i < len; i++)
2929 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2930 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2931 memcpy(pvarDest->u.calpstr.pElems[i],
2932 pvarSrc->u.calpstr.pElems[i], strLen);
2935 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2938 for (i = 0; i < len; i++)
2940 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2942 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2943 memcpy(pvarDest->u.calpstr.pElems[i],
2944 pvarSrc->u.calpstr.pElems[i], strLen);
2948 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2951 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2957 /***********************************************************************
2958 * FreePropVariantArray [OLE32.@]
2960 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2961 PROPVARIANT *rgvars) /* [in/out] */
2965 TRACE("(%u, %p)\n", cVariants, rgvars);
2968 return E_INVALIDARG;
2970 for(i = 0; i < cVariants; i++)
2971 PropVariantClear(&rgvars[i]);
2976 /******************************************************************************
2977 * DllDebugObjectRPCHook (OLE32.@)
2978 * turns on and off internal debugging, pointer is only used on macintosh
2981 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)