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
49 #include "wine/unicode.h"
50 #include "compobj_private.h"
51 #include "wine/list.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(ole);
56 WINE_DECLARE_DEBUG_CHANNEL(accel);
58 /******************************************************************************
59 * These are static/global variables and internal data structures that the
60 * OLE module uses to maintain it's state.
62 typedef struct tagDropTargetNode
65 IDropTarget* dropTarget;
69 typedef struct tagTrackerWindowInfo
71 IDataObject* dataObject;
72 IDropSource* dropSource;
79 HWND curTargetHWND; /* window the mouse is hovering over */
80 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
81 IDropTarget* curDragTarget;
82 POINTL curMousePos; /* current position of the mouse in screen coordinates */
83 DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
86 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
88 HWND hwndFrame; /* The containers frame window */
89 HWND hwndActiveObject; /* The active objects window */
90 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
91 HMENU hmenuCombined; /* The combined menu */
92 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
95 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
97 DWORD tid; /* Thread Id */
98 HANDLE hHeap; /* Heap this is allocated from */
99 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
100 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
101 struct tagOleMenuHookItem *next;
104 static OleMenuHookItem *hook_list;
107 * This is the lock count on the OLE library. It is controlled by the
108 * OLEInitialize/OLEUninitialize methods.
110 static ULONG OLE_moduleLockCount = 0;
113 * Name of our registered window class.
115 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
118 * This is the head of the Drop target container.
120 static struct list targetListHead = LIST_INIT(targetListHead);
122 /******************************************************************************
123 * These are the prototypes of miscelaneous utility methods
125 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
127 /******************************************************************************
128 * These are the prototypes of the utility methods used to manage a shared menu
130 static void OLEMenu_Initialize(void);
131 static void OLEMenu_UnInitialize(void);
132 static BOOL OLEMenu_InstallHooks( DWORD tid );
133 static BOOL OLEMenu_UnInstallHooks( DWORD tid );
134 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
135 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
136 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
137 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
138 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
140 /******************************************************************************
141 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
143 extern void OLEClipbrd_UnInitialize(void);
144 extern void OLEClipbrd_Initialize(void);
146 /******************************************************************************
147 * These are the prototypes of the utility methods used for OLE Drag n Drop
149 static void OLEDD_Initialize(void);
150 static void OLEDD_UnInitialize(void);
151 static DropTargetNode* OLEDD_FindDropTarget(
153 static void OLEDD_FreeDropTarget(DropTargetNode*);
154 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
159 static void OLEDD_TrackMouseMove(
160 TrackerWindowInfo* trackerInfo);
161 static void OLEDD_TrackStateChange(
162 TrackerWindowInfo* trackerInfo);
163 static DWORD OLEDD_GetButtonState(void);
166 /******************************************************************************
167 * OleBuildVersion [OLE2.1]
168 * OleBuildVersion [OLE32.@]
170 DWORD WINAPI OleBuildVersion(void)
172 TRACE("Returning version %d, build %d.\n", rmm, rup);
173 return (rmm<<16)+rup;
176 /***********************************************************************
177 * OleInitialize (OLE2.2)
178 * OleInitialize (OLE32.@)
180 HRESULT WINAPI OleInitialize(LPVOID reserved)
184 TRACE("(%p)\n", reserved);
187 * The first duty of the OleInitialize is to initialize the COM libraries.
189 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
192 * If the CoInitializeEx call failed, the OLE libraries can't be
199 * Then, it has to initialize the OLE specific modules.
203 * Object linking and Embedding
204 * In-place activation
206 if (OLE_moduleLockCount==0)
209 * Initialize the libraries.
211 TRACE("() - Initializing the OLE libraries\n");
216 OLEClipbrd_Initialize();
226 OLEMenu_Initialize();
230 * Then, we increase the lock count on the OLE module.
232 OLE_moduleLockCount++;
237 /******************************************************************************
238 * OleUninitialize [OLE2.3]
239 * OleUninitialize [OLE32.@]
241 void WINAPI OleUninitialize(void)
246 * Decrease the lock count on the OLE module.
248 OLE_moduleLockCount--;
251 * If we hit the bottom of the lock stack, free the libraries.
253 if (OLE_moduleLockCount==0)
256 * Actually free the libraries.
258 TRACE("() - Freeing the last reference count\n");
263 OLEClipbrd_UnInitialize();
268 OLEDD_UnInitialize();
273 OLEMenu_UnInitialize();
277 * Then, uninitialize the COM libraries.
282 /******************************************************************************
283 * OleInitializeWOW [OLE32.@]
285 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
286 FIXME("(0x%08lx, 0x%08lx),stub!\n",x, y);
290 /***********************************************************************
291 * RegisterDragDrop (OLE32.@)
293 HRESULT WINAPI RegisterDragDrop(
295 LPDROPTARGET pDropTarget)
297 DropTargetNode* dropTargetInfo;
299 TRACE("(%p,%p)\n", hwnd, pDropTarget);
305 * First, check if the window is already registered.
307 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
309 if (dropTargetInfo!=NULL)
310 return DRAGDROP_E_ALREADYREGISTERED;
313 * If it's not there, we can add it. We first create a node for it.
315 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
317 if (dropTargetInfo==NULL)
318 return E_OUTOFMEMORY;
320 dropTargetInfo->hwndTarget = hwnd;
323 * Don't forget that this is an interface pointer, need to nail it down since
324 * we keep a copy of it.
326 IDropTarget_AddRef(pDropTarget);
327 dropTargetInfo->dropTarget = pDropTarget;
329 list_add_tail(&targetListHead, &dropTargetInfo->entry);
334 /***********************************************************************
335 * RevokeDragDrop (OLE32.@)
337 HRESULT WINAPI RevokeDragDrop(
340 DropTargetNode* dropTargetInfo;
342 TRACE("(%p)\n", hwnd);
345 * First, check if the window is already registered.
347 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
350 * If it ain't in there, it's an error.
352 if (dropTargetInfo==NULL)
353 return DRAGDROP_E_NOTREGISTERED;
355 OLEDD_FreeDropTarget(dropTargetInfo);
360 /***********************************************************************
361 * OleRegGetUserType (OLE32.@)
363 * This implementation of OleRegGetUserType ignores the dwFormOfType
364 * parameter and always returns the full name of the object. This is
365 * not too bad since this is the case for many objects because of the
366 * way they are registered.
368 HRESULT WINAPI OleRegGetUserType(
371 LPOLESTR* pszUserType)
381 * Initialize the out parameter.
386 * Build the key name we're looking for
388 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
389 clsid->Data1, clsid->Data2, clsid->Data3,
390 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
391 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
393 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
396 * Open the class id Key
398 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
402 if (hres != ERROR_SUCCESS)
403 return REGDB_E_CLASSNOTREG;
406 * Retrieve the size of the name string.
410 hres = RegQueryValueExA(clsidKey,
417 if (hres!=ERROR_SUCCESS)
419 RegCloseKey(clsidKey);
420 return REGDB_E_READREGDB;
424 * Allocate a buffer for the registry value.
426 *pszUserType = CoTaskMemAlloc(cbData*2);
428 if (*pszUserType==NULL)
430 RegCloseKey(clsidKey);
431 return E_OUTOFMEMORY;
434 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
438 RegCloseKey(clsidKey);
439 CoTaskMemFree(*pszUserType);
441 return E_OUTOFMEMORY;
444 hres = RegQueryValueExA(clsidKey,
451 RegCloseKey(clsidKey);
454 if (hres!=ERROR_SUCCESS)
456 CoTaskMemFree(*pszUserType);
459 retVal = REGDB_E_READREGDB;
463 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
466 HeapFree(GetProcessHeap(), 0, buffer);
471 /***********************************************************************
472 * DoDragDrop [OLE32.@]
474 HRESULT WINAPI DoDragDrop (
475 IDataObject *pDataObject, /* [in] ptr to the data obj */
476 IDropSource* pDropSource, /* [in] ptr to the source obj */
477 DWORD dwOKEffect, /* [in] effects allowed by the source */
478 DWORD *pdwEffect) /* [out] ptr to effects of the source */
480 TrackerWindowInfo trackerInfo;
481 HWND hwndTrackWindow;
484 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
487 * Setup the drag n drop tracking window.
489 if (!IsValidInterface((LPUNKNOWN)pDropSource))
492 trackerInfo.dataObject = pDataObject;
493 trackerInfo.dropSource = pDropSource;
494 trackerInfo.dwOKEffect = dwOKEffect;
495 trackerInfo.pdwEffect = pdwEffect;
496 trackerInfo.trackingDone = FALSE;
497 trackerInfo.escPressed = FALSE;
498 trackerInfo.curDragTargetHWND = 0;
499 trackerInfo.curTargetHWND = 0;
500 trackerInfo.curDragTarget = 0;
502 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
505 CW_USEDEFAULT, CW_USEDEFAULT,
506 CW_USEDEFAULT, CW_USEDEFAULT,
510 (LPVOID)&trackerInfo);
512 if (hwndTrackWindow!=0)
515 * Capture the mouse input
517 SetCapture(hwndTrackWindow);
522 * Pump messages. All mouse input should go the the capture window.
524 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
526 trackerInfo.curMousePos.x = msg.pt.x;
527 trackerInfo.curMousePos.y = msg.pt.y;
528 trackerInfo.dwKeyState = OLEDD_GetButtonState();
530 if ( (msg.message >= WM_KEYFIRST) &&
531 (msg.message <= WM_KEYLAST) )
534 * When keyboard messages are sent to windows on this thread, we
535 * want to ignore notify the drop source that the state changed.
536 * in the case of the Escape key, we also notify the drop source
537 * we give it a special meaning.
539 if ( (msg.message==WM_KEYDOWN) &&
540 (msg.wParam==VK_ESCAPE) )
542 trackerInfo.escPressed = TRUE;
546 * Notify the drop source.
548 OLEDD_TrackStateChange(&trackerInfo);
553 * Dispatch the messages only when it's not a keyboard message.
555 DispatchMessageA(&msg);
559 /* re-post the quit message to outer message loop */
560 if (msg.message == WM_QUIT)
561 PostQuitMessage(msg.wParam);
563 * Destroy the temporary window.
565 DestroyWindow(hwndTrackWindow);
567 return trackerInfo.returnValue;
573 /***********************************************************************
574 * OleQueryLinkFromData [OLE32.@]
576 HRESULT WINAPI OleQueryLinkFromData(
577 IDataObject* pSrcDataObject)
579 FIXME("(%p),stub!\n", pSrcDataObject);
583 /***********************************************************************
584 * OleRegGetMiscStatus [OLE32.@]
586 HRESULT WINAPI OleRegGetMiscStatus(
598 * Initialize the out parameter.
603 * Build the key name we're looking for
605 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
606 clsid->Data1, clsid->Data2, clsid->Data3,
607 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
608 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
610 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
613 * Open the class id Key
615 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
619 if (result != ERROR_SUCCESS)
620 return REGDB_E_CLASSNOTREG;
625 result = RegOpenKeyA(clsidKey,
630 if (result != ERROR_SUCCESS)
632 RegCloseKey(clsidKey);
633 return REGDB_E_READREGDB;
637 * Read the default value
639 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
642 * Open the key specific to the requested aspect.
644 sprintf(keyName, "%ld", dwAspect);
646 result = RegOpenKeyA(miscStatusKey,
650 if (result == ERROR_SUCCESS)
652 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
653 RegCloseKey(aspectKey);
659 RegCloseKey(miscStatusKey);
660 RegCloseKey(clsidKey);
665 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
669 const IEnumOLEVERBVtbl *lpvtbl;
676 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
677 IEnumOLEVERB *iface, REFIID riid, void **ppv)
679 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
680 if (IsEqualIID(riid, &IID_IUnknown) ||
681 IsEqualIID(riid, &IID_IEnumOLEVERB))
683 IUnknown_AddRef(iface);
687 return E_NOINTERFACE;
690 static ULONG WINAPI EnumOLEVERB_AddRef(
693 EnumOLEVERB *This = (EnumOLEVERB *)iface;
695 return InterlockedIncrement(&This->ref);
698 static ULONG WINAPI EnumOLEVERB_Release(
701 EnumOLEVERB *This = (EnumOLEVERB *)iface;
702 LONG refs = InterlockedDecrement(&This->ref);
706 RegCloseKey(This->hkeyVerb);
707 HeapFree(GetProcessHeap(), 0, This);
712 static HRESULT WINAPI EnumOLEVERB_Next(
713 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
716 EnumOLEVERB *This = (EnumOLEVERB *)iface;
719 TRACE("(%ld, %p, %p)\n", celt, rgelt, pceltFetched);
724 for (; celt; celt--, rgelt++)
729 LPWSTR pwszMenuFlags;
731 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
732 if (res == ERROR_NO_MORE_ITEMS)
737 else if (res != ERROR_SUCCESS)
739 ERR("RegEnumKeyW failed with error %ld\n", res);
740 hr = REGDB_E_READREGDB;
743 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
744 if (res != ERROR_SUCCESS)
746 ERR("RegQueryValueW failed with error %ld\n", res);
747 hr = REGDB_E_READREGDB;
750 pwszOLEVERB = CoTaskMemAlloc(cbData);
756 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
757 if (res != ERROR_SUCCESS)
759 ERR("RegQueryValueW failed with error %ld\n", res);
760 hr = REGDB_E_READREGDB;
761 CoTaskMemFree(pwszOLEVERB);
765 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
766 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
769 hr = OLEOBJ_E_INVALIDVERB;
770 CoTaskMemFree(pwszOLEVERB);
773 /* nul terminate the name string and advance to first character */
774 *pwszMenuFlags = '\0';
776 pwszAttribs = strchrW(pwszMenuFlags, ',');
779 hr = OLEOBJ_E_INVALIDVERB;
780 CoTaskMemFree(pwszOLEVERB);
783 /* nul terminate the menu string and advance to first character */
787 /* fill out structure for this verb */
788 rgelt->lVerb = atolW(wszSubKey);
789 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
790 rgelt->fuFlags = atolW(pwszMenuFlags);
791 rgelt->grfAttribs = atolW(pwszAttribs);
800 static HRESULT WINAPI EnumOLEVERB_Skip(
801 IEnumOLEVERB *iface, ULONG celt)
803 EnumOLEVERB *This = (EnumOLEVERB *)iface;
805 TRACE("(%ld)\n", celt);
811 static HRESULT WINAPI EnumOLEVERB_Reset(
814 EnumOLEVERB *This = (EnumOLEVERB *)iface;
822 static HRESULT WINAPI EnumOLEVERB_Clone(
824 IEnumOLEVERB **ppenum)
826 EnumOLEVERB *This = (EnumOLEVERB *)iface;
828 TRACE("(%p)\n", ppenum);
829 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
830 return HRESULT_FROM_WIN32(GetLastError());
831 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
834 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
836 EnumOLEVERB_QueryInterface,
845 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
847 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
850 RegCloseKey(hkeyVerb);
851 return E_OUTOFMEMORY;
853 This->lpvtbl = &EnumOLEVERB_VTable;
856 This->hkeyVerb = hkeyVerb;
857 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
861 /***********************************************************************
862 * OleRegEnumVerbs [OLE32.@]
864 * Enumerates verbs associated with a class stored in the registry.
867 * clsid [I] Class ID to enumerate the verbs for.
868 * ppenum [O] Enumerator.
872 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
873 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
874 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
875 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
877 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
882 static const WCHAR wszVerb[] = {'V','e','r','b',0};
884 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
886 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
889 if (res == REGDB_E_CLASSNOTREG)
890 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
891 else if (res == REGDB_E_KEYMISSING)
892 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
894 ERR("failed to open Verbs key for CLSID %s with error %ld\n",
895 debugstr_guid(clsid), res);
899 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
900 NULL, NULL, NULL, NULL, NULL, NULL);
901 if (res != ERROR_SUCCESS)
903 ERR("failed to get subkey count with error %ld\n", GetLastError());
904 return REGDB_E_READREGDB;
909 WARN("class %s has no verbs\n", debugstr_guid(clsid));
910 RegCloseKey(hkeyVerb);
911 return OLEOBJ_E_NOVERBS;
914 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
917 /******************************************************************************
918 * OleSetContainedObject [OLE32.@]
920 HRESULT WINAPI OleSetContainedObject(
924 IRunnableObject* runnable = NULL;
927 TRACE("(%p,%x)\n", pUnknown, fContained);
929 hres = IUnknown_QueryInterface(pUnknown,
930 &IID_IRunnableObject,
935 hres = IRunnableObject_SetContainedObject(runnable, fContained);
937 IRunnableObject_Release(runnable);
945 /******************************************************************************
948 HRESULT WINAPI OleLoad(
951 LPOLECLIENTSITE pClientSite,
954 IPersistStorage* persistStorage = NULL;
956 IOleObject* pOleObject = NULL;
960 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
965 * TODO, Conversion ... OleDoAutoConvert
969 * Get the class ID for the object.
971 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
974 * Now, try and create the handler for the object
976 hres = CoCreateInstance(&storageInfo.clsid,
978 CLSCTX_INPROC_HANDLER,
983 * If that fails, as it will most times, load the default
988 hres = OleCreateDefaultHandler(&storageInfo.clsid,
995 * If we couldn't find a handler... this is bad. Abort the whole thing.
1002 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1003 if (SUCCEEDED(hres))
1006 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1010 if (SUCCEEDED(hres))
1012 * Initialize the object with it's IPersistStorage interface.
1014 hres = IOleObject_QueryInterface(pUnk,
1015 &IID_IPersistStorage,
1016 (void**)&persistStorage);
1018 if (SUCCEEDED(hres))
1020 hres = IPersistStorage_Load(persistStorage, pStg);
1022 IPersistStorage_Release(persistStorage);
1023 persistStorage = NULL;
1026 if (SUCCEEDED(hres) && pClientSite)
1028 * Inform the new object of it's client site.
1030 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1033 * Cleanup interfaces used internally
1036 IOleObject_Release(pOleObject);
1038 if (SUCCEEDED(hres))
1042 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1043 if (SUCCEEDED(hres1))
1045 FIXME("handle OLE link\n");
1046 IOleLink_Release(pOleLink);
1052 IUnknown_Release(pUnk);
1061 /***********************************************************************
1064 HRESULT WINAPI OleSave(
1065 LPPERSISTSTORAGE pPS,
1072 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1075 * First, we transfer the class ID (if available)
1077 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1079 if (SUCCEEDED(hres))
1081 WriteClassStg(pStg, &objectClass);
1085 * Then, we ask the object to save itself to the
1086 * storage. If it is successful, we commit the storage.
1088 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1090 if (SUCCEEDED(hres))
1092 IStorage_Commit(pStg,
1100 /******************************************************************************
1101 * OleLockRunning [OLE32.@]
1103 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1105 IRunnableObject* runnable = NULL;
1108 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1110 hres = IUnknown_QueryInterface(pUnknown,
1111 &IID_IRunnableObject,
1114 if (SUCCEEDED(hres))
1116 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1118 IRunnableObject_Release(runnable);
1123 return E_INVALIDARG;
1127 /**************************************************************************
1128 * Internal methods to manage the shared OLE menu in response to the
1129 * OLE***MenuDescriptor API
1133 * OLEMenu_Initialize()
1135 * Initializes the OLEMENU data structures.
1137 static void OLEMenu_Initialize(void)
1142 * OLEMenu_UnInitialize()
1144 * Releases the OLEMENU data structures.
1146 static void OLEMenu_UnInitialize(void)
1150 /*************************************************************************
1151 * OLEMenu_InstallHooks
1152 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1154 * RETURNS: TRUE if message hooks were successfully installed
1157 static BOOL OLEMenu_InstallHooks( DWORD tid )
1159 OleMenuHookItem *pHookItem = NULL;
1161 /* Create an entry for the hook table */
1162 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1163 sizeof(OleMenuHookItem)) ) )
1166 pHookItem->tid = tid;
1167 pHookItem->hHeap = GetProcessHeap();
1169 /* Install a thread scope message hook for WH_GETMESSAGE */
1170 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1171 0, GetCurrentThreadId() );
1172 if ( !pHookItem->GetMsg_hHook )
1175 /* Install a thread scope message hook for WH_CALLWNDPROC */
1176 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1177 0, GetCurrentThreadId() );
1178 if ( !pHookItem->CallWndProc_hHook )
1181 /* Insert the hook table entry */
1182 pHookItem->next = hook_list;
1183 hook_list = pHookItem;
1188 /* Unhook any hooks */
1189 if ( pHookItem->GetMsg_hHook )
1190 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1191 if ( pHookItem->CallWndProc_hHook )
1192 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1193 /* Release the hook table entry */
1194 HeapFree(pHookItem->hHeap, 0, pHookItem );
1199 /*************************************************************************
1200 * OLEMenu_UnInstallHooks
1201 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1203 * RETURNS: TRUE if message hooks were successfully installed
1206 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1208 OleMenuHookItem *pHookItem = NULL;
1209 OleMenuHookItem **ppHook = &hook_list;
1213 if ((*ppHook)->tid == tid)
1215 pHookItem = *ppHook;
1216 *ppHook = pHookItem->next;
1219 ppHook = &(*ppHook)->next;
1221 if (!pHookItem) return FALSE;
1223 /* Uninstall the hooks installed for this thread */
1224 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1226 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1229 /* Release the hook table entry */
1230 HeapFree(pHookItem->hHeap, 0, pHookItem );
1235 /* Release the hook table entry */
1236 HeapFree(pHookItem->hHeap, 0, pHookItem );
1241 /*************************************************************************
1242 * OLEMenu_IsHookInstalled
1243 * Tests if OLEMenu hooks have been installed for a thread
1245 * RETURNS: The pointer and index of the hook table entry for the tid
1246 * NULL and -1 for the index if no hooks were installed for this thread
1248 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1250 OleMenuHookItem *pHookItem = NULL;
1252 /* Do a simple linear search for an entry whose tid matches ours.
1253 * We really need a map but efficiency is not a concern here. */
1254 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1256 if ( tid == pHookItem->tid )
1263 /***********************************************************************
1264 * OLEMenu_FindMainMenuIndex
1266 * Used by OLEMenu API to find the top level group a menu item belongs to.
1267 * On success pnPos contains the index of the item in the top level menu group
1269 * RETURNS: TRUE if the ID was found, FALSE on failure
1271 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1275 nItems = GetMenuItemCount( hMainMenu );
1277 for (i = 0; i < nItems; i++)
1281 /* Is the current item a submenu? */
1282 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1284 /* If the handle is the same we're done */
1285 if ( hsubmenu == hPopupMenu )
1291 /* Recursively search without updating pnPos */
1292 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1304 /***********************************************************************
1305 * OLEMenu_SetIsServerMenu
1307 * Checks whether a popup menu belongs to a shared menu group which is
1308 * owned by the server, and sets the menu descriptor state accordingly.
1309 * All menu messages from these groups should be routed to the server.
1311 * RETURNS: TRUE if the popup menu is part of a server owned group
1312 * FALSE if the popup menu is part of a container owned group
1314 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1316 UINT nPos = 0, nWidth, i;
1318 pOleMenuDescriptor->bIsServerItem = FALSE;
1320 /* Don't bother searching if the popup is the combined menu itself */
1321 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1324 /* Find the menu item index in the shared OLE menu that this item belongs to */
1325 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1328 /* The group widths array has counts for the number of elements
1329 * in the groups File, Edit, Container, Object, Window, Help.
1330 * The Edit, Object & Help groups belong to the server object
1331 * and the other three belong to the container.
1332 * Loop through the group widths and locate the group we are a member of.
1334 for ( i = 0, nWidth = 0; i < 6; i++ )
1336 nWidth += pOleMenuDescriptor->mgw.width[i];
1337 if ( nPos < nWidth )
1339 /* Odd elements are server menu widths */
1340 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1345 return pOleMenuDescriptor->bIsServerItem;
1348 /*************************************************************************
1349 * OLEMenu_CallWndProc
1350 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1351 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1353 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1355 LPCWPSTRUCT pMsg = NULL;
1356 HOLEMENU hOleMenu = 0;
1357 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1358 OleMenuHookItem *pHookItem = NULL;
1361 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1363 /* Check if we're being asked to process the message */
1364 if ( HC_ACTION != code )
1367 /* Retrieve the current message being dispatched from lParam */
1368 pMsg = (LPCWPSTRUCT)lParam;
1370 /* Check if the message is destined for a window we are interested in:
1371 * If the window has an OLEMenu property we may need to dispatch
1372 * the menu message to its active objects window instead. */
1374 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1378 /* Get the menu descriptor */
1379 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1380 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1383 /* Process menu messages */
1384 switch( pMsg->message )
1388 /* Reset the menu descriptor state */
1389 pOleMenuDescriptor->bIsServerItem = FALSE;
1391 /* Send this message to the server as well */
1392 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1393 pMsg->message, pMsg->wParam, pMsg->lParam );
1397 case WM_INITMENUPOPUP:
1399 /* Save the state for whether this is a server owned menu */
1400 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1406 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1407 if ( fuFlags & MF_SYSMENU )
1410 /* Save the state for whether this is a server owned popup menu */
1411 else if ( fuFlags & MF_POPUP )
1412 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1419 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1420 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1421 goto NEXTHOOK; /* Not a menu message */
1430 /* If the message was for the server dispatch it accordingly */
1431 if ( pOleMenuDescriptor->bIsServerItem )
1433 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1434 pMsg->message, pMsg->wParam, pMsg->lParam );
1438 if ( pOleMenuDescriptor )
1439 GlobalUnlock( hOleMenu );
1441 /* Lookup the hook item for the current thread */
1442 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1444 /* This should never fail!! */
1445 WARN("could not retrieve hHook for current thread!\n" );
1449 /* Pass on the message to the next hooker */
1450 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1453 /*************************************************************************
1454 * OLEMenu_GetMsgProc
1455 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1456 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1458 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1461 HOLEMENU hOleMenu = 0;
1462 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1463 OleMenuHookItem *pHookItem = NULL;
1466 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1468 /* Check if we're being asked to process a messages */
1469 if ( HC_ACTION != code )
1472 /* Retrieve the current message being dispatched from lParam */
1473 pMsg = (LPMSG)lParam;
1475 /* Check if the message is destined for a window we are interested in:
1476 * If the window has an OLEMenu property we may need to dispatch
1477 * the menu message to its active objects window instead. */
1479 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1483 /* Process menu messages */
1484 switch( pMsg->message )
1488 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1490 goto NEXTHOOK; /* Not a menu message */
1497 /* Get the menu descriptor */
1498 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1499 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1502 /* If the message was for the server dispatch it accordingly */
1503 if ( pOleMenuDescriptor->bIsServerItem )
1505 /* Change the hWnd in the message to the active objects hWnd.
1506 * The message loop which reads this message will automatically
1507 * dispatch it to the embedded objects window. */
1508 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1512 if ( pOleMenuDescriptor )
1513 GlobalUnlock( hOleMenu );
1515 /* Lookup the hook item for the current thread */
1516 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1518 /* This should never fail!! */
1519 WARN("could not retrieve hHook for current thread!\n" );
1523 /* Pass on the message to the next hooker */
1524 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1527 /***********************************************************************
1528 * OleCreateMenuDescriptor [OLE32.@]
1529 * Creates an OLE menu descriptor for OLE to use when dispatching
1530 * menu messages and commands.
1533 * hmenuCombined - Handle to the objects combined menu
1534 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1537 HOLEMENU WINAPI OleCreateMenuDescriptor(
1538 HMENU hmenuCombined,
1539 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1542 OleMenuDescriptor *pOleMenuDescriptor;
1545 if ( !hmenuCombined || !lpMenuWidths )
1548 /* Create an OLE menu descriptor */
1549 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1550 sizeof(OleMenuDescriptor) ) ) )
1553 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1554 if ( !pOleMenuDescriptor )
1557 /* Initialize menu group widths and hmenu */
1558 for ( i = 0; i < 6; i++ )
1559 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1561 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1562 pOleMenuDescriptor->bIsServerItem = FALSE;
1563 GlobalUnlock( hOleMenu );
1568 /***********************************************************************
1569 * OleDestroyMenuDescriptor [OLE32.@]
1570 * Destroy the shared menu descriptor
1572 HRESULT WINAPI OleDestroyMenuDescriptor(
1573 HOLEMENU hmenuDescriptor)
1575 if ( hmenuDescriptor )
1576 GlobalFree( hmenuDescriptor );
1580 /***********************************************************************
1581 * OleSetMenuDescriptor [OLE32.@]
1582 * Installs or removes OLE dispatching code for the containers frame window.
1585 * hOleMenu Handle to composite menu descriptor
1586 * hwndFrame Handle to containers frame window
1587 * hwndActiveObject Handle to objects in-place activation window
1588 * lpFrame Pointer to IOleInPlaceFrame on containers window
1589 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1592 * S_OK - menu installed correctly
1593 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1596 * The lpFrame and lpActiveObject parameters are currently ignored
1597 * OLE should install context sensitive help F1 filtering for the app when
1598 * these are non null.
1600 HRESULT WINAPI OleSetMenuDescriptor(
1603 HWND hwndActiveObject,
1604 LPOLEINPLACEFRAME lpFrame,
1605 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1607 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1610 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1611 return E_INVALIDARG;
1613 if ( lpFrame || lpActiveObject )
1615 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1623 /* Set up a message hook to intercept the containers frame window messages.
1624 * The message filter is responsible for dispatching menu messages from the
1625 * shared menu which are intended for the object.
1628 if ( hOleMenu ) /* Want to install dispatching code */
1630 /* If OLEMenu hooks are already installed for this thread, fail
1631 * Note: This effectively means that OleSetMenuDescriptor cannot
1632 * be called twice in succession on the same frame window
1633 * without first calling it with a null hOleMenu to uninstall */
1634 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1637 /* Get the menu descriptor */
1638 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1639 if ( !pOleMenuDescriptor )
1640 return E_UNEXPECTED;
1642 /* Update the menu descriptor */
1643 pOleMenuDescriptor->hwndFrame = hwndFrame;
1644 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1646 GlobalUnlock( hOleMenu );
1647 pOleMenuDescriptor = NULL;
1649 /* Add a menu descriptor windows property to the frame window */
1650 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1652 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1653 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1656 else /* Want to uninstall dispatching code */
1658 /* Uninstall the hooks */
1659 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1662 /* Remove the menu descriptor property from the frame window */
1663 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1669 /******************************************************************************
1670 * IsAccelerator [OLE32.@]
1671 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1673 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1678 if(!lpMsg) return FALSE;
1681 WARN_(accel)("NULL accel handle\n");
1684 if((lpMsg->message != WM_KEYDOWN &&
1685 lpMsg->message != WM_KEYUP &&
1686 lpMsg->message != WM_SYSKEYDOWN &&
1687 lpMsg->message != WM_SYSKEYUP &&
1688 lpMsg->message != WM_CHAR)) return FALSE;
1689 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1690 if (NULL == lpAccelTbl)
1694 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1696 WARN_(accel)("CopyAcceleratorTableW failed\n");
1697 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1701 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1702 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1703 hAccel, cAccelEntries,
1704 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1705 for(i = 0; i < cAccelEntries; i++)
1707 if(lpAccelTbl[i].key != lpMsg->wParam)
1710 if(lpMsg->message == WM_CHAR)
1712 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1714 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1720 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1723 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1724 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1725 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1726 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1727 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1728 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1729 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1733 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1735 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1736 { /* ^^ ALT pressed */
1737 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1745 WARN_(accel)("couldn't translate accelerator key\n");
1746 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1750 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1751 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1755 /***********************************************************************
1756 * ReleaseStgMedium [OLE32.@]
1758 void WINAPI ReleaseStgMedium(
1761 switch (pmedium->tymed)
1765 if ( (pmedium->pUnkForRelease==0) &&
1766 (pmedium->u.hGlobal!=0) )
1767 GlobalFree(pmedium->u.hGlobal);
1772 if (pmedium->u.lpszFileName!=0)
1774 if (pmedium->pUnkForRelease==0)
1776 DeleteFileW(pmedium->u.lpszFileName);
1779 CoTaskMemFree(pmedium->u.lpszFileName);
1785 if (pmedium->u.pstm!=0)
1787 IStream_Release(pmedium->u.pstm);
1791 case TYMED_ISTORAGE:
1793 if (pmedium->u.pstg!=0)
1795 IStorage_Release(pmedium->u.pstg);
1801 if ( (pmedium->pUnkForRelease==0) &&
1802 (pmedium->u.hBitmap!=0) )
1803 DeleteObject(pmedium->u.hBitmap);
1808 if ( (pmedium->pUnkForRelease==0) &&
1809 (pmedium->u.hMetaFilePict!=0) )
1811 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1812 DeleteMetaFile(pMP->hMF);
1813 GlobalUnlock(pmedium->u.hMetaFilePict);
1814 GlobalFree(pmedium->u.hMetaFilePict);
1820 if ( (pmedium->pUnkForRelease==0) &&
1821 (pmedium->u.hEnhMetaFile!=0) )
1823 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1831 pmedium->tymed=TYMED_NULL;
1834 * After cleaning up, the unknown is released
1836 if (pmedium->pUnkForRelease!=0)
1838 IUnknown_Release(pmedium->pUnkForRelease);
1839 pmedium->pUnkForRelease = 0;
1844 * OLEDD_Initialize()
1846 * Initializes the OLE drag and drop data structures.
1848 static void OLEDD_Initialize(void)
1852 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1853 wndClass.style = CS_GLOBALCLASS;
1854 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1855 wndClass.cbClsExtra = 0;
1856 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1857 wndClass.hCursor = 0;
1858 wndClass.hbrBackground = 0;
1859 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1861 RegisterClassA (&wndClass);
1865 * OLEDD_FreeDropTarget()
1867 * Frees the drag and drop data structure
1869 static void OLEDD_FreeDropTarget(DropTargetNode *dropTargetInfo)
1871 list_remove(&dropTargetInfo->entry);
1872 IDropTarget_Release(dropTargetInfo->dropTarget);
1873 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
1877 * OLEDD_UnInitialize()
1879 * Releases the OLE drag and drop data structures.
1881 static void OLEDD_UnInitialize(void)
1884 * Simply empty the list.
1886 while (!list_empty(&targetListHead))
1888 DropTargetNode* curNode;
1889 curNode = LIST_ENTRY(list_head(&targetListHead), DropTargetNode, entry);
1890 OLEDD_FreeDropTarget(curNode);
1895 * OLEDD_FindDropTarget()
1897 * Finds information about the drop target.
1899 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1901 DropTargetNode* curNode;
1904 * Iterate the list to find the HWND value.
1906 LIST_FOR_EACH_ENTRY(curNode, &targetListHead, DropTargetNode, entry)
1907 if (hwndOfTarget==curNode->hwndTarget)
1911 * If we get here, the item is not in the list
1917 * OLEDD_DragTrackerWindowProc()
1919 * This method is the WindowProcedure of the drag n drop tracking
1920 * window. During a drag n Drop operation, an invisible window is created
1921 * to receive the user input and act upon it. This procedure is in charge
1925 #define DRAG_TIMER_ID 1
1927 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1937 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1939 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1940 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
1947 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
1953 case WM_LBUTTONDOWN:
1954 case WM_MBUTTONDOWN:
1955 case WM_RBUTTONDOWN:
1957 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
1962 KillTimer(hwnd, DRAG_TIMER_ID);
1968 * This is a window proc after all. Let's call the default.
1970 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1974 * OLEDD_TrackMouseMove()
1976 * This method is invoked while a drag and drop operation is in effect.
1977 * it will generate the appropriate callbacks in the drop source
1978 * and drop target. It will also provide the expected feedback to
1982 * trackerInfo - Pointer to the structure identifying the
1983 * drag & drop operation that is currently
1986 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
1988 HWND hwndNewTarget = 0;
1993 * Get the handle of the window under the mouse
1995 pt.x = trackerInfo->curMousePos.x;
1996 pt.y = trackerInfo->curMousePos.y;
1997 hwndNewTarget = WindowFromPoint(pt);
2000 * Every time, we re-initialize the effects passed to the
2001 * IDropTarget to the effects allowed by the source.
2003 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2006 * If we are hovering over the same target as before, send the
2007 * DragOver notification
2009 if ( (trackerInfo->curDragTarget != 0) &&
2010 (trackerInfo->curTargetHWND == hwndNewTarget) )
2012 IDropTarget_DragOver(trackerInfo->curDragTarget,
2013 trackerInfo->dwKeyState,
2014 trackerInfo->curMousePos,
2015 trackerInfo->pdwEffect);
2019 DropTargetNode* newDropTargetNode = 0;
2022 * If we changed window, we have to notify our old target and check for
2025 if (trackerInfo->curDragTarget!=0)
2027 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2031 * Make sure we're hovering over a window.
2033 if (hwndNewTarget!=0)
2036 * Find-out if there is a drag target under the mouse
2038 HWND nexttar = hwndNewTarget;
2039 trackerInfo->curTargetHWND = hwndNewTarget;
2042 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
2043 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
2044 if(nexttar) hwndNewTarget = nexttar;
2046 trackerInfo->curDragTargetHWND = hwndNewTarget;
2047 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
2050 * If there is, notify it that we just dragged-in
2052 if (trackerInfo->curDragTarget!=0)
2054 IDropTarget_DragEnter(trackerInfo->curDragTarget,
2055 trackerInfo->dataObject,
2056 trackerInfo->dwKeyState,
2057 trackerInfo->curMousePos,
2058 trackerInfo->pdwEffect);
2064 * The mouse is not over a window so we don't track anything.
2066 trackerInfo->curDragTargetHWND = 0;
2067 trackerInfo->curTargetHWND = 0;
2068 trackerInfo->curDragTarget = 0;
2073 * Now that we have done that, we have to tell the source to give
2074 * us feedback on the work being done by the target. If we don't
2075 * have a target, simulate no effect.
2077 if (trackerInfo->curDragTarget==0)
2079 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2082 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2083 *trackerInfo->pdwEffect);
2086 * When we ask for feedback from the drop source, sometimes it will
2087 * do all the necessary work and sometimes it will not handle it
2088 * when that's the case, we must display the standard drag and drop
2091 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2093 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2095 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2097 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2099 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2101 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2103 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2107 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2113 * OLEDD_TrackStateChange()
2115 * This method is invoked while a drag and drop operation is in effect.
2116 * It is used to notify the drop target/drop source callbacks when
2117 * the state of the keyboard or mouse button change.
2120 * trackerInfo - Pointer to the structure identifying the
2121 * drag & drop operation that is currently
2124 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2127 * Ask the drop source what to do with the operation.
2129 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2130 trackerInfo->dropSource,
2131 trackerInfo->escPressed,
2132 trackerInfo->dwKeyState);
2135 * All the return valued will stop the operation except the S_OK
2138 if (trackerInfo->returnValue!=S_OK)
2141 * Make sure the message loop in DoDragDrop stops
2143 trackerInfo->trackingDone = TRUE;
2146 * Release the mouse in case the drop target decides to show a popup
2147 * or a menu or something.
2152 * If we end-up over a target, drop the object in the target or
2153 * inform the target that the operation was cancelled.
2155 if (trackerInfo->curDragTarget!=0)
2157 switch (trackerInfo->returnValue)
2160 * If the source wants us to complete the operation, we tell
2161 * the drop target that we just dropped the object in it.
2163 case DRAGDROP_S_DROP:
2165 IDropTarget_Drop(trackerInfo->curDragTarget,
2166 trackerInfo->dataObject,
2167 trackerInfo->dwKeyState,
2168 trackerInfo->curMousePos,
2169 trackerInfo->pdwEffect);
2173 * If the source told us that we should cancel, fool the drop
2174 * target by telling it that the mouse left it's window.
2175 * Also set the drop effect to "NONE" in case the application
2176 * ignores the result of DoDragDrop.
2178 case DRAGDROP_S_CANCEL:
2179 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2180 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2188 * OLEDD_GetButtonState()
2190 * This method will use the current state of the keyboard to build
2191 * a button state mask equivalent to the one passed in the
2192 * WM_MOUSEMOVE wParam.
2194 static DWORD OLEDD_GetButtonState(void)
2196 BYTE keyboardState[256];
2199 GetKeyboardState(keyboardState);
2201 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2202 keyMask |= MK_SHIFT;
2204 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2205 keyMask |= MK_CONTROL;
2207 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2208 keyMask |= MK_LBUTTON;
2210 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2211 keyMask |= MK_RBUTTON;
2213 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2214 keyMask |= MK_MBUTTON;
2220 * OLEDD_GetButtonState()
2222 * This method will read the default value of the registry key in
2223 * parameter and extract a DWORD value from it. The registry key value
2224 * can be in a string key or a DWORD key.
2227 * regKey - Key to read the default value from
2228 * pdwValue - Pointer to the location where the DWORD
2229 * value is returned. This value is not modified
2230 * if the value is not found.
2233 static void OLEUTL_ReadRegistryDWORDValue(
2242 lres = RegQueryValueExA(regKey,
2249 if (lres==ERROR_SUCCESS)
2254 *pdwValue = *(DWORD*)buffer;
2259 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2265 /******************************************************************************
2268 * The operation of this function is documented literally in the WinAPI
2269 * documentation to involve a QueryInterface for the IViewObject interface,
2270 * followed by a call to IViewObject::Draw.
2272 HRESULT WINAPI OleDraw(
2279 IViewObject *viewobject;
2281 hres = IUnknown_QueryInterface(pUnk,
2283 (void**)&viewobject);
2285 if (SUCCEEDED(hres))
2289 rectl.left = lprcBounds->left;
2290 rectl.right = lprcBounds->right;
2291 rectl.top = lprcBounds->top;
2292 rectl.bottom = lprcBounds->bottom;
2293 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2295 IViewObject_Release(viewobject);
2300 return DV_E_NOIVIEWOBJECT;
2304 /***********************************************************************
2305 * OleTranslateAccelerator [OLE32.@]
2307 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2308 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2312 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2314 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2315 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2320 /******************************************************************************
2321 * OleCreate [OLE32.@]
2324 HRESULT WINAPI OleCreate(
2328 LPFORMATETC pFormatEtc,
2329 LPOLECLIENTSITE pClientSite,
2334 IUnknown * pUnk = NULL;
2335 IOleObject *pOleObject = NULL;
2337 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2339 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk);
2341 if (SUCCEEDED(hres))
2342 hres = IStorage_SetClass(pStg, rclsid);
2344 if (pClientSite && SUCCEEDED(hres))
2346 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2347 if (SUCCEEDED(hres))
2350 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2354 if (SUCCEEDED(hres))
2356 IPersistStorage * pPS;
2357 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2359 TRACE("trying to set stg %p\n", pStg);
2360 hres = IPersistStorage_InitNew(pPS, pStg);
2361 TRACE("-- result 0x%08lx\n", hres);
2362 IPersistStorage_Release(pPS);
2366 if (pClientSite && SUCCEEDED(hres))
2368 TRACE("trying to set clientsite %p\n", pClientSite);
2369 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2370 TRACE("-- result 0x%08lx\n", hres);
2374 IOleObject_Release(pOleObject);
2376 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2379 IRunnableObject *pRunnable;
2380 IOleCache *pOleCache;
2382 hres = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2383 if (SUCCEEDED(hres))
2385 hres = IRunnableObject_Run(pRunnable, NULL);
2386 IRunnableObject_Release(pRunnable);
2389 if (SUCCEEDED(hres))
2390 hres = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2391 if (SUCCEEDED(hres))
2394 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2395 IOleCache_Release(pOleCache);
2401 IUnknown_Release(pUnk);
2407 TRACE("-- %p\n", pUnk);
2411 /******************************************************************************
2412 * OleGetAutoConvert [OLE32.@]
2414 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2416 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2418 WCHAR buf[CHARS_IN_GUID];
2422 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2427 if (RegQueryValueW(hkey, NULL, buf, &len))
2429 res = REGDB_E_KEYMISSING;
2432 res = CLSIDFromString(buf, pClsidNew);
2434 if (hkey) RegCloseKey(hkey);
2438 /******************************************************************************
2439 * OleSetAutoConvert [OLE32.@]
2441 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2443 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2445 WCHAR szClsidNew[CHARS_IN_GUID];
2448 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2450 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2453 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2454 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2456 res = REGDB_E_WRITEREGDB;
2461 if (hkey) RegCloseKey(hkey);
2465 /******************************************************************************
2466 * OleDoAutoConvert [OLE32.@]
2468 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2470 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2474 /******************************************************************************
2475 * OleIsRunning [OLE32.@]
2477 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2479 IRunnableObject *pRunnable;
2483 TRACE("(%p)\n", pObject);
2485 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2488 running = IRunnableObject_IsRunning(pRunnable);
2489 IRunnableObject_Release(pRunnable);
2493 /***********************************************************************
2494 * OleNoteObjectVisible [OLE32.@]
2496 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2498 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2499 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2503 /***********************************************************************
2504 * OLE_FreeClipDataArray [internal]
2507 * frees the data associated with an array of CLIPDATAs
2509 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2512 for (i = 0; i < count; i++)
2513 if (pClipDataArray[i].pClipData)
2514 CoTaskMemFree(pClipDataArray[i].pClipData);
2517 /***********************************************************************
2518 * PropSysAllocString [OLE32.@]
2520 * Basically a copy of SysAllocStringLen.
2522 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2526 WCHAR* stringBuffer;
2531 len = lstrlenW(str);
2533 * Find the length of the buffer passed-in in bytes.
2535 bufferSize = len * sizeof (WCHAR);
2538 * Allocate a new buffer to hold the string.
2539 * don't forget to keep an empty spot at the beginning of the
2540 * buffer for the character count and an extra character at the
2543 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2544 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2547 * If the memory allocation failed, return a null pointer.
2553 * Copy the length of the string in the placeholder.
2555 *newBuffer = bufferSize;
2558 * Skip the byte count.
2563 * Copy the information in the buffer.
2564 * Since it is valid to pass a NULL pointer here, we'll initialize the
2565 * buffer to nul if it is the case.
2568 memcpy(newBuffer, str, bufferSize);
2570 memset(newBuffer, 0, bufferSize);
2573 * Make sure that there is a nul character at the end of the
2576 stringBuffer = (WCHAR*)newBuffer;
2577 stringBuffer[len] = L'\0';
2579 return (LPWSTR)stringBuffer;
2582 /***********************************************************************
2583 * PropSysFreeString [OLE32.@]
2585 * Copy of SysFreeString.
2587 void WINAPI PropSysFreeString(LPOLESTR str)
2589 DWORD* bufferPointer;
2591 /* NULL is a valid parameter */
2595 * We have to be careful when we free a BSTR pointer, it points to
2596 * the beginning of the string but it skips the byte count contained
2597 * before the string.
2599 bufferPointer = (DWORD*)str;
2604 * Free the memory from its "real" origin.
2606 HeapFree(GetProcessHeap(), 0, bufferPointer);
2609 /******************************************************************************
2610 * Check if a PROPVARIANT's type is valid.
2612 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2638 case VT_STREAMED_OBJECT:
2639 case VT_STORED_OBJECT:
2640 case VT_BLOB_OBJECT:
2643 case VT_I2|VT_VECTOR:
2644 case VT_I4|VT_VECTOR:
2645 case VT_R4|VT_VECTOR:
2646 case VT_R8|VT_VECTOR:
2647 case VT_CY|VT_VECTOR:
2648 case VT_DATE|VT_VECTOR:
2649 case VT_BSTR|VT_VECTOR:
2650 case VT_ERROR|VT_VECTOR:
2651 case VT_BOOL|VT_VECTOR:
2652 case VT_VARIANT|VT_VECTOR:
2653 case VT_UI1|VT_VECTOR:
2654 case VT_UI2|VT_VECTOR:
2655 case VT_UI4|VT_VECTOR:
2656 case VT_I8|VT_VECTOR:
2657 case VT_UI8|VT_VECTOR:
2658 case VT_LPSTR|VT_VECTOR:
2659 case VT_LPWSTR|VT_VECTOR:
2660 case VT_FILETIME|VT_VECTOR:
2661 case VT_CF|VT_VECTOR:
2662 case VT_CLSID|VT_VECTOR:
2665 WARN("Bad type %d\n", vt);
2666 return STG_E_INVALIDPARAMETER;
2669 /***********************************************************************
2670 * PropVariantClear [OLE32.@]
2672 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2676 TRACE("(%p)\n", pvar);
2681 hr = PROPVARIANT_ValidateType(pvar->vt);
2705 case VT_STREAMED_OBJECT:
2707 case VT_STORED_OBJECT:
2708 if (pvar->u.pStream)
2709 IUnknown_Release(pvar->u.pStream);
2714 /* pick an arbitary typed pointer - we don't care about the type
2715 * as we are just freeing it */
2716 CoTaskMemFree(pvar->u.puuid);
2719 case VT_BLOB_OBJECT:
2720 CoTaskMemFree(pvar->u.blob.pBlobData);
2723 if (pvar->u.bstrVal)
2724 PropSysFreeString(pvar->u.bstrVal);
2727 if (pvar->u.pclipdata)
2729 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2730 CoTaskMemFree(pvar->u.pclipdata);
2734 if (pvar->vt & VT_VECTOR)
2738 switch (pvar->vt & ~VT_VECTOR)
2741 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2744 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2747 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2748 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2751 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2752 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2755 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2756 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2759 if (pvar->vt & ~VT_VECTOR)
2761 /* pick an arbitary VT_VECTOR structure - they all have the same
2763 CoTaskMemFree(pvar->u.capropvar.pElems);
2767 WARN("Invalid/unsupported type %d\n", pvar->vt);
2770 ZeroMemory(pvar, sizeof(*pvar));
2775 /***********************************************************************
2776 * PropVariantCopy [OLE32.@]
2778 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2779 const PROPVARIANT *pvarSrc) /* [in] */
2784 TRACE("(%p, %p)\n", pvarDest, pvarSrc);
2786 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2790 /* this will deal with most cases */
2791 CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2798 case VT_STREAMED_OBJECT:
2800 case VT_STORED_OBJECT:
2801 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2804 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2805 CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2808 len = strlen(pvarSrc->u.pszVal);
2809 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2810 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2813 len = lstrlenW(pvarSrc->u.pwszVal);
2814 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2815 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2818 case VT_BLOB_OBJECT:
2819 if (pvarSrc->u.blob.pBlobData)
2821 len = pvarSrc->u.blob.cbSize;
2822 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2823 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2827 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2830 if (pvarSrc->u.pclipdata)
2832 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2833 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
2834 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
2835 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
2836 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
2837 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2841 if (pvarSrc->vt & VT_VECTOR)
2846 switch(pvarSrc->vt & ~VT_VECTOR)
2848 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2849 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2850 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2851 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2852 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2853 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2854 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2855 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2856 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2857 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2858 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2859 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2860 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2861 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2862 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2863 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2864 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2865 case VT_BSTR: elemSize = sizeof(*pvarSrc->u.bstrVal); break;
2866 case VT_LPSTR: elemSize = sizeof(*pvarSrc->u.pszVal); break;
2867 case VT_LPWSTR: elemSize = sizeof(*pvarSrc->u.pwszVal); break;
2871 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2872 return E_INVALIDARG;
2874 len = pvarSrc->u.capropvar.cElems;
2875 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2876 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2878 for (i = 0; i < len; i++)
2879 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2881 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2883 FIXME("Copy clipformats\n");
2885 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2887 for (i = 0; i < len; i++)
2888 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2890 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2893 for (i = 0; i < len; i++)
2895 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2896 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2897 memcpy(pvarDest->u.calpstr.pElems[i],
2898 pvarSrc->u.calpstr.pElems[i], strLen);
2901 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2904 for (i = 0; i < len; i++)
2906 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2908 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2909 memcpy(pvarDest->u.calpstr.pElems[i],
2910 pvarSrc->u.calpstr.pElems[i], strLen);
2914 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2917 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2923 /***********************************************************************
2924 * FreePropVariantArray [OLE32.@]
2926 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2927 PROPVARIANT *rgvars) /* [in/out] */
2931 TRACE("(%lu, %p)\n", cVariants, rgvars);
2934 return E_INVALIDARG;
2936 for(i = 0; i < cVariants; i++)
2937 PropVariantClear(&rgvars[i]);
2942 /******************************************************************************
2943 * DllDebugObjectRPCHook (OLE32.@)
2944 * turns on and off internal debugging, pointer is only used on macintosh
2947 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)