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
193 if (!COM_CurrentInfo()->ole_inits)
197 * Then, it has to initialize the OLE specific modules.
201 * Object linking and Embedding
202 * In-place activation
204 if (!COM_CurrentInfo()->ole_inits++ &&
205 InterlockedIncrement(&OLE_moduleLockCount) == 1)
208 * Initialize the libraries.
210 TRACE("() - Initializing the OLE libraries\n");
215 OLEClipbrd_Initialize();
225 OLEMenu_Initialize();
231 /******************************************************************************
232 * OleUninitialize [OLE32.@]
234 void WINAPI OleUninitialize(void)
239 * If we hit the bottom of the lock stack, free the libraries.
241 if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
244 * Actually free the libraries.
246 TRACE("() - Freeing the last reference count\n");
251 OLEClipbrd_UnInitialize();
256 OLEMenu_UnInitialize();
260 * Then, uninitialize the COM libraries.
265 /******************************************************************************
266 * OleInitializeWOW [OLE32.@]
268 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
269 FIXME("(0x%08x, 0x%08x),stub!\n",x, y);
273 /***********************************************************************
274 * RegisterDragDrop (OLE32.@)
276 HRESULT WINAPI RegisterDragDrop(
278 LPDROPTARGET pDropTarget)
280 DropTargetNode* dropTargetInfo;
282 TRACE("(%p,%p)\n", hwnd, pDropTarget);
284 if (!COM_CurrentApt())
286 ERR("COM not initialized\n");
287 return E_OUTOFMEMORY;
295 ERR("invalid hwnd %p\n", hwnd);
296 return DRAGDROP_E_INVALIDHWND;
300 * First, check if the window is already registered.
302 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
304 if (dropTargetInfo!=NULL)
305 return DRAGDROP_E_ALREADYREGISTERED;
308 * If it's not there, we can add it. We first create a node for it.
310 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
312 if (dropTargetInfo==NULL)
313 return E_OUTOFMEMORY;
315 dropTargetInfo->hwndTarget = hwnd;
318 * Don't forget that this is an interface pointer, need to nail it down since
319 * we keep a copy of it.
321 IDropTarget_AddRef(pDropTarget);
322 dropTargetInfo->dropTarget = pDropTarget;
324 list_add_tail(&targetListHead, &dropTargetInfo->entry);
329 /***********************************************************************
330 * RevokeDragDrop (OLE32.@)
332 HRESULT WINAPI RevokeDragDrop(
335 DropTargetNode* dropTargetInfo;
337 TRACE("(%p)\n", hwnd);
341 ERR("invalid hwnd %p\n", hwnd);
342 return DRAGDROP_E_INVALIDHWND;
346 * First, check if the window is already registered.
348 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
351 * If it ain't in there, it's an error.
353 if (dropTargetInfo==NULL)
354 return DRAGDROP_E_NOTREGISTERED;
356 OLEDD_FreeDropTarget(dropTargetInfo, TRUE);
361 /***********************************************************************
362 * OleRegGetUserType (OLE32.@)
364 * This implementation of OleRegGetUserType ignores the dwFormOfType
365 * parameter and always returns the full name of the object. This is
366 * not too bad since this is the case for many objects because of the
367 * way they are registered.
369 HRESULT WINAPI OleRegGetUserType(
372 LPOLESTR* pszUserType)
382 * Initialize the out parameter.
387 * Build the key name we're looking for
389 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
390 clsid->Data1, clsid->Data2, clsid->Data3,
391 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
392 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
394 TRACE("(%s, %d, %p)\n", keyName, dwFormOfType, pszUserType);
397 * Open the class id Key
399 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
403 if (hres != ERROR_SUCCESS)
404 return REGDB_E_CLASSNOTREG;
407 * Retrieve the size of the name string.
411 hres = RegQueryValueExA(clsidKey,
418 if (hres!=ERROR_SUCCESS)
420 RegCloseKey(clsidKey);
421 return REGDB_E_READREGDB;
425 * Allocate a buffer for the registry value.
427 *pszUserType = CoTaskMemAlloc(cbData*2);
429 if (*pszUserType==NULL)
431 RegCloseKey(clsidKey);
432 return E_OUTOFMEMORY;
435 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
439 RegCloseKey(clsidKey);
440 CoTaskMemFree(*pszUserType);
442 return E_OUTOFMEMORY;
445 hres = RegQueryValueExA(clsidKey,
452 RegCloseKey(clsidKey);
455 if (hres!=ERROR_SUCCESS)
457 CoTaskMemFree(*pszUserType);
460 retVal = REGDB_E_READREGDB;
464 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
467 HeapFree(GetProcessHeap(), 0, buffer);
472 /***********************************************************************
473 * DoDragDrop [OLE32.@]
475 HRESULT WINAPI DoDragDrop (
476 IDataObject *pDataObject, /* [in] ptr to the data obj */
477 IDropSource* pDropSource, /* [in] ptr to the source obj */
478 DWORD dwOKEffect, /* [in] effects allowed by the source */
479 DWORD *pdwEffect) /* [out] ptr to effects of the source */
481 TrackerWindowInfo trackerInfo;
482 HWND hwndTrackWindow;
485 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
488 * Setup the drag n drop tracking window.
490 if (!IsValidInterface((LPUNKNOWN)pDropSource))
493 trackerInfo.dataObject = pDataObject;
494 trackerInfo.dropSource = pDropSource;
495 trackerInfo.dwOKEffect = dwOKEffect;
496 trackerInfo.pdwEffect = pdwEffect;
497 trackerInfo.trackingDone = FALSE;
498 trackerInfo.escPressed = FALSE;
499 trackerInfo.curDragTargetHWND = 0;
500 trackerInfo.curTargetHWND = 0;
501 trackerInfo.curDragTarget = 0;
503 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS, "TrackerWindow",
504 WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
505 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
508 if (hwndTrackWindow!=0)
511 * Capture the mouse input
513 SetCapture(hwndTrackWindow);
518 * Pump messages. All mouse input should go to the capture window.
520 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
522 trackerInfo.curMousePos.x = msg.pt.x;
523 trackerInfo.curMousePos.y = msg.pt.y;
524 trackerInfo.dwKeyState = OLEDD_GetButtonState();
526 if ( (msg.message >= WM_KEYFIRST) &&
527 (msg.message <= WM_KEYLAST) )
530 * When keyboard messages are sent to windows on this thread, we
531 * want to ignore notify the drop source that the state changed.
532 * in the case of the Escape key, we also notify the drop source
533 * we give it a special meaning.
535 if ( (msg.message==WM_KEYDOWN) &&
536 (msg.wParam==VK_ESCAPE) )
538 trackerInfo.escPressed = TRUE;
542 * Notify the drop source.
544 OLEDD_TrackStateChange(&trackerInfo);
549 * Dispatch the messages only when it's not a keyboard message.
551 DispatchMessageA(&msg);
555 /* re-post the quit message to outer message loop */
556 if (msg.message == WM_QUIT)
557 PostQuitMessage(msg.wParam);
559 * Destroy the temporary window.
561 DestroyWindow(hwndTrackWindow);
563 return trackerInfo.returnValue;
569 /***********************************************************************
570 * OleQueryLinkFromData [OLE32.@]
572 HRESULT WINAPI OleQueryLinkFromData(
573 IDataObject* pSrcDataObject)
575 FIXME("(%p),stub!\n", pSrcDataObject);
579 /***********************************************************************
580 * OleRegGetMiscStatus [OLE32.@]
582 HRESULT WINAPI OleRegGetMiscStatus(
594 * Initialize the out parameter.
599 * Build the key name we're looking for
601 sprintf( keyName, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
602 clsid->Data1, clsid->Data2, clsid->Data3,
603 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
604 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
606 TRACE("(%s, %d, %p)\n", keyName, dwAspect, pdwStatus);
609 * Open the class id Key
611 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
615 if (result != ERROR_SUCCESS)
616 return REGDB_E_CLASSNOTREG;
621 result = RegOpenKeyA(clsidKey,
626 if (result != ERROR_SUCCESS)
628 RegCloseKey(clsidKey);
629 return REGDB_E_READREGDB;
633 * Read the default value
635 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
638 * Open the key specific to the requested aspect.
640 sprintf(keyName, "%d", dwAspect);
642 result = RegOpenKeyA(miscStatusKey,
646 if (result == ERROR_SUCCESS)
648 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
649 RegCloseKey(aspectKey);
655 RegCloseKey(miscStatusKey);
656 RegCloseKey(clsidKey);
661 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
665 const IEnumOLEVERBVtbl *lpvtbl;
672 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
673 IEnumOLEVERB *iface, REFIID riid, void **ppv)
675 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
676 if (IsEqualIID(riid, &IID_IUnknown) ||
677 IsEqualIID(riid, &IID_IEnumOLEVERB))
679 IUnknown_AddRef(iface);
683 return E_NOINTERFACE;
686 static ULONG WINAPI EnumOLEVERB_AddRef(
689 EnumOLEVERB *This = (EnumOLEVERB *)iface;
691 return InterlockedIncrement(&This->ref);
694 static ULONG WINAPI EnumOLEVERB_Release(
697 EnumOLEVERB *This = (EnumOLEVERB *)iface;
698 LONG refs = InterlockedDecrement(&This->ref);
702 RegCloseKey(This->hkeyVerb);
703 HeapFree(GetProcessHeap(), 0, This);
708 static HRESULT WINAPI EnumOLEVERB_Next(
709 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
712 EnumOLEVERB *This = (EnumOLEVERB *)iface;
715 TRACE("(%d, %p, %p)\n", celt, rgelt, pceltFetched);
720 for (; celt; celt--, rgelt++)
725 LPWSTR pwszMenuFlags;
727 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
728 if (res == ERROR_NO_MORE_ITEMS)
733 else if (res != ERROR_SUCCESS)
735 ERR("RegEnumKeyW failed with error %d\n", res);
736 hr = REGDB_E_READREGDB;
739 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
740 if (res != ERROR_SUCCESS)
742 ERR("RegQueryValueW failed with error %d\n", res);
743 hr = REGDB_E_READREGDB;
746 pwszOLEVERB = CoTaskMemAlloc(cbData);
752 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
753 if (res != ERROR_SUCCESS)
755 ERR("RegQueryValueW failed with error %d\n", res);
756 hr = REGDB_E_READREGDB;
757 CoTaskMemFree(pwszOLEVERB);
761 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
762 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
765 hr = OLEOBJ_E_INVALIDVERB;
766 CoTaskMemFree(pwszOLEVERB);
769 /* nul terminate the name string and advance to first character */
770 *pwszMenuFlags = '\0';
772 pwszAttribs = strchrW(pwszMenuFlags, ',');
775 hr = OLEOBJ_E_INVALIDVERB;
776 CoTaskMemFree(pwszOLEVERB);
779 /* nul terminate the menu string and advance to first character */
783 /* fill out structure for this verb */
784 rgelt->lVerb = atolW(wszSubKey);
785 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
786 rgelt->fuFlags = atolW(pwszMenuFlags);
787 rgelt->grfAttribs = atolW(pwszAttribs);
796 static HRESULT WINAPI EnumOLEVERB_Skip(
797 IEnumOLEVERB *iface, ULONG celt)
799 EnumOLEVERB *This = (EnumOLEVERB *)iface;
801 TRACE("(%d)\n", celt);
807 static HRESULT WINAPI EnumOLEVERB_Reset(
810 EnumOLEVERB *This = (EnumOLEVERB *)iface;
818 static HRESULT WINAPI EnumOLEVERB_Clone(
820 IEnumOLEVERB **ppenum)
822 EnumOLEVERB *This = (EnumOLEVERB *)iface;
824 TRACE("(%p)\n", ppenum);
825 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
826 return HRESULT_FROM_WIN32(GetLastError());
827 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
830 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
832 EnumOLEVERB_QueryInterface,
841 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
843 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
846 RegCloseKey(hkeyVerb);
847 return E_OUTOFMEMORY;
849 This->lpvtbl = &EnumOLEVERB_VTable;
852 This->hkeyVerb = hkeyVerb;
853 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
857 /***********************************************************************
858 * OleRegEnumVerbs [OLE32.@]
860 * Enumerates verbs associated with a class stored in the registry.
863 * clsid [I] Class ID to enumerate the verbs for.
864 * ppenum [O] Enumerator.
868 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
869 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
870 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
871 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
873 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
878 static const WCHAR wszVerb[] = {'V','e','r','b',0};
880 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
882 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
885 if (res == REGDB_E_CLASSNOTREG)
886 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
887 else if (res == REGDB_E_KEYMISSING)
888 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
890 ERR("failed to open Verbs key for CLSID %s with error %d\n",
891 debugstr_guid(clsid), res);
895 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
896 NULL, NULL, NULL, NULL, NULL, NULL);
897 if (res != ERROR_SUCCESS)
899 ERR("failed to get subkey count with error %d\n", GetLastError());
900 return REGDB_E_READREGDB;
905 WARN("class %s has no verbs\n", debugstr_guid(clsid));
906 RegCloseKey(hkeyVerb);
907 return OLEOBJ_E_NOVERBS;
910 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
913 /******************************************************************************
914 * OleSetContainedObject [OLE32.@]
916 HRESULT WINAPI OleSetContainedObject(
920 IRunnableObject* runnable = NULL;
923 TRACE("(%p,%x)\n", pUnknown, fContained);
925 hres = IUnknown_QueryInterface(pUnknown,
926 &IID_IRunnableObject,
931 hres = IRunnableObject_SetContainedObject(runnable, fContained);
933 IRunnableObject_Release(runnable);
941 /******************************************************************************
944 * Set the OLE object to the running state.
947 * pUnknown [I] OLE object to run.
951 * Failure: Any HRESULT code.
953 HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
955 IRunnableObject *runable;
958 TRACE("(%p)\n", pUnknown);
960 hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
962 return S_OK; /* Appears to return no error. */
964 hres = IRunnableObject_Run(runable, NULL);
965 IRunnableObject_Release(runable);
969 /******************************************************************************
972 HRESULT WINAPI OleLoad(
975 LPOLECLIENTSITE pClientSite,
978 IPersistStorage* persistStorage = NULL;
980 IOleObject* pOleObject = NULL;
984 TRACE("(%p, %s, %p, %p)\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
989 * TODO, Conversion ... OleDoAutoConvert
993 * Get the class ID for the object.
995 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
998 * Now, try and create the handler for the object
1000 hres = CoCreateInstance(&storageInfo.clsid,
1002 CLSCTX_INPROC_HANDLER|CLSCTX_INPROC_SERVER,
1007 * If that fails, as it will most times, load the default
1012 hres = OleCreateDefaultHandler(&storageInfo.clsid,
1019 * If we couldn't find a handler... this is bad. Abort the whole thing.
1026 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1027 if (SUCCEEDED(hres))
1030 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1034 if (SUCCEEDED(hres))
1036 * Initialize the object with it's IPersistStorage interface.
1038 hres = IOleObject_QueryInterface(pUnk,
1039 &IID_IPersistStorage,
1040 (void**)&persistStorage);
1042 if (SUCCEEDED(hres))
1044 hres = IPersistStorage_Load(persistStorage, pStg);
1046 IPersistStorage_Release(persistStorage);
1047 persistStorage = NULL;
1050 if (SUCCEEDED(hres) && pClientSite)
1052 * Inform the new object of it's client site.
1054 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1057 * Cleanup interfaces used internally
1060 IOleObject_Release(pOleObject);
1062 if (SUCCEEDED(hres))
1066 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1067 if (SUCCEEDED(hres1))
1069 FIXME("handle OLE link\n");
1070 IOleLink_Release(pOleLink);
1076 IUnknown_Release(pUnk);
1085 /***********************************************************************
1088 HRESULT WINAPI OleSave(
1089 LPPERSISTSTORAGE pPS,
1096 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1099 * First, we transfer the class ID (if available)
1101 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1103 if (SUCCEEDED(hres))
1105 WriteClassStg(pStg, &objectClass);
1109 * Then, we ask the object to save itself to the
1110 * storage. If it is successful, we commit the storage.
1112 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1114 if (SUCCEEDED(hres))
1116 IStorage_Commit(pStg,
1124 /******************************************************************************
1125 * OleLockRunning [OLE32.@]
1127 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1129 IRunnableObject* runnable = NULL;
1132 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1134 hres = IUnknown_QueryInterface(pUnknown,
1135 &IID_IRunnableObject,
1138 if (SUCCEEDED(hres))
1140 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1142 IRunnableObject_Release(runnable);
1151 /**************************************************************************
1152 * Internal methods to manage the shared OLE menu in response to the
1153 * OLE***MenuDescriptor API
1157 * OLEMenu_Initialize()
1159 * Initializes the OLEMENU data structures.
1161 static void OLEMenu_Initialize(void)
1166 * OLEMenu_UnInitialize()
1168 * Releases the OLEMENU data structures.
1170 static void OLEMenu_UnInitialize(void)
1174 /*************************************************************************
1175 * OLEMenu_InstallHooks
1176 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1178 * RETURNS: TRUE if message hooks were successfully installed
1181 static BOOL OLEMenu_InstallHooks( DWORD tid )
1183 OleMenuHookItem *pHookItem = NULL;
1185 /* Create an entry for the hook table */
1186 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1187 sizeof(OleMenuHookItem)) ) )
1190 pHookItem->tid = tid;
1191 pHookItem->hHeap = GetProcessHeap();
1193 /* Install a thread scope message hook for WH_GETMESSAGE */
1194 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1195 0, GetCurrentThreadId() );
1196 if ( !pHookItem->GetMsg_hHook )
1199 /* Install a thread scope message hook for WH_CALLWNDPROC */
1200 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1201 0, GetCurrentThreadId() );
1202 if ( !pHookItem->CallWndProc_hHook )
1205 /* Insert the hook table entry */
1206 pHookItem->next = hook_list;
1207 hook_list = pHookItem;
1212 /* Unhook any hooks */
1213 if ( pHookItem->GetMsg_hHook )
1214 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1215 if ( pHookItem->CallWndProc_hHook )
1216 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1217 /* Release the hook table entry */
1218 HeapFree(pHookItem->hHeap, 0, pHookItem );
1223 /*************************************************************************
1224 * OLEMenu_UnInstallHooks
1225 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1227 * RETURNS: TRUE if message hooks were successfully installed
1230 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1232 OleMenuHookItem *pHookItem = NULL;
1233 OleMenuHookItem **ppHook = &hook_list;
1237 if ((*ppHook)->tid == tid)
1239 pHookItem = *ppHook;
1240 *ppHook = pHookItem->next;
1243 ppHook = &(*ppHook)->next;
1245 if (!pHookItem) return FALSE;
1247 /* Uninstall the hooks installed for this thread */
1248 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1250 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1253 /* Release the hook table entry */
1254 HeapFree(pHookItem->hHeap, 0, pHookItem );
1259 /* Release the hook table entry */
1260 HeapFree(pHookItem->hHeap, 0, pHookItem );
1265 /*************************************************************************
1266 * OLEMenu_IsHookInstalled
1267 * Tests if OLEMenu hooks have been installed for a thread
1269 * RETURNS: The pointer and index of the hook table entry for the tid
1270 * NULL and -1 for the index if no hooks were installed for this thread
1272 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1274 OleMenuHookItem *pHookItem = NULL;
1276 /* Do a simple linear search for an entry whose tid matches ours.
1277 * We really need a map but efficiency is not a concern here. */
1278 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1280 if ( tid == pHookItem->tid )
1287 /***********************************************************************
1288 * OLEMenu_FindMainMenuIndex
1290 * Used by OLEMenu API to find the top level group a menu item belongs to.
1291 * On success pnPos contains the index of the item in the top level menu group
1293 * RETURNS: TRUE if the ID was found, FALSE on failure
1295 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1299 nItems = GetMenuItemCount( hMainMenu );
1301 for (i = 0; i < nItems; i++)
1305 /* Is the current item a submenu? */
1306 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1308 /* If the handle is the same we're done */
1309 if ( hsubmenu == hPopupMenu )
1315 /* Recursively search without updating pnPos */
1316 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1328 /***********************************************************************
1329 * OLEMenu_SetIsServerMenu
1331 * Checks whether a popup menu belongs to a shared menu group which is
1332 * owned by the server, and sets the menu descriptor state accordingly.
1333 * All menu messages from these groups should be routed to the server.
1335 * RETURNS: TRUE if the popup menu is part of a server owned group
1336 * FALSE if the popup menu is part of a container owned group
1338 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1340 UINT nPos = 0, nWidth, i;
1342 pOleMenuDescriptor->bIsServerItem = FALSE;
1344 /* Don't bother searching if the popup is the combined menu itself */
1345 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1348 /* Find the menu item index in the shared OLE menu that this item belongs to */
1349 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1352 /* The group widths array has counts for the number of elements
1353 * in the groups File, Edit, Container, Object, Window, Help.
1354 * The Edit, Object & Help groups belong to the server object
1355 * and the other three belong to the container.
1356 * Loop through the group widths and locate the group we are a member of.
1358 for ( i = 0, nWidth = 0; i < 6; i++ )
1360 nWidth += pOleMenuDescriptor->mgw.width[i];
1361 if ( nPos < nWidth )
1363 /* Odd elements are server menu widths */
1364 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1369 return pOleMenuDescriptor->bIsServerItem;
1372 /*************************************************************************
1373 * OLEMenu_CallWndProc
1374 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1375 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1377 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1379 LPCWPSTRUCT pMsg = NULL;
1380 HOLEMENU hOleMenu = 0;
1381 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1382 OleMenuHookItem *pHookItem = NULL;
1385 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1387 /* Check if we're being asked to process the message */
1388 if ( HC_ACTION != code )
1391 /* Retrieve the current message being dispatched from lParam */
1392 pMsg = (LPCWPSTRUCT)lParam;
1394 /* Check if the message is destined for a window we are interested in:
1395 * If the window has an OLEMenu property we may need to dispatch
1396 * the menu message to its active objects window instead. */
1398 hOleMenu = GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1402 /* Get the menu descriptor */
1403 pOleMenuDescriptor = GlobalLock( hOleMenu );
1404 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1407 /* Process menu messages */
1408 switch( pMsg->message )
1412 /* Reset the menu descriptor state */
1413 pOleMenuDescriptor->bIsServerItem = FALSE;
1415 /* Send this message to the server as well */
1416 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1417 pMsg->message, pMsg->wParam, pMsg->lParam );
1421 case WM_INITMENUPOPUP:
1423 /* Save the state for whether this is a server owned menu */
1424 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1430 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1431 if ( fuFlags & MF_SYSMENU )
1434 /* Save the state for whether this is a server owned popup menu */
1435 else if ( fuFlags & MF_POPUP )
1436 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1443 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1444 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1445 goto NEXTHOOK; /* Not a menu message */
1454 /* If the message was for the server dispatch it accordingly */
1455 if ( pOleMenuDescriptor->bIsServerItem )
1457 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1458 pMsg->message, pMsg->wParam, pMsg->lParam );
1462 if ( pOleMenuDescriptor )
1463 GlobalUnlock( hOleMenu );
1465 /* Lookup the hook item for the current thread */
1466 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1468 /* This should never fail!! */
1469 WARN("could not retrieve hHook for current thread!\n" );
1473 /* Pass on the message to the next hooker */
1474 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1477 /*************************************************************************
1478 * OLEMenu_GetMsgProc
1479 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1480 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1482 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1485 HOLEMENU hOleMenu = 0;
1486 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1487 OleMenuHookItem *pHookItem = NULL;
1490 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1492 /* Check if we're being asked to process a messages */
1493 if ( HC_ACTION != code )
1496 /* Retrieve the current message being dispatched from lParam */
1497 pMsg = (LPMSG)lParam;
1499 /* Check if the message is destined for a window we are interested in:
1500 * If the window has an OLEMenu property we may need to dispatch
1501 * the menu message to its active objects window instead. */
1503 hOleMenu = GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1507 /* Process menu messages */
1508 switch( pMsg->message )
1512 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1514 goto NEXTHOOK; /* Not a menu message */
1521 /* Get the menu descriptor */
1522 pOleMenuDescriptor = GlobalLock( hOleMenu );
1523 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1526 /* If the message was for the server dispatch it accordingly */
1527 if ( pOleMenuDescriptor->bIsServerItem )
1529 /* Change the hWnd in the message to the active objects hWnd.
1530 * The message loop which reads this message will automatically
1531 * dispatch it to the embedded objects window. */
1532 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1536 if ( pOleMenuDescriptor )
1537 GlobalUnlock( hOleMenu );
1539 /* Lookup the hook item for the current thread */
1540 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1542 /* This should never fail!! */
1543 WARN("could not retrieve hHook for current thread!\n" );
1547 /* Pass on the message to the next hooker */
1548 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1551 /***********************************************************************
1552 * OleCreateMenuDescriptor [OLE32.@]
1553 * Creates an OLE menu descriptor for OLE to use when dispatching
1554 * menu messages and commands.
1557 * hmenuCombined - Handle to the objects combined menu
1558 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1561 HOLEMENU WINAPI OleCreateMenuDescriptor(
1562 HMENU hmenuCombined,
1563 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1566 OleMenuDescriptor *pOleMenuDescriptor;
1569 if ( !hmenuCombined || !lpMenuWidths )
1572 /* Create an OLE menu descriptor */
1573 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1574 sizeof(OleMenuDescriptor) ) ) )
1577 pOleMenuDescriptor = GlobalLock( hOleMenu );
1578 if ( !pOleMenuDescriptor )
1581 /* Initialize menu group widths and hmenu */
1582 for ( i = 0; i < 6; i++ )
1583 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1585 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1586 pOleMenuDescriptor->bIsServerItem = FALSE;
1587 GlobalUnlock( hOleMenu );
1592 /***********************************************************************
1593 * OleDestroyMenuDescriptor [OLE32.@]
1594 * Destroy the shared menu descriptor
1596 HRESULT WINAPI OleDestroyMenuDescriptor(
1597 HOLEMENU hmenuDescriptor)
1599 if ( hmenuDescriptor )
1600 GlobalFree( hmenuDescriptor );
1604 /***********************************************************************
1605 * OleSetMenuDescriptor [OLE32.@]
1606 * Installs or removes OLE dispatching code for the containers frame window.
1609 * hOleMenu Handle to composite menu descriptor
1610 * hwndFrame Handle to containers frame window
1611 * hwndActiveObject Handle to objects in-place activation window
1612 * lpFrame Pointer to IOleInPlaceFrame on containers window
1613 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1616 * S_OK - menu installed correctly
1617 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1620 * The lpFrame and lpActiveObject parameters are currently ignored
1621 * OLE should install context sensitive help F1 filtering for the app when
1622 * these are non null.
1624 HRESULT WINAPI OleSetMenuDescriptor(
1627 HWND hwndActiveObject,
1628 LPOLEINPLACEFRAME lpFrame,
1629 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1631 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1634 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1635 return E_INVALIDARG;
1637 if ( lpFrame || lpActiveObject )
1639 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1647 /* Set up a message hook to intercept the containers frame window messages.
1648 * The message filter is responsible for dispatching menu messages from the
1649 * shared menu which are intended for the object.
1652 if ( hOleMenu ) /* Want to install dispatching code */
1654 /* If OLEMenu hooks are already installed for this thread, fail
1655 * Note: This effectively means that OleSetMenuDescriptor cannot
1656 * be called twice in succession on the same frame window
1657 * without first calling it with a null hOleMenu to uninstall */
1658 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1661 /* Get the menu descriptor */
1662 pOleMenuDescriptor = GlobalLock( hOleMenu );
1663 if ( !pOleMenuDescriptor )
1664 return E_UNEXPECTED;
1666 /* Update the menu descriptor */
1667 pOleMenuDescriptor->hwndFrame = hwndFrame;
1668 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1670 GlobalUnlock( hOleMenu );
1671 pOleMenuDescriptor = NULL;
1673 /* Add a menu descriptor windows property to the frame window */
1674 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1676 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1677 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1680 else /* Want to uninstall dispatching code */
1682 /* Uninstall the hooks */
1683 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1686 /* Remove the menu descriptor property from the frame window */
1687 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1693 /******************************************************************************
1694 * IsAccelerator [OLE32.@]
1695 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1697 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1702 if(!lpMsg) return FALSE;
1705 WARN_(accel)("NULL accel handle\n");
1708 if((lpMsg->message != WM_KEYDOWN &&
1709 lpMsg->message != WM_SYSKEYDOWN &&
1710 lpMsg->message != WM_SYSCHAR &&
1711 lpMsg->message != WM_CHAR)) return FALSE;
1712 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1713 if (NULL == lpAccelTbl)
1717 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1719 WARN_(accel)("CopyAcceleratorTableW failed\n");
1720 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1724 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1725 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1726 hAccel, cAccelEntries,
1727 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1728 for(i = 0; i < cAccelEntries; i++)
1730 if(lpAccelTbl[i].key != lpMsg->wParam)
1733 if(lpMsg->message == WM_CHAR)
1735 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1737 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg->wParam) & 0xff);
1743 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1746 TRACE_(accel)("found accel for virt_key %04lx (scan %04x)\n",
1747 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1748 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1749 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1750 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1751 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1752 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1756 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1758 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1759 { /* ^^ ALT pressed */
1760 TRACE_(accel)("found accel for Alt-%c\n", LOWORD(lpMsg->wParam) & 0xff);
1768 WARN_(accel)("couldn't translate accelerator key\n");
1769 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1773 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1774 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1778 /***********************************************************************
1779 * ReleaseStgMedium [OLE32.@]
1781 void WINAPI ReleaseStgMedium(
1784 switch (pmedium->tymed)
1788 if ( (pmedium->pUnkForRelease==0) &&
1789 (pmedium->u.hGlobal!=0) )
1790 GlobalFree(pmedium->u.hGlobal);
1795 if (pmedium->u.lpszFileName!=0)
1797 if (pmedium->pUnkForRelease==0)
1799 DeleteFileW(pmedium->u.lpszFileName);
1802 CoTaskMemFree(pmedium->u.lpszFileName);
1808 if (pmedium->u.pstm!=0)
1810 IStream_Release(pmedium->u.pstm);
1814 case TYMED_ISTORAGE:
1816 if (pmedium->u.pstg!=0)
1818 IStorage_Release(pmedium->u.pstg);
1824 if ( (pmedium->pUnkForRelease==0) &&
1825 (pmedium->u.hBitmap!=0) )
1826 DeleteObject(pmedium->u.hBitmap);
1831 if ( (pmedium->pUnkForRelease==0) &&
1832 (pmedium->u.hMetaFilePict!=0) )
1834 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1835 DeleteMetaFile(pMP->hMF);
1836 GlobalUnlock(pmedium->u.hMetaFilePict);
1837 GlobalFree(pmedium->u.hMetaFilePict);
1843 if ( (pmedium->pUnkForRelease==0) &&
1844 (pmedium->u.hEnhMetaFile!=0) )
1846 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1854 pmedium->tymed=TYMED_NULL;
1857 * After cleaning up, the unknown is released
1859 if (pmedium->pUnkForRelease!=0)
1861 IUnknown_Release(pmedium->pUnkForRelease);
1862 pmedium->pUnkForRelease = 0;
1867 * OLEDD_Initialize()
1869 * Initializes the OLE drag and drop data structures.
1871 static void OLEDD_Initialize(void)
1875 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1876 wndClass.style = CS_GLOBALCLASS;
1877 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1878 wndClass.cbClsExtra = 0;
1879 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1880 wndClass.hCursor = 0;
1881 wndClass.hbrBackground = 0;
1882 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1884 RegisterClassA (&wndClass);
1888 * OLEDD_FreeDropTarget()
1890 * Frees the drag and drop data structure
1892 static void OLEDD_FreeDropTarget(DropTargetNode *dropTargetInfo, BOOL release_drop_target)
1894 list_remove(&dropTargetInfo->entry);
1895 if (release_drop_target) IDropTarget_Release(dropTargetInfo->dropTarget);
1896 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
1900 * OLEDD_UnInitialize()
1902 * Releases the OLE drag and drop data structures.
1904 void OLEDD_UnInitialize(void)
1907 * Simply empty the list.
1909 while (!list_empty(&targetListHead))
1911 DropTargetNode* curNode = LIST_ENTRY(list_head(&targetListHead), DropTargetNode, entry);
1912 OLEDD_FreeDropTarget(curNode, FALSE);
1917 * OLEDD_FindDropTarget()
1919 * Finds information about the drop target.
1921 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1923 DropTargetNode* curNode;
1926 * Iterate the list to find the HWND value.
1928 LIST_FOR_EACH_ENTRY(curNode, &targetListHead, DropTargetNode, entry)
1929 if (hwndOfTarget==curNode->hwndTarget)
1933 * If we get here, the item is not in the list
1939 * OLEDD_DragTrackerWindowProc()
1941 * This method is the WindowProcedure of the drag n drop tracking
1942 * window. During a drag n Drop operation, an invisible window is created
1943 * to receive the user input and act upon it. This procedure is in charge
1947 #define DRAG_TIMER_ID 1
1949 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1959 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1961 SetWindowLongPtrA(hwnd, 0, (LONG_PTR)createStruct->lpCreateParams);
1962 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
1969 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1975 case WM_LBUTTONDOWN:
1976 case WM_MBUTTONDOWN:
1977 case WM_RBUTTONDOWN:
1979 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1984 KillTimer(hwnd, DRAG_TIMER_ID);
1990 * This is a window proc after all. Let's call the default.
1992 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1996 * OLEDD_TrackMouseMove()
1998 * This method is invoked while a drag and drop operation is in effect.
1999 * it will generate the appropriate callbacks in the drop source
2000 * and drop target. It will also provide the expected feedback to
2004 * trackerInfo - Pointer to the structure identifying the
2005 * drag & drop operation that is currently
2008 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
2010 HWND hwndNewTarget = 0;
2015 * Get the handle of the window under the mouse
2017 pt.x = trackerInfo->curMousePos.x;
2018 pt.y = trackerInfo->curMousePos.y;
2019 hwndNewTarget = WindowFromPoint(pt);
2022 * Every time, we re-initialize the effects passed to the
2023 * IDropTarget to the effects allowed by the source.
2025 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2028 * If we are hovering over the same target as before, send the
2029 * DragOver notification
2031 if ( (trackerInfo->curDragTarget != 0) &&
2032 (trackerInfo->curTargetHWND == hwndNewTarget) )
2034 IDropTarget_DragOver(trackerInfo->curDragTarget,
2035 trackerInfo->dwKeyState,
2036 trackerInfo->curMousePos,
2037 trackerInfo->pdwEffect);
2041 DropTargetNode* newDropTargetNode = 0;
2044 * If we changed window, we have to notify our old target and check for
2047 if (trackerInfo->curDragTarget!=0)
2049 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2053 * Make sure we're hovering over a window.
2055 if (hwndNewTarget!=0)
2058 * Find-out if there is a drag target under the mouse
2060 HWND nexttar = hwndNewTarget;
2061 trackerInfo->curTargetHWND = hwndNewTarget;
2064 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
2065 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
2066 if(nexttar) hwndNewTarget = nexttar;
2068 trackerInfo->curDragTargetHWND = hwndNewTarget;
2069 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
2072 * If there is, notify it that we just dragged-in
2074 if (trackerInfo->curDragTarget!=0)
2076 IDropTarget_DragEnter(trackerInfo->curDragTarget,
2077 trackerInfo->dataObject,
2078 trackerInfo->dwKeyState,
2079 trackerInfo->curMousePos,
2080 trackerInfo->pdwEffect);
2086 * The mouse is not over a window so we don't track anything.
2088 trackerInfo->curDragTargetHWND = 0;
2089 trackerInfo->curTargetHWND = 0;
2090 trackerInfo->curDragTarget = 0;
2095 * Now that we have done that, we have to tell the source to give
2096 * us feedback on the work being done by the target. If we don't
2097 * have a target, simulate no effect.
2099 if (trackerInfo->curDragTarget==0)
2101 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2104 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2105 *trackerInfo->pdwEffect);
2108 * When we ask for feedback from the drop source, sometimes it will
2109 * do all the necessary work and sometimes it will not handle it
2110 * when that's the case, we must display the standard drag and drop
2113 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2115 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2117 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(1)));
2119 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2121 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(2)));
2123 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2125 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(3)));
2129 SetCursor(LoadCursorA(hProxyDll, MAKEINTRESOURCEA(0)));
2135 * OLEDD_TrackStateChange()
2137 * This method is invoked while a drag and drop operation is in effect.
2138 * It is used to notify the drop target/drop source callbacks when
2139 * the state of the keyboard or mouse button change.
2142 * trackerInfo - Pointer to the structure identifying the
2143 * drag & drop operation that is currently
2146 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2149 * Ask the drop source what to do with the operation.
2151 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2152 trackerInfo->dropSource,
2153 trackerInfo->escPressed,
2154 trackerInfo->dwKeyState);
2157 * All the return valued will stop the operation except the S_OK
2160 if (trackerInfo->returnValue!=S_OK)
2163 * Make sure the message loop in DoDragDrop stops
2165 trackerInfo->trackingDone = TRUE;
2168 * Release the mouse in case the drop target decides to show a popup
2169 * or a menu or something.
2174 * If we end-up over a target, drop the object in the target or
2175 * inform the target that the operation was cancelled.
2177 if (trackerInfo->curDragTarget!=0)
2179 switch (trackerInfo->returnValue)
2182 * If the source wants us to complete the operation, we tell
2183 * the drop target that we just dropped the object in it.
2185 case DRAGDROP_S_DROP:
2187 IDropTarget_Drop(trackerInfo->curDragTarget,
2188 trackerInfo->dataObject,
2189 trackerInfo->dwKeyState,
2190 trackerInfo->curMousePos,
2191 trackerInfo->pdwEffect);
2195 * If the source told us that we should cancel, fool the drop
2196 * target by telling it that the mouse left it's window.
2197 * Also set the drop effect to "NONE" in case the application
2198 * ignores the result of DoDragDrop.
2200 case DRAGDROP_S_CANCEL:
2201 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2202 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2210 * OLEDD_GetButtonState()
2212 * This method will use the current state of the keyboard to build
2213 * a button state mask equivalent to the one passed in the
2214 * WM_MOUSEMOVE wParam.
2216 static DWORD OLEDD_GetButtonState(void)
2218 BYTE keyboardState[256];
2221 GetKeyboardState(keyboardState);
2223 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2224 keyMask |= MK_SHIFT;
2226 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2227 keyMask |= MK_CONTROL;
2229 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2230 keyMask |= MK_LBUTTON;
2232 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2233 keyMask |= MK_RBUTTON;
2235 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2236 keyMask |= MK_MBUTTON;
2242 * OLEDD_GetButtonState()
2244 * This method will read the default value of the registry key in
2245 * parameter and extract a DWORD value from it. The registry key value
2246 * can be in a string key or a DWORD key.
2249 * regKey - Key to read the default value from
2250 * pdwValue - Pointer to the location where the DWORD
2251 * value is returned. This value is not modified
2252 * if the value is not found.
2255 static void OLEUTL_ReadRegistryDWORDValue(
2264 lres = RegQueryValueExA(regKey,
2271 if (lres==ERROR_SUCCESS)
2276 *pdwValue = *(DWORD*)buffer;
2281 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2287 /******************************************************************************
2290 * The operation of this function is documented literally in the WinAPI
2291 * documentation to involve a QueryInterface for the IViewObject interface,
2292 * followed by a call to IViewObject::Draw.
2294 HRESULT WINAPI OleDraw(
2301 IViewObject *viewobject;
2303 hres = IUnknown_QueryInterface(pUnk,
2305 (void**)&viewobject);
2307 if (SUCCEEDED(hres))
2311 rectl.left = lprcBounds->left;
2312 rectl.right = lprcBounds->right;
2313 rectl.top = lprcBounds->top;
2314 rectl.bottom = lprcBounds->bottom;
2315 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2317 IViewObject_Release(viewobject);
2322 return DV_E_NOIVIEWOBJECT;
2326 /***********************************************************************
2327 * OleTranslateAccelerator [OLE32.@]
2329 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2330 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2334 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2336 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2337 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2342 /******************************************************************************
2343 * OleCreate [OLE32.@]
2346 HRESULT WINAPI OleCreate(
2350 LPFORMATETC pFormatEtc,
2351 LPOLECLIENTSITE pClientSite,
2356 IUnknown * pUnk = NULL;
2357 IOleObject *pOleObject = NULL;
2359 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid),
2360 debugstr_guid(riid), renderopt, pFormatEtc, pClientSite, pStg, ppvObj);
2362 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, riid, (LPVOID*)&pUnk);
2364 if (SUCCEEDED(hres))
2365 hres = IStorage_SetClass(pStg, rclsid);
2367 if (pClientSite && SUCCEEDED(hres))
2369 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2370 if (SUCCEEDED(hres))
2373 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2377 if (SUCCEEDED(hres))
2379 IPersistStorage * pPS;
2380 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2382 TRACE("trying to set stg %p\n", pStg);
2383 hres = IPersistStorage_InitNew(pPS, pStg);
2384 TRACE("-- result 0x%08x\n", hres);
2385 IPersistStorage_Release(pPS);
2389 if (pClientSite && SUCCEEDED(hres))
2391 TRACE("trying to set clientsite %p\n", pClientSite);
2392 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2393 TRACE("-- result 0x%08x\n", hres);
2397 IOleObject_Release(pOleObject);
2399 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2402 IRunnableObject *pRunnable;
2403 IOleCache *pOleCache;
2406 hres2 = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2407 if (SUCCEEDED(hres2))
2409 hres = IRunnableObject_Run(pRunnable, NULL);
2410 IRunnableObject_Release(pRunnable);
2413 if (SUCCEEDED(hres))
2415 hres2 = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2416 if (SUCCEEDED(hres2))
2419 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2420 IOleCache_Release(pOleCache);
2425 if (FAILED(hres) && pUnk)
2427 IUnknown_Release(pUnk);
2433 TRACE("-- %p\n", pUnk);
2437 /******************************************************************************
2438 * OleGetAutoConvert [OLE32.@]
2440 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2442 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2444 WCHAR buf[CHARS_IN_GUID];
2448 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2453 if (RegQueryValueW(hkey, NULL, buf, &len))
2455 res = REGDB_E_KEYMISSING;
2458 res = CLSIDFromString(buf, pClsidNew);
2460 if (hkey) RegCloseKey(hkey);
2464 /******************************************************************************
2465 * OleSetAutoConvert [OLE32.@]
2467 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2469 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2471 WCHAR szClsidNew[CHARS_IN_GUID];
2474 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2476 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2479 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2480 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2482 res = REGDB_E_WRITEREGDB;
2487 if (hkey) RegCloseKey(hkey);
2491 /******************************************************************************
2492 * OleDoAutoConvert [OLE32.@]
2494 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2496 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2500 /******************************************************************************
2501 * OleIsRunning [OLE32.@]
2503 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2505 IRunnableObject *pRunnable;
2509 TRACE("(%p)\n", pObject);
2511 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2514 running = IRunnableObject_IsRunning(pRunnable);
2515 IRunnableObject_Release(pRunnable);
2519 /***********************************************************************
2520 * OleNoteObjectVisible [OLE32.@]
2522 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2524 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2525 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2529 /***********************************************************************
2530 * OLE_FreeClipDataArray [internal]
2533 * frees the data associated with an array of CLIPDATAs
2535 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2538 for (i = 0; i < count; i++)
2539 if (pClipDataArray[i].pClipData)
2540 CoTaskMemFree(pClipDataArray[i].pClipData);
2543 /***********************************************************************
2544 * PropSysAllocString [OLE32.@]
2546 * Basically a copy of SysAllocStringLen.
2548 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2552 WCHAR* stringBuffer;
2557 len = lstrlenW(str);
2559 * Find the length of the buffer passed-in, in bytes.
2561 bufferSize = len * sizeof (WCHAR);
2564 * Allocate a new buffer to hold the string.
2565 * Don't forget to keep an empty spot at the beginning of the
2566 * buffer for the character count and an extra character at the
2569 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2570 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2573 * If the memory allocation failed, return a null pointer.
2579 * Copy the length of the string in the placeholder.
2581 *newBuffer = bufferSize;
2584 * Skip the byte count.
2588 memcpy(newBuffer, str, bufferSize);
2591 * Make sure that there is a nul character at the end of the
2594 stringBuffer = (WCHAR*)newBuffer;
2595 stringBuffer[len] = '\0';
2597 return stringBuffer;
2600 /***********************************************************************
2601 * PropSysFreeString [OLE32.@]
2603 * Copy of SysFreeString.
2605 void WINAPI PropSysFreeString(LPOLESTR str)
2607 DWORD* bufferPointer;
2609 /* NULL is a valid parameter */
2613 * We have to be careful when we free a BSTR pointer, it points to
2614 * the beginning of the string but it skips the byte count contained
2615 * before the string.
2617 bufferPointer = (DWORD*)str;
2622 * Free the memory from its "real" origin.
2624 HeapFree(GetProcessHeap(), 0, bufferPointer);
2627 /******************************************************************************
2628 * Check if a PROPVARIANT's type is valid.
2630 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2657 case VT_STREAMED_OBJECT:
2658 case VT_STORED_OBJECT:
2659 case VT_BLOB_OBJECT:
2662 case VT_I2|VT_VECTOR:
2663 case VT_I4|VT_VECTOR:
2664 case VT_R4|VT_VECTOR:
2665 case VT_R8|VT_VECTOR:
2666 case VT_CY|VT_VECTOR:
2667 case VT_DATE|VT_VECTOR:
2668 case VT_BSTR|VT_VECTOR:
2669 case VT_ERROR|VT_VECTOR:
2670 case VT_BOOL|VT_VECTOR:
2671 case VT_VARIANT|VT_VECTOR:
2672 case VT_UI1|VT_VECTOR:
2673 case VT_UI2|VT_VECTOR:
2674 case VT_UI4|VT_VECTOR:
2675 case VT_I8|VT_VECTOR:
2676 case VT_UI8|VT_VECTOR:
2677 case VT_LPSTR|VT_VECTOR:
2678 case VT_LPWSTR|VT_VECTOR:
2679 case VT_FILETIME|VT_VECTOR:
2680 case VT_CF|VT_VECTOR:
2681 case VT_CLSID|VT_VECTOR:
2684 WARN("Bad type %d\n", vt);
2685 return STG_E_INVALIDPARAMETER;
2688 /***********************************************************************
2689 * PropVariantClear [OLE32.@]
2691 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2695 TRACE("(%p)\n", pvar);
2700 hr = PROPVARIANT_ValidateType(pvar->vt);
2725 case VT_STREAMED_OBJECT:
2727 case VT_STORED_OBJECT:
2728 if (pvar->u.pStream)
2729 IUnknown_Release(pvar->u.pStream);
2734 /* pick an arbitrary typed pointer - we don't care about the type
2735 * as we are just freeing it */
2736 CoTaskMemFree(pvar->u.puuid);
2739 case VT_BLOB_OBJECT:
2740 CoTaskMemFree(pvar->u.blob.pBlobData);
2743 if (pvar->u.bstrVal)
2744 PropSysFreeString(pvar->u.bstrVal);
2747 if (pvar->u.pclipdata)
2749 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2750 CoTaskMemFree(pvar->u.pclipdata);
2754 if (pvar->vt & VT_VECTOR)
2758 switch (pvar->vt & ~VT_VECTOR)
2761 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2764 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2767 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2768 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2771 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2772 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2775 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2776 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2779 if (pvar->vt & ~VT_VECTOR)
2781 /* pick an arbitrary VT_VECTOR structure - they all have the same
2783 CoTaskMemFree(pvar->u.capropvar.pElems);
2787 WARN("Invalid/unsupported type %d\n", pvar->vt);
2790 ZeroMemory(pvar, sizeof(*pvar));
2795 /***********************************************************************
2796 * PropVariantCopy [OLE32.@]
2798 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2799 const PROPVARIANT *pvarSrc) /* [in] */
2804 TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt);
2806 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2810 /* this will deal with most cases */
2811 *pvarDest = *pvarSrc;
2835 case VT_STREAMED_OBJECT:
2837 case VT_STORED_OBJECT:
2838 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2841 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2842 *pvarDest->u.puuid = *pvarSrc->u.puuid;
2845 len = strlen(pvarSrc->u.pszVal);
2846 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2847 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2850 len = lstrlenW(pvarSrc->u.pwszVal);
2851 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2852 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2855 case VT_BLOB_OBJECT:
2856 if (pvarSrc->u.blob.pBlobData)
2858 len = pvarSrc->u.blob.cbSize;
2859 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2860 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2864 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2867 if (pvarSrc->u.pclipdata)
2869 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2870 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
2871 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
2872 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
2873 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
2874 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2878 if (pvarSrc->vt & VT_VECTOR)
2883 switch(pvarSrc->vt & ~VT_VECTOR)
2885 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2886 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2887 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2888 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2889 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2890 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2891 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2892 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2893 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2894 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2895 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2896 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2897 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2898 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2899 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2900 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2901 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2902 case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break;
2903 case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break;
2904 case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break;
2905 case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break;
2908 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2909 return E_INVALIDARG;
2911 len = pvarSrc->u.capropvar.cElems;
2912 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2913 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2915 for (i = 0; i < len; i++)
2916 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2918 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2920 FIXME("Copy clipformats\n");
2922 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2924 for (i = 0; i < len; i++)
2925 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2927 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2930 for (i = 0; i < len; i++)
2932 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2933 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2934 memcpy(pvarDest->u.calpstr.pElems[i],
2935 pvarSrc->u.calpstr.pElems[i], strLen);
2938 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2941 for (i = 0; i < len; i++)
2943 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2945 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2946 memcpy(pvarDest->u.calpstr.pElems[i],
2947 pvarSrc->u.calpstr.pElems[i], strLen);
2951 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2954 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2960 /***********************************************************************
2961 * FreePropVariantArray [OLE32.@]
2963 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2964 PROPVARIANT *rgvars) /* [in/out] */
2968 TRACE("(%u, %p)\n", cVariants, rgvars);
2971 return E_INVALIDARG;
2973 for(i = 0; i < cVariants; i++)
2974 PropVariantClear(&rgvars[i]);
2979 /******************************************************************************
2980 * DllDebugObjectRPCHook (OLE32.@)
2981 * turns on and off internal debugging, pointer is only used on macintosh
2984 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)