4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
7 * Copyright 1999, 2000 Marcus Meissner
8 * Copyright 2005 Juan Lang
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
49 #include "wine/list.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(accel);
56 /******************************************************************************
57 * These are static/global variables and internal data structures that the
58 * OLE module uses to maintain it's state.
60 typedef struct tagTrackerWindowInfo
62 IDataObject* dataObject;
63 IDropSource* dropSource;
70 HWND curTargetHWND; /* window the mouse is hovering over */
71 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
72 IDropTarget* curDragTarget;
73 POINTL curMousePos; /* current position of the mouse in screen coordinates */
74 DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
77 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
79 HWND hwndFrame; /* The containers frame window */
80 HWND hwndActiveObject; /* The active objects window */
81 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
82 HMENU hmenuCombined; /* The combined menu */
83 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
86 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
88 DWORD tid; /* Thread Id */
89 HANDLE hHeap; /* Heap this is allocated from */
90 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
91 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
92 struct tagOleMenuHookItem *next;
95 static OleMenuHookItem *hook_list;
98 * This is the lock count on the OLE library. It is controlled by the
99 * OLEInitialize/OLEUninitialize methods.
101 static LONG OLE_moduleLockCount = 0;
104 * Name of our registered window class.
106 static const WCHAR OLEDD_DRAGTRACKERCLASS[] =
107 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
110 * Name of menu descriptor property.
112 static const WCHAR prop_olemenuW[] =
113 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
115 /* property to store IDropTarget pointer */
116 static const WCHAR prop_oledroptarget[] =
117 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
119 static const WCHAR clsidfmtW[] =
120 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
121 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
122 '%','0','2','x','%','0','2','x','}','\\',0};
124 static const WCHAR emptyW[] = { 0 };
126 /******************************************************************************
127 * These are the prototypes of miscellaneous utility methods
129 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
131 /******************************************************************************
132 * These are the prototypes of the utility methods used to manage a shared menu
134 static void OLEMenu_Initialize(void);
135 static void OLEMenu_UnInitialize(void);
136 static BOOL OLEMenu_InstallHooks( DWORD tid );
137 static BOOL OLEMenu_UnInstallHooks( DWORD tid );
138 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
139 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
140 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
141 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
142 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
144 /******************************************************************************
145 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
147 extern void OLEClipbrd_UnInitialize(void);
148 extern void OLEClipbrd_Initialize(void);
150 /******************************************************************************
151 * These are the prototypes of the utility methods used for OLE Drag n Drop
153 static void OLEDD_Initialize(void);
154 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
155 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo);
156 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo);
157 static DWORD OLEDD_GetButtonState(void);
159 /******************************************************************************
160 * OleBuildVersion [OLE32.@]
162 DWORD WINAPI OleBuildVersion(void)
164 TRACE("Returning version %d, build %d.\n", rmm, rup);
165 return (rmm<<16)+rup;
168 /***********************************************************************
169 * OleInitialize (OLE32.@)
171 HRESULT WINAPI OleInitialize(LPVOID reserved)
175 TRACE("(%p)\n", reserved);
178 * The first duty of the OleInitialize is to initialize the COM libraries.
180 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
183 * If the CoInitializeEx call failed, the OLE libraries can't be
189 if (!COM_CurrentInfo()->ole_inits)
193 * Then, it has to initialize the OLE specific modules.
197 * Object linking and Embedding
198 * In-place activation
200 if (!COM_CurrentInfo()->ole_inits++ &&
201 InterlockedIncrement(&OLE_moduleLockCount) == 1)
204 * Initialize the libraries.
206 TRACE("() - Initializing the OLE libraries\n");
211 OLEClipbrd_Initialize();
221 OLEMenu_Initialize();
227 /******************************************************************************
228 * OleUninitialize [OLE32.@]
230 void WINAPI OleUninitialize(void)
235 * If we hit the bottom of the lock stack, free the libraries.
237 if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
240 * Actually free the libraries.
242 TRACE("() - Freeing the last reference count\n");
247 OLEClipbrd_UnInitialize();
252 OLEMenu_UnInitialize();
256 * Then, uninitialize the COM libraries.
261 /******************************************************************************
262 * OleInitializeWOW [OLE32.@]
264 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
265 FIXME("(0x%08x, 0x%08x),stub!\n",x, y);
270 * OLEDD_FindDropTarget()
272 * Returns IDropTarget pointer registered for this window.
274 static inline IDropTarget* OLEDD_FindDropTarget(HWND hwnd)
276 return GetPropW(hwnd, prop_oledroptarget);
279 /***********************************************************************
280 * RegisterDragDrop (OLE32.@)
282 HRESULT WINAPI RegisterDragDrop(HWND hwnd, LPDROPTARGET pDropTarget)
286 TRACE("(%p,%p)\n", hwnd, pDropTarget);
288 if (!COM_CurrentApt())
290 ERR("COM not initialized\n");
291 return E_OUTOFMEMORY;
299 ERR("invalid hwnd %p\n", hwnd);
300 return DRAGDROP_E_INVALIDHWND;
303 /* block register for other processes windows */
304 GetWindowThreadProcessId(hwnd, &pid);
305 if (pid != GetCurrentProcessId())
307 FIXME("register for another process windows is disabled\n");
308 return DRAGDROP_E_INVALIDHWND;
311 /* check if the window is already registered */
312 if (OLEDD_FindDropTarget(hwnd))
313 return DRAGDROP_E_ALREADYREGISTERED;
315 IDropTarget_AddRef(pDropTarget);
316 SetPropW(hwnd, prop_oledroptarget, pDropTarget);
321 /***********************************************************************
322 * RevokeDragDrop (OLE32.@)
324 HRESULT WINAPI RevokeDragDrop(HWND hwnd)
326 IDropTarget* droptarget;
328 TRACE("(%p)\n", hwnd);
332 ERR("invalid hwnd %p\n", hwnd);
333 return DRAGDROP_E_INVALIDHWND;
336 /* no registration data */
337 if (!(droptarget = OLEDD_FindDropTarget(hwnd)))
338 return DRAGDROP_E_NOTREGISTERED;
340 IDropTarget_Release(droptarget);
341 RemovePropW(hwnd, prop_oledroptarget);
346 /***********************************************************************
347 * OleRegGetUserType (OLE32.@)
349 * This implementation of OleRegGetUserType ignores the dwFormOfType
350 * parameter and always returns the full name of the object. This is
351 * not too bad since this is the case for many objects because of the
352 * way they are registered.
354 HRESULT WINAPI OleRegGetUserType(
357 LPOLESTR* pszUserType)
366 * Initialize the out parameter.
371 * Build the key name we're looking for
373 sprintfW( keyName, clsidfmtW,
374 clsid->Data1, clsid->Data2, clsid->Data3,
375 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
376 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
378 TRACE("(%s, %d, %p)\n", debugstr_w(keyName), dwFormOfType, pszUserType);
381 * Open the class id Key
383 hres = RegOpenKeyW(HKEY_CLASSES_ROOT,
387 if (hres != ERROR_SUCCESS)
388 return REGDB_E_CLASSNOTREG;
391 * Retrieve the size of the name string.
395 hres = RegQueryValueExW(clsidKey,
402 if (hres!=ERROR_SUCCESS)
404 RegCloseKey(clsidKey);
405 return REGDB_E_READREGDB;
409 * Allocate a buffer for the registry value.
411 *pszUserType = CoTaskMemAlloc(cbData);
413 if (*pszUserType==NULL)
415 RegCloseKey(clsidKey);
416 return E_OUTOFMEMORY;
419 hres = RegQueryValueExW(clsidKey,
423 (LPBYTE) *pszUserType,
426 RegCloseKey(clsidKey);
428 if (hres != ERROR_SUCCESS)
430 CoTaskMemFree(*pszUserType);
433 return REGDB_E_READREGDB;
439 /***********************************************************************
440 * DoDragDrop [OLE32.@]
442 HRESULT WINAPI DoDragDrop (
443 IDataObject *pDataObject, /* [in] ptr to the data obj */
444 IDropSource* pDropSource, /* [in] ptr to the source obj */
445 DWORD dwOKEffect, /* [in] effects allowed by the source */
446 DWORD *pdwEffect) /* [out] ptr to effects of the source */
448 static const WCHAR trackerW[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
449 TrackerWindowInfo trackerInfo;
450 HWND hwndTrackWindow;
453 TRACE("(%p, %p, %d, %p)\n", pDataObject, pDropSource, dwOKEffect, pdwEffect);
455 if (!pDataObject || !pDropSource || !pdwEffect)
459 * Setup the drag n drop tracking window.
462 trackerInfo.dataObject = pDataObject;
463 trackerInfo.dropSource = pDropSource;
464 trackerInfo.dwOKEffect = dwOKEffect;
465 trackerInfo.pdwEffect = pdwEffect;
466 trackerInfo.trackingDone = FALSE;
467 trackerInfo.escPressed = FALSE;
468 trackerInfo.curDragTargetHWND = 0;
469 trackerInfo.curTargetHWND = 0;
470 trackerInfo.curDragTarget = 0;
472 hwndTrackWindow = CreateWindowW(OLEDD_DRAGTRACKERCLASS, trackerW,
473 WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
474 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
480 * Capture the mouse input
482 SetCapture(hwndTrackWindow);
487 * Pump messages. All mouse input should go to the capture window.
489 while (!trackerInfo.trackingDone && GetMessageW(&msg, 0, 0, 0) )
491 trackerInfo.curMousePos.x = msg.pt.x;
492 trackerInfo.curMousePos.y = msg.pt.y;
493 trackerInfo.dwKeyState = OLEDD_GetButtonState();
495 if ( (msg.message >= WM_KEYFIRST) &&
496 (msg.message <= WM_KEYLAST) )
499 * When keyboard messages are sent to windows on this thread, we
500 * want to ignore notify the drop source that the state changed.
501 * in the case of the Escape key, we also notify the drop source
502 * we give it a special meaning.
504 if ( (msg.message==WM_KEYDOWN) &&
505 (msg.wParam==VK_ESCAPE) )
507 trackerInfo.escPressed = TRUE;
511 * Notify the drop source.
513 OLEDD_TrackStateChange(&trackerInfo);
518 * Dispatch the messages only when it's not a keyboard message.
520 DispatchMessageW(&msg);
524 /* re-post the quit message to outer message loop */
525 if (msg.message == WM_QUIT)
526 PostQuitMessage(msg.wParam);
528 * Destroy the temporary window.
530 DestroyWindow(hwndTrackWindow);
532 return trackerInfo.returnValue;
538 /***********************************************************************
539 * OleQueryLinkFromData [OLE32.@]
541 HRESULT WINAPI OleQueryLinkFromData(
542 IDataObject* pSrcDataObject)
544 FIXME("(%p),stub!\n", pSrcDataObject);
548 /***********************************************************************
549 * OleRegGetMiscStatus [OLE32.@]
551 HRESULT WINAPI OleRegGetMiscStatus(
556 static const WCHAR miscstatusW[] = {'M','i','s','c','S','t','a','t','u','s',0};
557 static const WCHAR dfmtW[] = {'%','d',0};
565 * Initialize the out parameter.
570 * Build the key name we're looking for
572 sprintfW( keyName, clsidfmtW,
573 clsid->Data1, clsid->Data2, clsid->Data3,
574 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
575 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
577 TRACE("(%s, %d, %p)\n", debugstr_w(keyName), dwAspect, pdwStatus);
580 * Open the class id Key
582 result = RegOpenKeyW(HKEY_CLASSES_ROOT,
586 if (result != ERROR_SUCCESS)
587 return REGDB_E_CLASSNOTREG;
592 result = RegOpenKeyW(clsidKey,
597 if (result != ERROR_SUCCESS)
599 RegCloseKey(clsidKey);
600 return REGDB_E_READREGDB;
604 * Read the default value
606 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
609 * Open the key specific to the requested aspect.
611 sprintfW(keyName, dfmtW, dwAspect);
613 result = RegOpenKeyW(miscStatusKey,
617 if (result == ERROR_SUCCESS)
619 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
620 RegCloseKey(aspectKey);
626 RegCloseKey(miscStatusKey);
627 RegCloseKey(clsidKey);
632 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
636 const IEnumOLEVERBVtbl *lpvtbl;
643 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
644 IEnumOLEVERB *iface, REFIID riid, void **ppv)
646 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
647 if (IsEqualIID(riid, &IID_IUnknown) ||
648 IsEqualIID(riid, &IID_IEnumOLEVERB))
650 IUnknown_AddRef(iface);
654 return E_NOINTERFACE;
657 static ULONG WINAPI EnumOLEVERB_AddRef(
660 EnumOLEVERB *This = (EnumOLEVERB *)iface;
662 return InterlockedIncrement(&This->ref);
665 static ULONG WINAPI EnumOLEVERB_Release(
668 EnumOLEVERB *This = (EnumOLEVERB *)iface;
669 LONG refs = InterlockedDecrement(&This->ref);
673 RegCloseKey(This->hkeyVerb);
674 HeapFree(GetProcessHeap(), 0, This);
679 static HRESULT WINAPI EnumOLEVERB_Next(
680 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
683 EnumOLEVERB *This = (EnumOLEVERB *)iface;
686 TRACE("(%d, %p, %p)\n", celt, rgelt, pceltFetched);
691 for (; celt; celt--, rgelt++)
696 LPWSTR pwszMenuFlags;
698 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
699 if (res == ERROR_NO_MORE_ITEMS)
704 else if (res != ERROR_SUCCESS)
706 ERR("RegEnumKeyW failed with error %d\n", res);
707 hr = REGDB_E_READREGDB;
710 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
711 if (res != ERROR_SUCCESS)
713 ERR("RegQueryValueW failed with error %d\n", res);
714 hr = REGDB_E_READREGDB;
717 pwszOLEVERB = CoTaskMemAlloc(cbData);
723 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
724 if (res != ERROR_SUCCESS)
726 ERR("RegQueryValueW failed with error %d\n", res);
727 hr = REGDB_E_READREGDB;
728 CoTaskMemFree(pwszOLEVERB);
732 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
733 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
736 hr = OLEOBJ_E_INVALIDVERB;
737 CoTaskMemFree(pwszOLEVERB);
740 /* nul terminate the name string and advance to first character */
741 *pwszMenuFlags = '\0';
743 pwszAttribs = strchrW(pwszMenuFlags, ',');
746 hr = OLEOBJ_E_INVALIDVERB;
747 CoTaskMemFree(pwszOLEVERB);
750 /* nul terminate the menu string and advance to first character */
754 /* fill out structure for this verb */
755 rgelt->lVerb = atolW(wszSubKey);
756 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
757 rgelt->fuFlags = atolW(pwszMenuFlags);
758 rgelt->grfAttribs = atolW(pwszAttribs);
767 static HRESULT WINAPI EnumOLEVERB_Skip(
768 IEnumOLEVERB *iface, ULONG celt)
770 EnumOLEVERB *This = (EnumOLEVERB *)iface;
772 TRACE("(%d)\n", celt);
778 static HRESULT WINAPI EnumOLEVERB_Reset(
781 EnumOLEVERB *This = (EnumOLEVERB *)iface;
789 static HRESULT WINAPI EnumOLEVERB_Clone(
791 IEnumOLEVERB **ppenum)
793 EnumOLEVERB *This = (EnumOLEVERB *)iface;
795 TRACE("(%p)\n", ppenum);
796 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
797 return HRESULT_FROM_WIN32(GetLastError());
798 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
801 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
803 EnumOLEVERB_QueryInterface,
812 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
814 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
817 RegCloseKey(hkeyVerb);
818 return E_OUTOFMEMORY;
820 This->lpvtbl = &EnumOLEVERB_VTable;
823 This->hkeyVerb = hkeyVerb;
824 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
828 /***********************************************************************
829 * OleRegEnumVerbs [OLE32.@]
831 * Enumerates verbs associated with a class stored in the registry.
834 * clsid [I] Class ID to enumerate the verbs for.
835 * ppenum [O] Enumerator.
839 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
840 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
841 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
842 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
844 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
849 static const WCHAR wszVerb[] = {'V','e','r','b',0};
851 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
853 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
856 if (res == REGDB_E_CLASSNOTREG)
857 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
858 else if (res == REGDB_E_KEYMISSING)
859 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
861 ERR("failed to open Verbs key for CLSID %s with error %d\n",
862 debugstr_guid(clsid), res);
866 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
867 NULL, NULL, NULL, NULL, NULL, NULL);
868 if (res != ERROR_SUCCESS)
870 ERR("failed to get subkey count with error %d\n", GetLastError());
871 return REGDB_E_READREGDB;
876 WARN("class %s has no verbs\n", debugstr_guid(clsid));
877 RegCloseKey(hkeyVerb);
878 return OLEOBJ_E_NOVERBS;
881 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
884 /******************************************************************************
885 * OleSetContainedObject [OLE32.@]
887 HRESULT WINAPI OleSetContainedObject(
891 IRunnableObject* runnable = NULL;
894 TRACE("(%p,%x)\n", pUnknown, fContained);
896 hres = IUnknown_QueryInterface(pUnknown,
897 &IID_IRunnableObject,
902 hres = IRunnableObject_SetContainedObject(runnable, fContained);
904 IRunnableObject_Release(runnable);
912 /******************************************************************************
915 * Set the OLE object to the running state.
918 * pUnknown [I] OLE object to run.
922 * Failure: Any HRESULT code.
924 HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
926 IRunnableObject *runable;
929 TRACE("(%p)\n", pUnknown);
931 hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
933 return S_OK; /* Appears to return no error. */
935 hres = IRunnableObject_Run(runable, NULL);
936 IRunnableObject_Release(runable);
940 /******************************************************************************
943 HRESULT WINAPI OleLoad(
946 LPOLECLIENTSITE pClientSite,
949 IPersistStorage* persistStorage = NULL;
951 IOleObject* pOleObject = NULL;
955 TRACE("(%p, %s, %p, %p)\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
960 * TODO, Conversion ... OleDoAutoConvert
964 * Get the class ID for the object.
966 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
969 * Now, try and create the handler for the object
971 hres = CoCreateInstance(&storageInfo.clsid,
973 CLSCTX_INPROC_HANDLER|CLSCTX_INPROC_SERVER,
978 * If that fails, as it will most times, load the default
983 hres = OleCreateDefaultHandler(&storageInfo.clsid,
990 * If we couldn't find a handler... this is bad. Abort the whole thing.
997 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1001 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1005 if (SUCCEEDED(hres))
1007 * Initialize the object with it's IPersistStorage interface.
1009 hres = IOleObject_QueryInterface(pUnk,
1010 &IID_IPersistStorage,
1011 (void**)&persistStorage);
1013 if (SUCCEEDED(hres))
1015 hres = IPersistStorage_Load(persistStorage, pStg);
1017 IPersistStorage_Release(persistStorage);
1018 persistStorage = NULL;
1021 if (SUCCEEDED(hres) && pClientSite)
1023 * Inform the new object of it's client site.
1025 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1028 * Cleanup interfaces used internally
1031 IOleObject_Release(pOleObject);
1033 if (SUCCEEDED(hres))
1037 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1038 if (SUCCEEDED(hres1))
1040 FIXME("handle OLE link\n");
1041 IOleLink_Release(pOleLink);
1047 IUnknown_Release(pUnk);
1056 /***********************************************************************
1059 HRESULT WINAPI OleSave(
1060 LPPERSISTSTORAGE pPS,
1067 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1070 * First, we transfer the class ID (if available)
1072 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1074 if (SUCCEEDED(hres))
1076 WriteClassStg(pStg, &objectClass);
1080 * Then, we ask the object to save itself to the
1081 * storage. If it is successful, we commit the storage.
1083 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1085 if (SUCCEEDED(hres))
1087 IStorage_Commit(pStg,
1095 /******************************************************************************
1096 * OleLockRunning [OLE32.@]
1098 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1100 IRunnableObject* runnable = NULL;
1103 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1105 hres = IUnknown_QueryInterface(pUnknown,
1106 &IID_IRunnableObject,
1109 if (SUCCEEDED(hres))
1111 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1113 IRunnableObject_Release(runnable);
1122 /**************************************************************************
1123 * Internal methods to manage the shared OLE menu in response to the
1124 * OLE***MenuDescriptor API
1128 * OLEMenu_Initialize()
1130 * Initializes the OLEMENU data structures.
1132 static void OLEMenu_Initialize(void)
1137 * OLEMenu_UnInitialize()
1139 * Releases the OLEMENU data structures.
1141 static void OLEMenu_UnInitialize(void)
1145 /*************************************************************************
1146 * OLEMenu_InstallHooks
1147 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1149 * RETURNS: TRUE if message hooks were successfully installed
1152 static BOOL OLEMenu_InstallHooks( DWORD tid )
1154 OleMenuHookItem *pHookItem;
1156 /* Create an entry for the hook table */
1157 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1158 sizeof(OleMenuHookItem)) ) )
1161 pHookItem->tid = tid;
1162 pHookItem->hHeap = GetProcessHeap();
1163 pHookItem->CallWndProc_hHook = NULL;
1165 /* Install a thread scope message hook for WH_GETMESSAGE */
1166 pHookItem->GetMsg_hHook = SetWindowsHookExW( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1167 0, GetCurrentThreadId() );
1168 if ( !pHookItem->GetMsg_hHook )
1171 /* Install a thread scope message hook for WH_CALLWNDPROC */
1172 pHookItem->CallWndProc_hHook = SetWindowsHookExW( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1173 0, GetCurrentThreadId() );
1174 if ( !pHookItem->CallWndProc_hHook )
1177 /* Insert the hook table entry */
1178 pHookItem->next = hook_list;
1179 hook_list = pHookItem;
1184 /* Unhook any hooks */
1185 if ( pHookItem->GetMsg_hHook )
1186 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1187 if ( pHookItem->CallWndProc_hHook )
1188 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1189 /* Release the hook table entry */
1190 HeapFree(pHookItem->hHeap, 0, pHookItem );
1195 /*************************************************************************
1196 * OLEMenu_UnInstallHooks
1197 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1199 * RETURNS: TRUE if message hooks were successfully installed
1202 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1204 OleMenuHookItem *pHookItem = NULL;
1205 OleMenuHookItem **ppHook = &hook_list;
1209 if ((*ppHook)->tid == tid)
1211 pHookItem = *ppHook;
1212 *ppHook = pHookItem->next;
1215 ppHook = &(*ppHook)->next;
1217 if (!pHookItem) return FALSE;
1219 /* Uninstall the hooks installed for this thread */
1220 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1222 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1225 /* Release the hook table entry */
1226 HeapFree(pHookItem->hHeap, 0, pHookItem );
1231 /* Release the hook table entry */
1232 HeapFree(pHookItem->hHeap, 0, pHookItem );
1237 /*************************************************************************
1238 * OLEMenu_IsHookInstalled
1239 * Tests if OLEMenu hooks have been installed for a thread
1241 * RETURNS: The pointer and index of the hook table entry for the tid
1242 * NULL and -1 for the index if no hooks were installed for this thread
1244 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1246 OleMenuHookItem *pHookItem;
1248 /* Do a simple linear search for an entry whose tid matches ours.
1249 * We really need a map but efficiency is not a concern here. */
1250 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1252 if ( tid == pHookItem->tid )
1259 /***********************************************************************
1260 * OLEMenu_FindMainMenuIndex
1262 * Used by OLEMenu API to find the top level group a menu item belongs to.
1263 * On success pnPos contains the index of the item in the top level menu group
1265 * RETURNS: TRUE if the ID was found, FALSE on failure
1267 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1271 nItems = GetMenuItemCount( hMainMenu );
1273 for (i = 0; i < nItems; i++)
1277 /* Is the current item a submenu? */
1278 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1280 /* If the handle is the same we're done */
1281 if ( hsubmenu == hPopupMenu )
1287 /* Recursively search without updating pnPos */
1288 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1300 /***********************************************************************
1301 * OLEMenu_SetIsServerMenu
1303 * Checks whether a popup menu belongs to a shared menu group which is
1304 * owned by the server, and sets the menu descriptor state accordingly.
1305 * All menu messages from these groups should be routed to the server.
1307 * RETURNS: TRUE if the popup menu is part of a server owned group
1308 * FALSE if the popup menu is part of a container owned group
1310 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1312 UINT nPos = 0, nWidth, i;
1314 pOleMenuDescriptor->bIsServerItem = FALSE;
1316 /* Don't bother searching if the popup is the combined menu itself */
1317 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1320 /* Find the menu item index in the shared OLE menu that this item belongs to */
1321 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1324 /* The group widths array has counts for the number of elements
1325 * in the groups File, Edit, Container, Object, Window, Help.
1326 * The Edit, Object & Help groups belong to the server object
1327 * and the other three belong to the container.
1328 * Loop through the group widths and locate the group we are a member of.
1330 for ( i = 0, nWidth = 0; i < 6; i++ )
1332 nWidth += pOleMenuDescriptor->mgw.width[i];
1333 if ( nPos < nWidth )
1335 /* Odd elements are server menu widths */
1336 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1341 return pOleMenuDescriptor->bIsServerItem;
1344 /*************************************************************************
1345 * OLEMenu_CallWndProc
1346 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1347 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1349 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1352 HOLEMENU hOleMenu = 0;
1353 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1354 OleMenuHookItem *pHookItem = NULL;
1357 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1359 /* Check if we're being asked to process the message */
1360 if ( HC_ACTION != code )
1363 /* Retrieve the current message being dispatched from lParam */
1364 pMsg = (LPCWPSTRUCT)lParam;
1366 /* Check if the message is destined for a window we are interested in:
1367 * If the window has an OLEMenu property we may need to dispatch
1368 * the menu message to its active objects window instead. */
1370 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1374 /* Get the menu descriptor */
1375 pOleMenuDescriptor = GlobalLock( hOleMenu );
1376 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1379 /* Process menu messages */
1380 switch( pMsg->message )
1384 /* Reset the menu descriptor state */
1385 pOleMenuDescriptor->bIsServerItem = FALSE;
1387 /* Send this message to the server as well */
1388 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1389 pMsg->message, pMsg->wParam, pMsg->lParam );
1393 case WM_INITMENUPOPUP:
1395 /* Save the state for whether this is a server owned menu */
1396 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1402 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1403 if ( fuFlags & MF_SYSMENU )
1406 /* Save the state for whether this is a server owned popup menu */
1407 else if ( fuFlags & MF_POPUP )
1408 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1415 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1416 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1417 goto NEXTHOOK; /* Not a menu message */
1426 /* If the message was for the server dispatch it accordingly */
1427 if ( pOleMenuDescriptor->bIsServerItem )
1429 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1430 pMsg->message, pMsg->wParam, pMsg->lParam );
1434 if ( pOleMenuDescriptor )
1435 GlobalUnlock( hOleMenu );
1437 /* Lookup the hook item for the current thread */
1438 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1440 /* This should never fail!! */
1441 WARN("could not retrieve hHook for current thread!\n" );
1445 /* Pass on the message to the next hooker */
1446 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1449 /*************************************************************************
1450 * OLEMenu_GetMsgProc
1451 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1452 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1454 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1457 HOLEMENU hOleMenu = 0;
1458 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1459 OleMenuHookItem *pHookItem = NULL;
1462 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1464 /* Check if we're being asked to process a messages */
1465 if ( HC_ACTION != code )
1468 /* Retrieve the current message being dispatched from lParam */
1469 pMsg = (LPMSG)lParam;
1471 /* Check if the message is destined for a window we are interested in:
1472 * If the window has an OLEMenu property we may need to dispatch
1473 * the menu message to its active objects window instead. */
1475 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1479 /* Process menu messages */
1480 switch( pMsg->message )
1484 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1486 goto NEXTHOOK; /* Not a menu message */
1493 /* Get the menu descriptor */
1494 pOleMenuDescriptor = GlobalLock( hOleMenu );
1495 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1498 /* If the message was for the server dispatch it accordingly */
1499 if ( pOleMenuDescriptor->bIsServerItem )
1501 /* Change the hWnd in the message to the active objects hWnd.
1502 * The message loop which reads this message will automatically
1503 * dispatch it to the embedded objects window. */
1504 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1508 if ( pOleMenuDescriptor )
1509 GlobalUnlock( hOleMenu );
1511 /* Lookup the hook item for the current thread */
1512 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1514 /* This should never fail!! */
1515 WARN("could not retrieve hHook for current thread!\n" );
1519 /* Pass on the message to the next hooker */
1520 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1523 /***********************************************************************
1524 * OleCreateMenuDescriptor [OLE32.@]
1525 * Creates an OLE menu descriptor for OLE to use when dispatching
1526 * menu messages and commands.
1529 * hmenuCombined - Handle to the objects combined menu
1530 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1533 HOLEMENU WINAPI OleCreateMenuDescriptor(
1534 HMENU hmenuCombined,
1535 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1538 OleMenuDescriptor *pOleMenuDescriptor;
1541 if ( !hmenuCombined || !lpMenuWidths )
1544 /* Create an OLE menu descriptor */
1545 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1546 sizeof(OleMenuDescriptor) ) ) )
1549 pOleMenuDescriptor = GlobalLock( hOleMenu );
1550 if ( !pOleMenuDescriptor )
1553 /* Initialize menu group widths and hmenu */
1554 for ( i = 0; i < 6; i++ )
1555 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1557 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1558 pOleMenuDescriptor->bIsServerItem = FALSE;
1559 GlobalUnlock( hOleMenu );
1564 /***********************************************************************
1565 * OleDestroyMenuDescriptor [OLE32.@]
1566 * Destroy the shared menu descriptor
1568 HRESULT WINAPI OleDestroyMenuDescriptor(
1569 HOLEMENU hmenuDescriptor)
1571 if ( hmenuDescriptor )
1572 GlobalFree( hmenuDescriptor );
1576 /***********************************************************************
1577 * OleSetMenuDescriptor [OLE32.@]
1578 * Installs or removes OLE dispatching code for the containers frame window.
1581 * hOleMenu Handle to composite menu descriptor
1582 * hwndFrame Handle to containers frame window
1583 * hwndActiveObject Handle to objects in-place activation window
1584 * lpFrame Pointer to IOleInPlaceFrame on containers window
1585 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1588 * S_OK - menu installed correctly
1589 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1592 * The lpFrame and lpActiveObject parameters are currently ignored
1593 * OLE should install context sensitive help F1 filtering for the app when
1594 * these are non null.
1596 HRESULT WINAPI OleSetMenuDescriptor(
1599 HWND hwndActiveObject,
1600 LPOLEINPLACEFRAME lpFrame,
1601 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1603 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1606 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1607 return E_INVALIDARG;
1609 if ( lpFrame || lpActiveObject )
1611 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1619 /* Set up a message hook to intercept the containers frame window messages.
1620 * The message filter is responsible for dispatching menu messages from the
1621 * shared menu which are intended for the object.
1624 if ( hOleMenu ) /* Want to install dispatching code */
1626 /* If OLEMenu hooks are already installed for this thread, fail
1627 * Note: This effectively means that OleSetMenuDescriptor cannot
1628 * be called twice in succession on the same frame window
1629 * without first calling it with a null hOleMenu to uninstall */
1630 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1633 /* Get the menu descriptor */
1634 pOleMenuDescriptor = GlobalLock( hOleMenu );
1635 if ( !pOleMenuDescriptor )
1636 return E_UNEXPECTED;
1638 /* Update the menu descriptor */
1639 pOleMenuDescriptor->hwndFrame = hwndFrame;
1640 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1642 GlobalUnlock( hOleMenu );
1643 pOleMenuDescriptor = NULL;
1645 /* Add a menu descriptor windows property to the frame window */
1646 SetPropW( hwndFrame, prop_olemenuW, hOleMenu );
1648 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1649 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1652 else /* Want to uninstall dispatching code */
1654 /* Uninstall the hooks */
1655 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1658 /* Remove the menu descriptor property from the frame window */
1659 RemovePropW( hwndFrame, prop_olemenuW );
1665 /******************************************************************************
1666 * IsAccelerator [OLE32.@]
1667 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1669 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1674 if(!lpMsg) return FALSE;
1677 WARN_(accel)("NULL accel handle\n");
1680 if((lpMsg->message != WM_KEYDOWN &&
1681 lpMsg->message != WM_SYSKEYDOWN &&
1682 lpMsg->message != WM_SYSCHAR &&
1683 lpMsg->message != WM_CHAR)) return FALSE;
1684 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1685 if (NULL == lpAccelTbl)
1689 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1691 WARN_(accel)("CopyAcceleratorTableW failed\n");
1692 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1696 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1697 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1698 hAccel, cAccelEntries,
1699 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1700 for(i = 0; i < cAccelEntries; i++)
1702 if(lpAccelTbl[i].key != lpMsg->wParam)
1705 if(lpMsg->message == WM_CHAR)
1707 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1709 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg->wParam) & 0xff);
1715 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1718 TRACE_(accel)("found accel for virt_key %04lx (scan %04x)\n",
1719 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1720 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1721 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1722 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1723 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1724 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1728 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1730 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1731 { /* ^^ ALT pressed */
1732 TRACE_(accel)("found accel for Alt-%c\n", LOWORD(lpMsg->wParam) & 0xff);
1740 WARN_(accel)("couldn't translate accelerator key\n");
1741 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1745 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1746 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1750 /***********************************************************************
1751 * ReleaseStgMedium [OLE32.@]
1753 void WINAPI ReleaseStgMedium(
1756 switch (pmedium->tymed)
1760 if ( (pmedium->pUnkForRelease==0) &&
1761 (pmedium->u.hGlobal!=0) )
1762 GlobalFree(pmedium->u.hGlobal);
1767 if (pmedium->u.lpszFileName!=0)
1769 if (pmedium->pUnkForRelease==0)
1771 DeleteFileW(pmedium->u.lpszFileName);
1774 CoTaskMemFree(pmedium->u.lpszFileName);
1780 if (pmedium->u.pstm!=0)
1782 IStream_Release(pmedium->u.pstm);
1786 case TYMED_ISTORAGE:
1788 if (pmedium->u.pstg!=0)
1790 IStorage_Release(pmedium->u.pstg);
1796 if ( (pmedium->pUnkForRelease==0) &&
1797 (pmedium->u.hBitmap!=0) )
1798 DeleteObject(pmedium->u.hBitmap);
1803 if ( (pmedium->pUnkForRelease==0) &&
1804 (pmedium->u.hMetaFilePict!=0) )
1806 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1807 DeleteMetaFile(pMP->hMF);
1808 GlobalUnlock(pmedium->u.hMetaFilePict);
1809 GlobalFree(pmedium->u.hMetaFilePict);
1815 if ( (pmedium->pUnkForRelease==0) &&
1816 (pmedium->u.hEnhMetaFile!=0) )
1818 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1826 pmedium->tymed=TYMED_NULL;
1829 * After cleaning up, the unknown is released
1831 if (pmedium->pUnkForRelease!=0)
1833 IUnknown_Release(pmedium->pUnkForRelease);
1834 pmedium->pUnkForRelease = 0;
1839 * OLEDD_Initialize()
1841 * Initializes the OLE drag and drop data structures.
1843 static void OLEDD_Initialize(void)
1847 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1848 wndClass.style = CS_GLOBALCLASS;
1849 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1850 wndClass.cbClsExtra = 0;
1851 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1852 wndClass.hCursor = 0;
1853 wndClass.hbrBackground = 0;
1854 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1856 RegisterClassW (&wndClass);
1860 * OLEDD_DragTrackerWindowProc()
1862 * This method is the WindowProcedure of the drag n drop tracking
1863 * window. During a drag n Drop operation, an invisible window is created
1864 * to receive the user input and act upon it. This procedure is in charge
1868 #define DRAG_TIMER_ID 1
1870 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1880 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1882 SetWindowLongPtrW(hwnd, 0, (LONG_PTR)createStruct->lpCreateParams);
1883 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
1890 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1896 case WM_LBUTTONDOWN:
1897 case WM_MBUTTONDOWN:
1898 case WM_RBUTTONDOWN:
1900 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
1905 KillTimer(hwnd, DRAG_TIMER_ID);
1911 * This is a window proc after all. Let's call the default.
1913 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
1917 * OLEDD_TrackMouseMove()
1919 * This method is invoked while a drag and drop operation is in effect.
1920 * it will generate the appropriate callbacks in the drop source
1921 * and drop target. It will also provide the expected feedback to
1925 * trackerInfo - Pointer to the structure identifying the
1926 * drag & drop operation that is currently
1929 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
1931 HWND hwndNewTarget = 0;
1936 * Get the handle of the window under the mouse
1938 pt.x = trackerInfo->curMousePos.x;
1939 pt.y = trackerInfo->curMousePos.y;
1940 hwndNewTarget = WindowFromPoint(pt);
1943 * Every time, we re-initialize the effects passed to the
1944 * IDropTarget to the effects allowed by the source.
1946 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1949 * If we are hovering over the same target as before, send the
1950 * DragOver notification
1952 if ( (trackerInfo->curDragTarget != 0) &&
1953 (trackerInfo->curTargetHWND == hwndNewTarget) )
1955 IDropTarget_DragOver(trackerInfo->curDragTarget,
1956 trackerInfo->dwKeyState,
1957 trackerInfo->curMousePos,
1958 trackerInfo->pdwEffect);
1963 * If we changed window, we have to notify our old target and check for
1966 if (trackerInfo->curDragTarget)
1967 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1970 * Make sure we're hovering over a window.
1975 * Find-out if there is a drag target under the mouse
1977 HWND next_target_wnd = hwndNewTarget;
1978 IDropTarget *new_target;
1981 trackerInfo->curTargetHWND = hwndNewTarget;
1984 new_target = OLEDD_FindDropTarget(next_target_wnd);
1985 } while (!new_target && (next_target_wnd = GetParent(next_target_wnd)));
1987 if (next_target_wnd) hwndNewTarget = next_target_wnd;
1989 GetWindowThreadProcessId(hwndNewTarget, &pid);
1990 if (pid != GetCurrentProcessId())
1992 FIXME("drop to another process window is unsupported\n");
1993 trackerInfo->curDragTargetHWND = 0;
1994 trackerInfo->curTargetHWND = 0;
1995 trackerInfo->curDragTarget = 0;
1999 trackerInfo->curDragTargetHWND = hwndNewTarget;
2000 trackerInfo->curDragTarget = new_target;
2004 * If there is, notify it that we just dragged-in
2006 if (trackerInfo->curDragTarget)
2008 hr = IDropTarget_DragEnter(trackerInfo->curDragTarget,
2009 trackerInfo->dataObject,
2010 trackerInfo->dwKeyState,
2011 trackerInfo->curMousePos,
2012 trackerInfo->pdwEffect);
2014 /* failed DragEnter() means invalid target */
2017 trackerInfo->curDragTargetHWND = 0;
2018 trackerInfo->curTargetHWND = 0;
2019 trackerInfo->curDragTarget = 0;
2026 * The mouse is not over a window so we don't track anything.
2028 trackerInfo->curDragTargetHWND = 0;
2029 trackerInfo->curTargetHWND = 0;
2030 trackerInfo->curDragTarget = 0;
2035 * Now that we have done that, we have to tell the source to give
2036 * us feedback on the work being done by the target. If we don't
2037 * have a target, simulate no effect.
2039 if (trackerInfo->curDragTarget==0)
2041 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2044 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2045 *trackerInfo->pdwEffect);
2048 * When we ask for feedback from the drop source, sometimes it will
2049 * do all the necessary work and sometimes it will not handle it
2050 * when that's the case, we must display the standard drag and drop
2053 if (hr == DRAGDROP_S_USEDEFAULTCURSORS)
2057 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2059 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(1));
2061 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2063 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(2));
2065 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2067 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(3));
2071 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(0));
2079 * OLEDD_TrackStateChange()
2081 * This method is invoked while a drag and drop operation is in effect.
2082 * It is used to notify the drop target/drop source callbacks when
2083 * the state of the keyboard or mouse button change.
2086 * trackerInfo - Pointer to the structure identifying the
2087 * drag & drop operation that is currently
2090 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2093 * Ask the drop source what to do with the operation.
2095 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2096 trackerInfo->dropSource,
2097 trackerInfo->escPressed,
2098 trackerInfo->dwKeyState);
2101 * All the return valued will stop the operation except the S_OK
2104 if (trackerInfo->returnValue!=S_OK)
2107 * Make sure the message loop in DoDragDrop stops
2109 trackerInfo->trackingDone = TRUE;
2112 * Release the mouse in case the drop target decides to show a popup
2113 * or a menu or something.
2118 * If we end-up over a target, drop the object in the target or
2119 * inform the target that the operation was cancelled.
2121 if (trackerInfo->curDragTarget)
2123 switch (trackerInfo->returnValue)
2126 * If the source wants us to complete the operation, we tell
2127 * the drop target that we just dropped the object in it.
2129 case DRAGDROP_S_DROP:
2130 if (*trackerInfo->pdwEffect != DROPEFFECT_NONE)
2131 IDropTarget_Drop(trackerInfo->curDragTarget,
2132 trackerInfo->dataObject,
2133 trackerInfo->dwKeyState,
2134 trackerInfo->curMousePos,
2135 trackerInfo->pdwEffect);
2137 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2141 * If the source told us that we should cancel, fool the drop
2142 * target by telling it that the mouse left it's window.
2143 * Also set the drop effect to "NONE" in case the application
2144 * ignores the result of DoDragDrop.
2146 case DRAGDROP_S_CANCEL:
2147 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2148 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2156 * OLEDD_GetButtonState()
2158 * This method will use the current state of the keyboard to build
2159 * a button state mask equivalent to the one passed in the
2160 * WM_MOUSEMOVE wParam.
2162 static DWORD OLEDD_GetButtonState(void)
2164 BYTE keyboardState[256];
2167 GetKeyboardState(keyboardState);
2169 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2170 keyMask |= MK_SHIFT;
2172 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2173 keyMask |= MK_CONTROL;
2175 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2176 keyMask |= MK_LBUTTON;
2178 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2179 keyMask |= MK_RBUTTON;
2181 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2182 keyMask |= MK_MBUTTON;
2188 * OLEDD_GetButtonState()
2190 * This method will read the default value of the registry key in
2191 * parameter and extract a DWORD value from it. The registry key value
2192 * can be in a string key or a DWORD key.
2195 * regKey - Key to read the default value from
2196 * pdwValue - Pointer to the location where the DWORD
2197 * value is returned. This value is not modified
2198 * if the value is not found.
2201 static void OLEUTL_ReadRegistryDWORDValue(
2206 DWORD cbData = sizeof(buffer);
2210 lres = RegQueryValueExW(regKey,
2217 if (lres==ERROR_SUCCESS)
2222 *pdwValue = *(DWORD*)buffer;
2227 *pdwValue = (DWORD)strtoulW(buffer, NULL, 10);
2233 /******************************************************************************
2236 * The operation of this function is documented literally in the WinAPI
2237 * documentation to involve a QueryInterface for the IViewObject interface,
2238 * followed by a call to IViewObject::Draw.
2240 HRESULT WINAPI OleDraw(
2247 IViewObject *viewobject;
2249 hres = IUnknown_QueryInterface(pUnk,
2251 (void**)&viewobject);
2253 if (SUCCEEDED(hres))
2257 rectl.left = lprcBounds->left;
2258 rectl.right = lprcBounds->right;
2259 rectl.top = lprcBounds->top;
2260 rectl.bottom = lprcBounds->bottom;
2261 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2263 IViewObject_Release(viewobject);
2268 return DV_E_NOIVIEWOBJECT;
2272 /***********************************************************************
2273 * OleTranslateAccelerator [OLE32.@]
2275 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2276 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2280 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2282 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2283 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2288 /******************************************************************************
2289 * OleCreate [OLE32.@]
2292 HRESULT WINAPI OleCreate(
2296 LPFORMATETC pFormatEtc,
2297 LPOLECLIENTSITE pClientSite,
2302 IUnknown * pUnk = NULL;
2303 IOleObject *pOleObject = NULL;
2305 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid),
2306 debugstr_guid(riid), renderopt, pFormatEtc, pClientSite, pStg, ppvObj);
2308 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, riid, (LPVOID*)&pUnk);
2310 if (SUCCEEDED(hres))
2311 hres = IStorage_SetClass(pStg, rclsid);
2313 if (pClientSite && SUCCEEDED(hres))
2315 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2316 if (SUCCEEDED(hres))
2319 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2323 if (SUCCEEDED(hres))
2325 IPersistStorage * pPS;
2326 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2328 TRACE("trying to set stg %p\n", pStg);
2329 hres = IPersistStorage_InitNew(pPS, pStg);
2330 TRACE("-- result 0x%08x\n", hres);
2331 IPersistStorage_Release(pPS);
2335 if (pClientSite && SUCCEEDED(hres))
2337 TRACE("trying to set clientsite %p\n", pClientSite);
2338 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2339 TRACE("-- result 0x%08x\n", hres);
2343 IOleObject_Release(pOleObject);
2345 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2348 IRunnableObject *pRunnable;
2349 IOleCache *pOleCache;
2352 hres2 = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2353 if (SUCCEEDED(hres2))
2355 hres = IRunnableObject_Run(pRunnable, NULL);
2356 IRunnableObject_Release(pRunnable);
2359 if (SUCCEEDED(hres))
2361 hres2 = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2362 if (SUCCEEDED(hres2))
2365 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2366 IOleCache_Release(pOleCache);
2371 if (FAILED(hres) && pUnk)
2373 IUnknown_Release(pUnk);
2379 TRACE("-- %p\n", pUnk);
2383 /******************************************************************************
2384 * OleGetAutoConvert [OLE32.@]
2386 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2388 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2390 WCHAR buf[CHARS_IN_GUID];
2394 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2399 if (RegQueryValueW(hkey, NULL, buf, &len))
2401 res = REGDB_E_KEYMISSING;
2404 res = CLSIDFromString(buf, pClsidNew);
2406 if (hkey) RegCloseKey(hkey);
2410 /******************************************************************************
2411 * OleSetAutoConvert [OLE32.@]
2413 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2415 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2417 WCHAR szClsidNew[CHARS_IN_GUID];
2420 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2422 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2425 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2426 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2428 res = REGDB_E_WRITEREGDB;
2433 if (hkey) RegCloseKey(hkey);
2437 /******************************************************************************
2438 * OleDoAutoConvert [OLE32.@]
2440 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2442 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2446 /******************************************************************************
2447 * OleIsRunning [OLE32.@]
2449 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2451 IRunnableObject *pRunnable;
2455 TRACE("(%p)\n", pObject);
2457 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2460 running = IRunnableObject_IsRunning(pRunnable);
2461 IRunnableObject_Release(pRunnable);
2465 /***********************************************************************
2466 * OleNoteObjectVisible [OLE32.@]
2468 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2470 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2471 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2475 /***********************************************************************
2476 * OLE_FreeClipDataArray [internal]
2479 * frees the data associated with an array of CLIPDATAs
2481 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2484 for (i = 0; i < count; i++)
2485 if (pClipDataArray[i].pClipData)
2486 CoTaskMemFree(pClipDataArray[i].pClipData);
2489 /***********************************************************************
2490 * PropSysAllocString [OLE32.@]
2492 * Basically a copy of SysAllocStringLen.
2494 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2498 WCHAR* stringBuffer;
2503 len = lstrlenW(str);
2505 * Find the length of the buffer passed-in, in bytes.
2507 bufferSize = len * sizeof (WCHAR);
2510 * Allocate a new buffer to hold the string.
2511 * Don't forget to keep an empty spot at the beginning of the
2512 * buffer for the character count and an extra character at the
2515 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2516 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2519 * If the memory allocation failed, return a null pointer.
2525 * Copy the length of the string in the placeholder.
2527 *newBuffer = bufferSize;
2530 * Skip the byte count.
2534 memcpy(newBuffer, str, bufferSize);
2537 * Make sure that there is a nul character at the end of the
2540 stringBuffer = (WCHAR*)newBuffer;
2541 stringBuffer[len] = '\0';
2543 return stringBuffer;
2546 /***********************************************************************
2547 * PropSysFreeString [OLE32.@]
2549 * Copy of SysFreeString.
2551 void WINAPI PropSysFreeString(LPOLESTR str)
2553 DWORD* bufferPointer;
2555 /* NULL is a valid parameter */
2559 * We have to be careful when we free a BSTR pointer, it points to
2560 * the beginning of the string but it skips the byte count contained
2561 * before the string.
2563 bufferPointer = (DWORD*)str;
2568 * Free the memory from its "real" origin.
2570 HeapFree(GetProcessHeap(), 0, bufferPointer);
2573 /******************************************************************************
2574 * Check if a PROPVARIANT's type is valid.
2576 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2603 case VT_STREAMED_OBJECT:
2604 case VT_STORED_OBJECT:
2605 case VT_BLOB_OBJECT:
2608 case VT_I2|VT_VECTOR:
2609 case VT_I4|VT_VECTOR:
2610 case VT_R4|VT_VECTOR:
2611 case VT_R8|VT_VECTOR:
2612 case VT_CY|VT_VECTOR:
2613 case VT_DATE|VT_VECTOR:
2614 case VT_BSTR|VT_VECTOR:
2615 case VT_ERROR|VT_VECTOR:
2616 case VT_BOOL|VT_VECTOR:
2617 case VT_VARIANT|VT_VECTOR:
2618 case VT_UI1|VT_VECTOR:
2619 case VT_UI2|VT_VECTOR:
2620 case VT_UI4|VT_VECTOR:
2621 case VT_I8|VT_VECTOR:
2622 case VT_UI8|VT_VECTOR:
2623 case VT_LPSTR|VT_VECTOR:
2624 case VT_LPWSTR|VT_VECTOR:
2625 case VT_FILETIME|VT_VECTOR:
2626 case VT_CF|VT_VECTOR:
2627 case VT_CLSID|VT_VECTOR:
2630 WARN("Bad type %d\n", vt);
2631 return STG_E_INVALIDPARAMETER;
2634 /***********************************************************************
2635 * PropVariantClear [OLE32.@]
2637 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2641 TRACE("(%p)\n", pvar);
2646 hr = PROPVARIANT_ValidateType(pvar->vt);
2671 case VT_STREAMED_OBJECT:
2673 case VT_STORED_OBJECT:
2674 if (pvar->u.pStream)
2675 IUnknown_Release(pvar->u.pStream);
2680 /* pick an arbitrary typed pointer - we don't care about the type
2681 * as we are just freeing it */
2682 CoTaskMemFree(pvar->u.puuid);
2685 case VT_BLOB_OBJECT:
2686 CoTaskMemFree(pvar->u.blob.pBlobData);
2689 if (pvar->u.bstrVal)
2690 PropSysFreeString(pvar->u.bstrVal);
2693 if (pvar->u.pclipdata)
2695 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2696 CoTaskMemFree(pvar->u.pclipdata);
2700 if (pvar->vt & VT_VECTOR)
2704 switch (pvar->vt & ~VT_VECTOR)
2707 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2710 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2713 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2714 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2717 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2718 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2721 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2722 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2725 if (pvar->vt & ~VT_VECTOR)
2727 /* pick an arbitrary VT_VECTOR structure - they all have the same
2729 CoTaskMemFree(pvar->u.capropvar.pElems);
2733 WARN("Invalid/unsupported type %d\n", pvar->vt);
2736 ZeroMemory(pvar, sizeof(*pvar));
2741 /***********************************************************************
2742 * PropVariantCopy [OLE32.@]
2744 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2745 const PROPVARIANT *pvarSrc) /* [in] */
2750 TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt);
2752 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2756 /* this will deal with most cases */
2757 *pvarDest = *pvarSrc;
2781 case VT_STREAMED_OBJECT:
2783 case VT_STORED_OBJECT:
2784 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2787 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2788 *pvarDest->u.puuid = *pvarSrc->u.puuid;
2791 len = strlen(pvarSrc->u.pszVal);
2792 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2793 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2796 len = lstrlenW(pvarSrc->u.pwszVal);
2797 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2798 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2801 case VT_BLOB_OBJECT:
2802 if (pvarSrc->u.blob.pBlobData)
2804 len = pvarSrc->u.blob.cbSize;
2805 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2806 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2810 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2813 if (pvarSrc->u.pclipdata)
2815 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2816 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
2817 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
2818 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
2819 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
2820 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2824 if (pvarSrc->vt & VT_VECTOR)
2829 switch(pvarSrc->vt & ~VT_VECTOR)
2831 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2832 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2833 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2834 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2835 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2836 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2837 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2838 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2839 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2840 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2841 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2842 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2843 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2844 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2845 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2846 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2847 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2848 case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break;
2849 case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break;
2850 case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break;
2851 case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break;
2854 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2855 return E_INVALIDARG;
2857 len = pvarSrc->u.capropvar.cElems;
2858 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2859 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2861 for (i = 0; i < len; i++)
2862 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2864 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2866 FIXME("Copy clipformats\n");
2868 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2870 for (i = 0; i < len; i++)
2871 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2873 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2876 for (i = 0; i < len; i++)
2878 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2879 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2880 memcpy(pvarDest->u.calpstr.pElems[i],
2881 pvarSrc->u.calpstr.pElems[i], strLen);
2884 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2887 for (i = 0; i < len; i++)
2889 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2891 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2892 memcpy(pvarDest->u.calpstr.pElems[i],
2893 pvarSrc->u.calpstr.pElems[i], strLen);
2897 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2900 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2906 /***********************************************************************
2907 * FreePropVariantArray [OLE32.@]
2909 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2910 PROPVARIANT *rgvars) /* [in/out] */
2914 TRACE("(%u, %p)\n", cVariants, rgvars);
2917 return E_INVALIDARG;
2919 for(i = 0; i < cVariants; i++)
2920 PropVariantClear(&rgvars[i]);
2925 /******************************************************************************
2926 * DllDebugObjectRPCHook (OLE32.@)
2927 * turns on and off internal debugging, pointer is only used on macintosh
2930 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)