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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
50 #include "compobj_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(ole);
55 WINE_DECLARE_DEBUG_CHANNEL(accel);
57 /******************************************************************************
58 * These are static/global variables and internal data structures that the
59 * OLE module uses to maintain it's state.
61 typedef struct tagDropTargetNode
64 IDropTarget* dropTarget;
65 struct tagDropTargetNode* prevDropTarget;
66 struct tagDropTargetNode* nextDropTarget;
69 typedef struct tagTrackerWindowInfo
71 IDataObject* dataObject;
72 IDropSource* dropSource;
79 HWND curTargetHWND; /* window the mouse is hovering over */
80 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
81 IDropTarget* curDragTarget;
82 POINTL curMousePos; /* current position of the mouse in screen coordinates */
83 DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
86 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
88 HWND hwndFrame; /* The containers frame window */
89 HWND hwndActiveObject; /* The active objects window */
90 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
91 HMENU hmenuCombined; /* The combined menu */
92 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
95 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
97 DWORD tid; /* Thread Id */
98 HANDLE hHeap; /* Heap this is allocated from */
99 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
100 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
101 struct tagOleMenuHookItem *next;
104 static OleMenuHookItem *hook_list;
107 * This is the lock count on the OLE library. It is controlled by the
108 * OLEInitialize/OLEUninitialize methods.
110 static ULONG OLE_moduleLockCount = 0;
113 * Name of our registered window class.
115 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
118 * This is the head of the Drop target container.
120 static DropTargetNode* targetListHead = NULL;
122 /******************************************************************************
123 * These are the prototypes of miscelaneous utility methods
125 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
127 /******************************************************************************
128 * These are the prototypes of the utility methods used to manage a shared menu
130 static void OLEMenu_Initialize(void);
131 static void OLEMenu_UnInitialize(void);
132 BOOL OLEMenu_InstallHooks( DWORD tid );
133 BOOL OLEMenu_UnInstallHooks( DWORD tid );
134 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
135 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
136 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
137 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
138 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
140 /******************************************************************************
141 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
143 extern void OLEClipbrd_UnInitialize(void);
144 extern void OLEClipbrd_Initialize(void);
146 /******************************************************************************
147 * These are the prototypes of the utility methods used for OLE Drag n Drop
149 static void OLEDD_Initialize(void);
150 static void OLEDD_UnInitialize(void);
151 static void OLEDD_InsertDropTarget(
152 DropTargetNode* nodeToAdd);
153 static DropTargetNode* OLEDD_ExtractDropTarget(
155 static DropTargetNode* OLEDD_FindDropTarget(
157 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
162 static void OLEDD_TrackMouseMove(
163 TrackerWindowInfo* trackerInfo);
164 static void OLEDD_TrackStateChange(
165 TrackerWindowInfo* trackerInfo);
166 static DWORD OLEDD_GetButtonState(void);
169 /******************************************************************************
170 * OleBuildVersion [OLE2.1]
171 * OleBuildVersion [OLE32.@]
173 DWORD WINAPI OleBuildVersion(void)
175 TRACE("Returning version %d, build %d.\n", rmm, rup);
176 return (rmm<<16)+rup;
179 /***********************************************************************
180 * OleInitialize (OLE2.2)
181 * OleInitialize (OLE32.@)
183 HRESULT WINAPI OleInitialize(LPVOID reserved)
187 TRACE("(%p)\n", reserved);
190 * The first duty of the OleInitialize is to initialize the COM libraries.
192 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
195 * If the CoInitializeEx call failed, the OLE libraries can't be
202 * Then, it has to initialize the OLE specific modules.
206 * Object linking and Embedding
207 * In-place activation
209 if (OLE_moduleLockCount==0)
212 * Initialize the libraries.
214 TRACE("() - Initializing the OLE libraries\n");
219 OLEClipbrd_Initialize();
229 OLEMenu_Initialize();
233 * Then, we increase the lock count on the OLE module.
235 OLE_moduleLockCount++;
240 /******************************************************************************
241 * OleUninitialize [OLE2.3]
242 * OleUninitialize [OLE32.@]
244 void WINAPI OleUninitialize(void)
249 * Decrease the lock count on the OLE module.
251 OLE_moduleLockCount--;
254 * If we hit the bottom of the lock stack, free the libraries.
256 if (OLE_moduleLockCount==0)
259 * Actually free the libraries.
261 TRACE("() - Freeing the last reference count\n");
266 OLEClipbrd_UnInitialize();
271 OLEDD_UnInitialize();
276 OLEMenu_UnInitialize();
280 * Then, uninitialize the COM libraries.
285 /******************************************************************************
286 * OleInitializeWOW [OLE32.@]
288 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
289 FIXME("(0x%08lx, 0x%08lx),stub!\n",x, y);
293 /***********************************************************************
294 * RegisterDragDrop (OLE32.@)
296 HRESULT WINAPI RegisterDragDrop(
298 LPDROPTARGET pDropTarget)
300 DropTargetNode* dropTargetInfo;
302 TRACE("(%p,%p)\n", hwnd, pDropTarget);
308 * First, check if the window is already registered.
310 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
312 if (dropTargetInfo!=NULL)
313 return DRAGDROP_E_ALREADYREGISTERED;
316 * If it's not there, we can add it. We first create a node for it.
318 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
320 if (dropTargetInfo==NULL)
321 return E_OUTOFMEMORY;
323 dropTargetInfo->hwndTarget = hwnd;
324 dropTargetInfo->prevDropTarget = NULL;
325 dropTargetInfo->nextDropTarget = NULL;
328 * Don't forget that this is an interface pointer, need to nail it down since
329 * we keep a copy of it.
331 dropTargetInfo->dropTarget = pDropTarget;
332 IDropTarget_AddRef(dropTargetInfo->dropTarget);
334 OLEDD_InsertDropTarget(dropTargetInfo);
339 /***********************************************************************
340 * RevokeDragDrop (OLE32.@)
342 HRESULT WINAPI RevokeDragDrop(
345 DropTargetNode* dropTargetInfo;
347 TRACE("(%p)\n", hwnd);
350 * First, check if the window is already registered.
352 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
355 * If it ain't in there, it's an error.
357 if (dropTargetInfo==NULL)
358 return DRAGDROP_E_NOTREGISTERED;
361 * If it's in there, clean-up it's used memory and
364 IDropTarget_Release(dropTargetInfo->dropTarget);
365 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
370 /***********************************************************************
371 * OleRegGetUserType (OLE32.@)
373 * This implementation of OleRegGetUserType ignores the dwFormOfType
374 * parameter and always returns the full name of the object. This is
375 * not too bad since this is the case for many objects because of the
376 * way they are registered.
378 HRESULT WINAPI OleRegGetUserType(
381 LPOLESTR* pszUserType)
391 * Initialize the out parameter.
396 * Build the key name we're looking for
398 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
399 clsid->Data1, clsid->Data2, clsid->Data3,
400 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
401 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
403 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
406 * Open the class id Key
408 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
412 if (hres != ERROR_SUCCESS)
413 return REGDB_E_CLASSNOTREG;
416 * Retrieve the size of the name string.
420 hres = RegQueryValueExA(clsidKey,
427 if (hres!=ERROR_SUCCESS)
429 RegCloseKey(clsidKey);
430 return REGDB_E_READREGDB;
434 * Allocate a buffer for the registry value.
436 *pszUserType = CoTaskMemAlloc(cbData*2);
438 if (*pszUserType==NULL)
440 RegCloseKey(clsidKey);
441 return E_OUTOFMEMORY;
444 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
448 RegCloseKey(clsidKey);
449 CoTaskMemFree(*pszUserType);
451 return E_OUTOFMEMORY;
454 hres = RegQueryValueExA(clsidKey,
461 RegCloseKey(clsidKey);
464 if (hres!=ERROR_SUCCESS)
466 CoTaskMemFree(*pszUserType);
469 retVal = REGDB_E_READREGDB;
473 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
476 HeapFree(GetProcessHeap(), 0, buffer);
481 /***********************************************************************
482 * DoDragDrop [OLE32.@]
484 HRESULT WINAPI DoDragDrop (
485 IDataObject *pDataObject, /* [in] ptr to the data obj */
486 IDropSource* pDropSource, /* [in] ptr to the source obj */
487 DWORD dwOKEffect, /* [in] effects allowed by the source */
488 DWORD *pdwEffect) /* [out] ptr to effects of the source */
490 TrackerWindowInfo trackerInfo;
491 HWND hwndTrackWindow;
494 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
497 * Setup the drag n drop tracking window.
499 if (!IsValidInterface((LPUNKNOWN)pDropSource))
502 trackerInfo.dataObject = pDataObject;
503 trackerInfo.dropSource = pDropSource;
504 trackerInfo.dwOKEffect = dwOKEffect;
505 trackerInfo.pdwEffect = pdwEffect;
506 trackerInfo.trackingDone = FALSE;
507 trackerInfo.escPressed = FALSE;
508 trackerInfo.curDragTargetHWND = 0;
509 trackerInfo.curTargetHWND = 0;
510 trackerInfo.curDragTarget = 0;
512 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
515 CW_USEDEFAULT, CW_USEDEFAULT,
516 CW_USEDEFAULT, CW_USEDEFAULT,
520 (LPVOID)&trackerInfo);
522 if (hwndTrackWindow!=0)
525 * Capture the mouse input
527 SetCapture(hwndTrackWindow);
532 * Pump messages. All mouse input should go the the capture window.
534 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
536 trackerInfo.curMousePos.x = msg.pt.x;
537 trackerInfo.curMousePos.y = msg.pt.y;
538 trackerInfo.dwKeyState = OLEDD_GetButtonState();
540 if ( (msg.message >= WM_KEYFIRST) &&
541 (msg.message <= WM_KEYLAST) )
544 * When keyboard messages are sent to windows on this thread, we
545 * want to ignore notify the drop source that the state changed.
546 * in the case of the Escape key, we also notify the drop source
547 * we give it a special meaning.
549 if ( (msg.message==WM_KEYDOWN) &&
550 (msg.wParam==VK_ESCAPE) )
552 trackerInfo.escPressed = TRUE;
556 * Notify the drop source.
558 OLEDD_TrackStateChange(&trackerInfo);
563 * Dispatch the messages only when it's not a keyboard message.
565 DispatchMessageA(&msg);
569 /* re-post the quit message to outer message loop */
570 if (msg.message == WM_QUIT)
571 PostQuitMessage(msg.wParam);
573 * Destroy the temporary window.
575 DestroyWindow(hwndTrackWindow);
577 return trackerInfo.returnValue;
583 /***********************************************************************
584 * OleQueryLinkFromData [OLE32.@]
586 HRESULT WINAPI OleQueryLinkFromData(
587 IDataObject* pSrcDataObject)
589 FIXME("(%p),stub!\n", pSrcDataObject);
593 /***********************************************************************
594 * OleRegGetMiscStatus [OLE32.@]
596 HRESULT WINAPI OleRegGetMiscStatus(
608 * Initialize the out parameter.
613 * Build the key name we're looking for
615 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
616 clsid->Data1, clsid->Data2, clsid->Data3,
617 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
618 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
620 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
623 * Open the class id Key
625 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
629 if (result != ERROR_SUCCESS)
630 return REGDB_E_CLASSNOTREG;
635 result = RegOpenKeyA(clsidKey,
640 if (result != ERROR_SUCCESS)
642 RegCloseKey(clsidKey);
643 return REGDB_E_READREGDB;
647 * Read the default value
649 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
652 * Open the key specific to the requested aspect.
654 sprintf(keyName, "%ld", dwAspect);
656 result = RegOpenKeyA(miscStatusKey,
660 if (result == ERROR_SUCCESS)
662 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
663 RegCloseKey(aspectKey);
669 RegCloseKey(miscStatusKey);
670 RegCloseKey(clsidKey);
675 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
679 const IEnumOLEVERBVtbl *lpvtbl;
686 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
687 IEnumOLEVERB *iface, REFIID riid, void **ppv)
689 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
690 if (IsEqualIID(riid, &IID_IUnknown) ||
691 IsEqualIID(riid, &IID_IEnumOLEVERB))
693 IUnknown_AddRef(iface);
697 return E_NOINTERFACE;
700 static ULONG WINAPI EnumOLEVERB_AddRef(
703 EnumOLEVERB *This = (EnumOLEVERB *)iface;
705 return InterlockedIncrement(&This->ref);
708 static ULONG WINAPI EnumOLEVERB_Release(
711 EnumOLEVERB *This = (EnumOLEVERB *)iface;
712 LONG refs = InterlockedDecrement(&This->ref);
716 RegCloseKey(This->hkeyVerb);
717 HeapFree(GetProcessHeap(), 0, This);
722 static HRESULT WINAPI EnumOLEVERB_Next(
723 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
726 EnumOLEVERB *This = (EnumOLEVERB *)iface;
729 TRACE("(%ld, %p, %p)\n", celt, rgelt, pceltFetched);
734 for (; celt; celt--, rgelt++)
739 LPWSTR pwszMenuFlags;
741 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
742 if (res == ERROR_NO_MORE_ITEMS)
747 else if (res != ERROR_SUCCESS)
749 ERR("RegEnumKeyW failed with error %ld\n", res);
750 hr = REGDB_E_READREGDB;
753 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
754 if (res != ERROR_SUCCESS)
756 ERR("RegQueryValueW failed with error %ld\n", res);
757 hr = REGDB_E_READREGDB;
760 pwszOLEVERB = CoTaskMemAlloc(cbData);
766 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
767 if (res != ERROR_SUCCESS)
769 ERR("RegQueryValueW failed with error %ld\n", res);
770 hr = REGDB_E_READREGDB;
771 CoTaskMemFree(pwszOLEVERB);
775 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
776 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
779 hr = OLEOBJ_E_INVALIDVERB;
780 CoTaskMemFree(pwszOLEVERB);
783 /* nul terminate the name string and advance to first character */
784 *pwszMenuFlags = '\0';
786 pwszAttribs = strchrW(pwszMenuFlags, ',');
789 hr = OLEOBJ_E_INVALIDVERB;
790 CoTaskMemFree(pwszOLEVERB);
793 /* nul terminate the menu string and advance to first character */
797 /* fill out structure for this verb */
798 rgelt->lVerb = atolW(wszSubKey);
799 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
800 rgelt->fuFlags = atolW(pwszMenuFlags);
801 rgelt->grfAttribs = atolW(pwszAttribs);
810 static HRESULT WINAPI EnumOLEVERB_Skip(
811 IEnumOLEVERB *iface, ULONG celt)
813 EnumOLEVERB *This = (EnumOLEVERB *)iface;
815 TRACE("(%ld)\n", celt);
821 static HRESULT WINAPI EnumOLEVERB_Reset(
824 EnumOLEVERB *This = (EnumOLEVERB *)iface;
832 static HRESULT WINAPI EnumOLEVERB_Clone(
834 IEnumOLEVERB **ppenum)
836 EnumOLEVERB *This = (EnumOLEVERB *)iface;
838 TRACE("(%p)\n", ppenum);
839 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
840 return HRESULT_FROM_WIN32(GetLastError());
841 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
844 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
846 EnumOLEVERB_QueryInterface,
855 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
857 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
860 RegCloseKey(hkeyVerb);
861 return E_OUTOFMEMORY;
863 This->lpvtbl = &EnumOLEVERB_VTable;
866 This->hkeyVerb = hkeyVerb;
867 *ppenum = (IEnumOLEVERB *)&This->lpvtbl;
871 /***********************************************************************
872 * OleRegEnumVerbs [OLE32.@]
874 * Enumerates verbs associated with a class stored in the registry.
877 * clsid [I] Class ID to enumerate the verbs for.
878 * ppenum [O] Enumerator.
882 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
883 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
884 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
885 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
887 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
892 static const WCHAR wszVerb[] = {'V','e','r','b',0};
894 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
896 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
899 if (res == REGDB_E_CLASSNOTREG)
900 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
901 else if (res == REGDB_E_KEYMISSING)
902 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
904 ERR("failed to open Verbs key for CLSID %s with error %ld\n",
905 debugstr_guid(clsid), res);
909 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
910 NULL, NULL, NULL, NULL, NULL, NULL);
911 if (res != ERROR_SUCCESS)
913 ERR("failed to get subkey count with error %ld\n", GetLastError());
914 return REGDB_E_READREGDB;
919 WARN("class %s has no verbs\n", debugstr_guid(clsid));
920 RegCloseKey(hkeyVerb);
921 return OLEOBJ_E_NOVERBS;
924 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
927 /******************************************************************************
928 * OleSetContainedObject [OLE32.@]
930 HRESULT WINAPI OleSetContainedObject(
934 IRunnableObject* runnable = NULL;
937 TRACE("(%p,%x)\n", pUnknown, fContained);
939 hres = IUnknown_QueryInterface(pUnknown,
940 &IID_IRunnableObject,
945 hres = IRunnableObject_SetContainedObject(runnable, fContained);
947 IRunnableObject_Release(runnable);
955 /******************************************************************************
958 HRESULT WINAPI OleLoad(
961 LPOLECLIENTSITE pClientSite,
964 IPersistStorage* persistStorage = NULL;
965 IOleObject* oleObject = NULL;
969 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
972 * TODO, Conversion ... OleDoAutoConvert
976 * Get the class ID for the object.
978 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
981 * Now, try and create the handler for the object
983 hres = CoCreateInstance(&storageInfo.clsid,
985 CLSCTX_INPROC_HANDLER,
990 * If that fails, as it will most times, load the default
995 hres = OleCreateDefaultHandler(&storageInfo.clsid,
1002 * If we couldn't find a handler... this is bad. Abort the whole thing.
1008 * Inform the new object of it's client site.
1010 hres = IOleObject_SetClientSite(oleObject, pClientSite);
1013 * Initialize the object with it's IPersistStorage interface.
1015 hres = IOleObject_QueryInterface(oleObject,
1016 &IID_IPersistStorage,
1017 (void**)&persistStorage);
1019 if (SUCCEEDED(hres))
1021 IPersistStorage_Load(persistStorage, pStg);
1023 IPersistStorage_Release(persistStorage);
1024 persistStorage = NULL;
1028 * Return the requested interface to the caller.
1030 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
1033 * Cleanup interfaces used internally
1035 IOleObject_Release(oleObject);
1040 /***********************************************************************
1043 HRESULT WINAPI OleSave(
1044 LPPERSISTSTORAGE pPS,
1051 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1054 * First, we transfer the class ID (if available)
1056 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1058 if (SUCCEEDED(hres))
1060 WriteClassStg(pStg, &objectClass);
1064 * Then, we ask the object to save itself to the
1065 * storage. If it is successful, we commit the storage.
1067 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1069 if (SUCCEEDED(hres))
1071 IStorage_Commit(pStg,
1079 /******************************************************************************
1080 * OleLockRunning [OLE32.@]
1082 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1084 IRunnableObject* runnable = NULL;
1087 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1089 hres = IUnknown_QueryInterface(pUnknown,
1090 &IID_IRunnableObject,
1093 if (SUCCEEDED(hres))
1095 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1097 IRunnableObject_Release(runnable);
1102 return E_INVALIDARG;
1106 /**************************************************************************
1107 * Internal methods to manage the shared OLE menu in response to the
1108 * OLE***MenuDescriptor API
1112 * OLEMenu_Initialize()
1114 * Initializes the OLEMENU data structures.
1116 static void OLEMenu_Initialize()
1121 * OLEMenu_UnInitialize()
1123 * Releases the OLEMENU data structures.
1125 static void OLEMenu_UnInitialize()
1129 /*************************************************************************
1130 * OLEMenu_InstallHooks
1131 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1133 * RETURNS: TRUE if message hooks were successfully installed
1136 BOOL OLEMenu_InstallHooks( DWORD tid )
1138 OleMenuHookItem *pHookItem = NULL;
1140 /* Create an entry for the hook table */
1141 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1142 sizeof(OleMenuHookItem)) ) )
1145 pHookItem->tid = tid;
1146 pHookItem->hHeap = GetProcessHeap();
1148 /* Install a thread scope message hook for WH_GETMESSAGE */
1149 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1150 0, GetCurrentThreadId() );
1151 if ( !pHookItem->GetMsg_hHook )
1154 /* Install a thread scope message hook for WH_CALLWNDPROC */
1155 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1156 0, GetCurrentThreadId() );
1157 if ( !pHookItem->CallWndProc_hHook )
1160 /* Insert the hook table entry */
1161 pHookItem->next = hook_list;
1162 hook_list = pHookItem;
1167 /* Unhook any hooks */
1168 if ( pHookItem->GetMsg_hHook )
1169 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1170 if ( pHookItem->CallWndProc_hHook )
1171 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1172 /* Release the hook table entry */
1173 HeapFree(pHookItem->hHeap, 0, pHookItem );
1178 /*************************************************************************
1179 * OLEMenu_UnInstallHooks
1180 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1182 * RETURNS: TRUE if message hooks were successfully installed
1185 BOOL OLEMenu_UnInstallHooks( DWORD tid )
1187 OleMenuHookItem *pHookItem = NULL;
1188 OleMenuHookItem **ppHook = &hook_list;
1192 if ((*ppHook)->tid == tid)
1194 pHookItem = *ppHook;
1195 *ppHook = pHookItem->next;
1198 ppHook = &(*ppHook)->next;
1200 if (!pHookItem) return FALSE;
1202 /* Uninstall the hooks installed for this thread */
1203 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1205 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1208 /* Release the hook table entry */
1209 HeapFree(pHookItem->hHeap, 0, pHookItem );
1214 /* Release the hook table entry */
1215 HeapFree(pHookItem->hHeap, 0, pHookItem );
1220 /*************************************************************************
1221 * OLEMenu_IsHookInstalled
1222 * Tests if OLEMenu hooks have been installed for a thread
1224 * RETURNS: The pointer and index of the hook table entry for the tid
1225 * NULL and -1 for the index if no hooks were installed for this thread
1227 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1229 OleMenuHookItem *pHookItem = NULL;
1231 /* Do a simple linear search for an entry whose tid matches ours.
1232 * We really need a map but efficiency is not a concern here. */
1233 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1235 if ( tid == pHookItem->tid )
1242 /***********************************************************************
1243 * OLEMenu_FindMainMenuIndex
1245 * Used by OLEMenu API to find the top level group a menu item belongs to.
1246 * On success pnPos contains the index of the item in the top level menu group
1248 * RETURNS: TRUE if the ID was found, FALSE on failure
1250 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1254 nItems = GetMenuItemCount( hMainMenu );
1256 for (i = 0; i < nItems; i++)
1260 /* Is the current item a submenu? */
1261 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1263 /* If the handle is the same we're done */
1264 if ( hsubmenu == hPopupMenu )
1270 /* Recursively search without updating pnPos */
1271 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1283 /***********************************************************************
1284 * OLEMenu_SetIsServerMenu
1286 * Checks whether a popup menu belongs to a shared menu group which is
1287 * owned by the server, and sets the menu descriptor state accordingly.
1288 * All menu messages from these groups should be routed to the server.
1290 * RETURNS: TRUE if the popup menu is part of a server owned group
1291 * FALSE if the popup menu is part of a container owned group
1293 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1295 UINT nPos = 0, nWidth, i;
1297 pOleMenuDescriptor->bIsServerItem = FALSE;
1299 /* Don't bother searching if the popup is the combined menu itself */
1300 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1303 /* Find the menu item index in the shared OLE menu that this item belongs to */
1304 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1307 /* The group widths array has counts for the number of elements
1308 * in the groups File, Edit, Container, Object, Window, Help.
1309 * The Edit, Object & Help groups belong to the server object
1310 * and the other three belong to the container.
1311 * Loop through the group widths and locate the group we are a member of.
1313 for ( i = 0, nWidth = 0; i < 6; i++ )
1315 nWidth += pOleMenuDescriptor->mgw.width[i];
1316 if ( nPos < nWidth )
1318 /* Odd elements are server menu widths */
1319 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1324 return pOleMenuDescriptor->bIsServerItem;
1327 /*************************************************************************
1328 * OLEMenu_CallWndProc
1329 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1330 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1332 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1334 LPCWPSTRUCT pMsg = NULL;
1335 HOLEMENU hOleMenu = 0;
1336 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1337 OleMenuHookItem *pHookItem = NULL;
1340 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1342 /* Check if we're being asked to process the message */
1343 if ( HC_ACTION != code )
1346 /* Retrieve the current message being dispatched from lParam */
1347 pMsg = (LPCWPSTRUCT)lParam;
1349 /* Check if the message is destined for a window we are interested in:
1350 * If the window has an OLEMenu property we may need to dispatch
1351 * the menu message to its active objects window instead. */
1353 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1357 /* Get the menu descriptor */
1358 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1359 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1362 /* Process menu messages */
1363 switch( pMsg->message )
1367 /* Reset the menu descriptor state */
1368 pOleMenuDescriptor->bIsServerItem = FALSE;
1370 /* Send this message to the server as well */
1371 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1372 pMsg->message, pMsg->wParam, pMsg->lParam );
1376 case WM_INITMENUPOPUP:
1378 /* Save the state for whether this is a server owned menu */
1379 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1385 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1386 if ( fuFlags & MF_SYSMENU )
1389 /* Save the state for whether this is a server owned popup menu */
1390 else if ( fuFlags & MF_POPUP )
1391 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1398 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1399 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1400 goto NEXTHOOK; /* Not a menu message */
1409 /* If the message was for the server dispatch it accordingly */
1410 if ( pOleMenuDescriptor->bIsServerItem )
1412 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1413 pMsg->message, pMsg->wParam, pMsg->lParam );
1417 if ( pOleMenuDescriptor )
1418 GlobalUnlock( hOleMenu );
1420 /* Lookup the hook item for the current thread */
1421 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1423 /* This should never fail!! */
1424 WARN("could not retrieve hHook for current thread!\n" );
1428 /* Pass on the message to the next hooker */
1429 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1432 /*************************************************************************
1433 * OLEMenu_GetMsgProc
1434 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1435 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1437 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1440 HOLEMENU hOleMenu = 0;
1441 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1442 OleMenuHookItem *pHookItem = NULL;
1445 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1447 /* Check if we're being asked to process a messages */
1448 if ( HC_ACTION != code )
1451 /* Retrieve the current message being dispatched from lParam */
1452 pMsg = (LPMSG)lParam;
1454 /* Check if the message is destined for a window we are interested in:
1455 * If the window has an OLEMenu property we may need to dispatch
1456 * the menu message to its active objects window instead. */
1458 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1462 /* Process menu messages */
1463 switch( pMsg->message )
1467 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1469 goto NEXTHOOK; /* Not a menu message */
1476 /* Get the menu descriptor */
1477 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1478 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1481 /* If the message was for the server dispatch it accordingly */
1482 if ( pOleMenuDescriptor->bIsServerItem )
1484 /* Change the hWnd in the message to the active objects hWnd.
1485 * The message loop which reads this message will automatically
1486 * dispatch it to the embedded objects window. */
1487 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1491 if ( pOleMenuDescriptor )
1492 GlobalUnlock( hOleMenu );
1494 /* Lookup the hook item for the current thread */
1495 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1497 /* This should never fail!! */
1498 WARN("could not retrieve hHook for current thread!\n" );
1502 /* Pass on the message to the next hooker */
1503 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1506 /***********************************************************************
1507 * OleCreateMenuDescriptor [OLE32.@]
1508 * Creates an OLE menu descriptor for OLE to use when dispatching
1509 * menu messages and commands.
1512 * hmenuCombined - Handle to the objects combined menu
1513 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1516 HOLEMENU WINAPI OleCreateMenuDescriptor(
1517 HMENU hmenuCombined,
1518 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1521 OleMenuDescriptor *pOleMenuDescriptor;
1524 if ( !hmenuCombined || !lpMenuWidths )
1527 /* Create an OLE menu descriptor */
1528 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1529 sizeof(OleMenuDescriptor) ) ) )
1532 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1533 if ( !pOleMenuDescriptor )
1536 /* Initialize menu group widths and hmenu */
1537 for ( i = 0; i < 6; i++ )
1538 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1540 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1541 pOleMenuDescriptor->bIsServerItem = FALSE;
1542 GlobalUnlock( hOleMenu );
1547 /***********************************************************************
1548 * OleDestroyMenuDescriptor [OLE32.@]
1549 * Destroy the shared menu descriptor
1551 HRESULT WINAPI OleDestroyMenuDescriptor(
1552 HOLEMENU hmenuDescriptor)
1554 if ( hmenuDescriptor )
1555 GlobalFree( hmenuDescriptor );
1559 /***********************************************************************
1560 * OleSetMenuDescriptor [OLE32.@]
1561 * Installs or removes OLE dispatching code for the containers frame window.
1564 * hOleMenu Handle to composite menu descriptor
1565 * hwndFrame Handle to containers frame window
1566 * hwndActiveObject Handle to objects in-place activation window
1567 * lpFrame Pointer to IOleInPlaceFrame on containers window
1568 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1571 * S_OK - menu installed correctly
1572 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1575 * The lpFrame and lpActiveObject parameters are currently ignored
1576 * OLE should install context sensitive help F1 filtering for the app when
1577 * these are non null.
1579 HRESULT WINAPI OleSetMenuDescriptor(
1582 HWND hwndActiveObject,
1583 LPOLEINPLACEFRAME lpFrame,
1584 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1586 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1589 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1590 return E_INVALIDARG;
1592 if ( lpFrame || lpActiveObject )
1594 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1602 /* Set up a message hook to intercept the containers frame window messages.
1603 * The message filter is responsible for dispatching menu messages from the
1604 * shared menu which are intended for the object.
1607 if ( hOleMenu ) /* Want to install dispatching code */
1609 /* If OLEMenu hooks are already installed for this thread, fail
1610 * Note: This effectively means that OleSetMenuDescriptor cannot
1611 * be called twice in succession on the same frame window
1612 * without first calling it with a null hOleMenu to uninstall */
1613 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1616 /* Get the menu descriptor */
1617 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1618 if ( !pOleMenuDescriptor )
1619 return E_UNEXPECTED;
1621 /* Update the menu descriptor */
1622 pOleMenuDescriptor->hwndFrame = hwndFrame;
1623 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1625 GlobalUnlock( hOleMenu );
1626 pOleMenuDescriptor = NULL;
1628 /* Add a menu descriptor windows property to the frame window */
1629 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1631 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1632 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1635 else /* Want to uninstall dispatching code */
1637 /* Uninstall the hooks */
1638 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1641 /* Remove the menu descriptor property from the frame window */
1642 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1648 /******************************************************************************
1649 * IsAccelerator [OLE32.@]
1650 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1652 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1657 if(!lpMsg) return FALSE;
1660 WARN_(accel)("NULL accel handle\n");
1663 if((lpMsg->message != WM_KEYDOWN &&
1664 lpMsg->message != WM_KEYUP &&
1665 lpMsg->message != WM_SYSKEYDOWN &&
1666 lpMsg->message != WM_SYSKEYUP &&
1667 lpMsg->message != WM_CHAR)) return FALSE;
1668 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1669 if (NULL == lpAccelTbl)
1673 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1675 WARN_(accel)("CopyAcceleratorTableW failed\n");
1676 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1680 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1681 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1682 hAccel, cAccelEntries,
1683 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1684 for(i = 0; i < cAccelEntries; i++)
1686 if(lpAccelTbl[i].key != lpMsg->wParam)
1689 if(lpMsg->message == WM_CHAR)
1691 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1693 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1699 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1702 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1703 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1704 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1705 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1706 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1707 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1708 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1712 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1714 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1715 { /* ^^ ALT pressed */
1716 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1724 WARN_(accel)("couldn't translate accelerator key\n");
1725 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1729 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1730 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1734 /***********************************************************************
1735 * ReleaseStgMedium [OLE32.@]
1737 void WINAPI ReleaseStgMedium(
1740 switch (pmedium->tymed)
1744 if ( (pmedium->pUnkForRelease==0) &&
1745 (pmedium->u.hGlobal!=0) )
1746 GlobalFree(pmedium->u.hGlobal);
1751 if (pmedium->u.lpszFileName!=0)
1753 if (pmedium->pUnkForRelease==0)
1755 DeleteFileW(pmedium->u.lpszFileName);
1758 CoTaskMemFree(pmedium->u.lpszFileName);
1764 if (pmedium->u.pstm!=0)
1766 IStream_Release(pmedium->u.pstm);
1770 case TYMED_ISTORAGE:
1772 if (pmedium->u.pstg!=0)
1774 IStorage_Release(pmedium->u.pstg);
1780 if ( (pmedium->pUnkForRelease==0) &&
1781 (pmedium->u.hBitmap!=0) )
1782 DeleteObject(pmedium->u.hBitmap);
1787 if ( (pmedium->pUnkForRelease==0) &&
1788 (pmedium->u.hMetaFilePict!=0) )
1790 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1791 DeleteMetaFile(pMP->hMF);
1792 GlobalUnlock(pmedium->u.hMetaFilePict);
1793 GlobalFree(pmedium->u.hMetaFilePict);
1799 if ( (pmedium->pUnkForRelease==0) &&
1800 (pmedium->u.hEnhMetaFile!=0) )
1802 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1810 pmedium->tymed=TYMED_NULL;
1813 * After cleaning up, the unknown is released
1815 if (pmedium->pUnkForRelease!=0)
1817 IUnknown_Release(pmedium->pUnkForRelease);
1818 pmedium->pUnkForRelease = 0;
1823 * OLEDD_Initialize()
1825 * Initializes the OLE drag and drop data structures.
1827 static void OLEDD_Initialize()
1831 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1832 wndClass.style = CS_GLOBALCLASS;
1833 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
1834 wndClass.cbClsExtra = 0;
1835 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1836 wndClass.hCursor = 0;
1837 wndClass.hbrBackground = 0;
1838 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1840 RegisterClassA (&wndClass);
1844 * OLEDD_UnInitialize()
1846 * Releases the OLE drag and drop data structures.
1848 static void OLEDD_UnInitialize()
1851 * Simply empty the list.
1853 while (targetListHead!=NULL)
1855 RevokeDragDrop(targetListHead->hwndTarget);
1860 * OLEDD_InsertDropTarget()
1862 * Insert the target node in the tree.
1864 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1866 DropTargetNode* curNode;
1867 DropTargetNode** parentNodeLink;
1870 * Iterate the tree to find the insertion point.
1872 curNode = targetListHead;
1873 parentNodeLink = &targetListHead;
1875 while (curNode!=NULL)
1877 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1880 * If the node we want to add has a smaller HWND, go left
1882 parentNodeLink = &curNode->prevDropTarget;
1883 curNode = curNode->prevDropTarget;
1885 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1888 * If the node we want to add has a larger HWND, go right
1890 parentNodeLink = &curNode->nextDropTarget;
1891 curNode = curNode->nextDropTarget;
1896 * The item was found in the list. It shouldn't have been there
1904 * If we get here, we have found a spot for our item. The parentNodeLink
1905 * pointer points to the pointer that we have to modify.
1906 * The curNode should be NULL. We just have to establish the link and Voila!
1908 assert(curNode==NULL);
1909 assert(parentNodeLink!=NULL);
1910 assert(*parentNodeLink==NULL);
1912 *parentNodeLink=nodeToAdd;
1916 * OLEDD_ExtractDropTarget()
1918 * Removes the target node from the tree.
1920 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1922 DropTargetNode* curNode;
1923 DropTargetNode** parentNodeLink;
1926 * Iterate the tree to find the insertion point.
1928 curNode = targetListHead;
1929 parentNodeLink = &targetListHead;
1931 while (curNode!=NULL)
1933 if (hwndOfTarget<curNode->hwndTarget)
1936 * If the node we want to add has a smaller HWND, go left
1938 parentNodeLink = &curNode->prevDropTarget;
1939 curNode = curNode->prevDropTarget;
1941 else if (hwndOfTarget>curNode->hwndTarget)
1944 * If the node we want to add has a larger HWND, go right
1946 parentNodeLink = &curNode->nextDropTarget;
1947 curNode = curNode->nextDropTarget;
1952 * The item was found in the list. Detach it from it's parent and
1953 * re-insert it's kids in the tree.
1955 assert(parentNodeLink!=NULL);
1956 assert(*parentNodeLink==curNode);
1959 * We arbitrately re-attach the left sub-tree to the parent.
1961 *parentNodeLink = curNode->prevDropTarget;
1964 * And we re-insert the right subtree
1966 if (curNode->nextDropTarget!=NULL)
1968 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1972 * The node we found is still a valid node once we complete
1973 * the unlinking of the kids.
1975 curNode->nextDropTarget=NULL;
1976 curNode->prevDropTarget=NULL;
1983 * If we get here, the node is not in the tree
1989 * OLEDD_FindDropTarget()
1991 * Finds information about the drop target.
1993 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1995 DropTargetNode* curNode;
1998 * Iterate the tree to find the HWND value.
2000 curNode = targetListHead;
2002 while (curNode!=NULL)
2004 if (hwndOfTarget<curNode->hwndTarget)
2007 * If the node we want to add has a smaller HWND, go left
2009 curNode = curNode->prevDropTarget;
2011 else if (hwndOfTarget>curNode->hwndTarget)
2014 * If the node we want to add has a larger HWND, go right
2016 curNode = curNode->nextDropTarget;
2021 * The item was found in the list.
2028 * If we get here, the item is not in the list
2034 * OLEDD_DragTrackerWindowProc()
2036 * This method is the WindowProcedure of the drag n drop tracking
2037 * window. During a drag n Drop operation, an invisible window is created
2038 * to receive the user input and act upon it. This procedure is in charge
2042 #define DRAG_TIMER_ID 1
2044 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
2054 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
2056 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
2057 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
2064 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
2070 case WM_LBUTTONDOWN:
2071 case WM_MBUTTONDOWN:
2072 case WM_RBUTTONDOWN:
2074 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongA(hwnd, 0));
2079 KillTimer(hwnd, DRAG_TIMER_ID);
2085 * This is a window proc after all. Let's call the default.
2087 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
2091 * OLEDD_TrackMouseMove()
2093 * This method is invoked while a drag and drop operation is in effect.
2094 * it will generate the appropriate callbacks in the drop source
2095 * and drop target. It will also provide the expected feedback to
2099 * trackerInfo - Pointer to the structure identifying the
2100 * drag & drop operation that is currently
2103 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
2105 HWND hwndNewTarget = 0;
2110 * Get the handle of the window under the mouse
2112 pt.x = trackerInfo->curMousePos.x;
2113 pt.y = trackerInfo->curMousePos.y;
2114 hwndNewTarget = WindowFromPoint(pt);
2117 * Every time, we re-initialize the effects passed to the
2118 * IDropTarget to the effects allowed by the source.
2120 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2123 * If we are hovering over the same target as before, send the
2124 * DragOver notification
2126 if ( (trackerInfo->curDragTarget != 0) &&
2127 (trackerInfo->curTargetHWND == hwndNewTarget) )
2129 IDropTarget_DragOver(trackerInfo->curDragTarget,
2130 trackerInfo->dwKeyState,
2131 trackerInfo->curMousePos,
2132 trackerInfo->pdwEffect);
2136 DropTargetNode* newDropTargetNode = 0;
2139 * If we changed window, we have to notify our old target and check for
2142 if (trackerInfo->curDragTarget!=0)
2144 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2148 * Make sure we're hovering over a window.
2150 if (hwndNewTarget!=0)
2153 * Find-out if there is a drag target under the mouse
2155 HWND nexttar = hwndNewTarget;
2156 trackerInfo->curTargetHWND = hwndNewTarget;
2159 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
2160 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
2161 if(nexttar) hwndNewTarget = nexttar;
2163 trackerInfo->curDragTargetHWND = hwndNewTarget;
2164 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
2167 * If there is, notify it that we just dragged-in
2169 if (trackerInfo->curDragTarget!=0)
2171 IDropTarget_DragEnter(trackerInfo->curDragTarget,
2172 trackerInfo->dataObject,
2173 trackerInfo->dwKeyState,
2174 trackerInfo->curMousePos,
2175 trackerInfo->pdwEffect);
2181 * The mouse is not over a window so we don't track anything.
2183 trackerInfo->curDragTargetHWND = 0;
2184 trackerInfo->curTargetHWND = 0;
2185 trackerInfo->curDragTarget = 0;
2190 * Now that we have done that, we have to tell the source to give
2191 * us feedback on the work being done by the target. If we don't
2192 * have a target, simulate no effect.
2194 if (trackerInfo->curDragTarget==0)
2196 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2199 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2200 *trackerInfo->pdwEffect);
2203 * When we ask for feedback from the drop source, sometimes it will
2204 * do all the necessary work and sometimes it will not handle it
2205 * when that's the case, we must display the standard drag and drop
2208 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2210 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2212 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2214 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2216 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2218 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2220 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2224 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2230 * OLEDD_TrackStateChange()
2232 * This method is invoked while a drag and drop operation is in effect.
2233 * It is used to notify the drop target/drop source callbacks when
2234 * the state of the keyboard or mouse button change.
2237 * trackerInfo - Pointer to the structure identifying the
2238 * drag & drop operation that is currently
2241 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2244 * Ask the drop source what to do with the operation.
2246 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2247 trackerInfo->dropSource,
2248 trackerInfo->escPressed,
2249 trackerInfo->dwKeyState);
2252 * All the return valued will stop the operation except the S_OK
2255 if (trackerInfo->returnValue!=S_OK)
2258 * Make sure the message loop in DoDragDrop stops
2260 trackerInfo->trackingDone = TRUE;
2263 * Release the mouse in case the drop target decides to show a popup
2264 * or a menu or something.
2269 * If we end-up over a target, drop the object in the target or
2270 * inform the target that the operation was cancelled.
2272 if (trackerInfo->curDragTarget!=0)
2274 switch (trackerInfo->returnValue)
2277 * If the source wants us to complete the operation, we tell
2278 * the drop target that we just dropped the object in it.
2280 case DRAGDROP_S_DROP:
2282 IDropTarget_Drop(trackerInfo->curDragTarget,
2283 trackerInfo->dataObject,
2284 trackerInfo->dwKeyState,
2285 trackerInfo->curMousePos,
2286 trackerInfo->pdwEffect);
2290 * If the source told us that we should cancel, fool the drop
2291 * target by telling it that the mouse left it's window.
2292 * Also set the drop effect to "NONE" in case the application
2293 * ignores the result of DoDragDrop.
2295 case DRAGDROP_S_CANCEL:
2296 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2297 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2305 * OLEDD_GetButtonState()
2307 * This method will use the current state of the keyboard to build
2308 * a button state mask equivalent to the one passed in the
2309 * WM_MOUSEMOVE wParam.
2311 static DWORD OLEDD_GetButtonState()
2313 BYTE keyboardState[256];
2316 GetKeyboardState(keyboardState);
2318 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2319 keyMask |= MK_SHIFT;
2321 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2322 keyMask |= MK_CONTROL;
2324 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2325 keyMask |= MK_LBUTTON;
2327 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2328 keyMask |= MK_RBUTTON;
2330 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2331 keyMask |= MK_MBUTTON;
2337 * OLEDD_GetButtonState()
2339 * This method will read the default value of the registry key in
2340 * parameter and extract a DWORD value from it. The registry key value
2341 * can be in a string key or a DWORD key.
2344 * regKey - Key to read the default value from
2345 * pdwValue - Pointer to the location where the DWORD
2346 * value is returned. This value is not modified
2347 * if the value is not found.
2350 static void OLEUTL_ReadRegistryDWORDValue(
2359 lres = RegQueryValueExA(regKey,
2366 if (lres==ERROR_SUCCESS)
2371 *pdwValue = *(DWORD*)buffer;
2376 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2382 /******************************************************************************
2385 * The operation of this function is documented literally in the WinAPI
2386 * documentation to involve a QueryInterface for the IViewObject interface,
2387 * followed by a call to IViewObject::Draw.
2389 HRESULT WINAPI OleDraw(
2396 IViewObject *viewobject;
2398 hres = IUnknown_QueryInterface(pUnk,
2400 (void**)&viewobject);
2402 if (SUCCEEDED(hres))
2406 rectl.left = lprcBounds->left;
2407 rectl.right = lprcBounds->right;
2408 rectl.top = lprcBounds->top;
2409 rectl.bottom = lprcBounds->bottom;
2410 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2412 IViewObject_Release(viewobject);
2417 return DV_E_NOIVIEWOBJECT;
2421 /***********************************************************************
2422 * OleTranslateAccelerator [OLE32.@]
2424 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2425 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2429 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2431 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2432 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2437 /******************************************************************************
2438 * OleCreate [OLE32.@]
2441 HRESULT WINAPI OleCreate(
2445 LPFORMATETC pFormatEtc,
2446 LPOLECLIENTSITE pClientSite,
2450 HRESULT hres, hres1;
2451 IUnknown * pUnk = NULL;
2453 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2455 if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk))))
2460 IPersistStorage * pPS;
2461 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE))))
2463 TRACE("trying to set clientsite %p\n", pClientSite);
2464 hres1 = IOleObject_SetClientSite(pOE, pClientSite);
2465 TRACE("-- result 0x%08lx\n", hres1);
2466 IOleObject_Release(pOE);
2468 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2470 TRACE("trying to set stg %p\n", pStg);
2471 hres1 = IPersistStorage_InitNew(pPS, pStg);
2472 TRACE("-- result 0x%08lx\n", hres1);
2473 IPersistStorage_Release(pPS);
2480 TRACE("-- %p\n", pUnk);
2484 /******************************************************************************
2485 * OleSetAutoConvert [OLE32.@]
2487 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2489 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2491 WCHAR szClsidNew[CHARS_IN_GUID];
2494 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2496 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2499 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2500 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2502 res = REGDB_E_WRITEREGDB;
2507 if (hkey) RegCloseKey(hkey);
2511 /******************************************************************************
2512 * OleDoAutoConvert [OLE32.@]
2514 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2516 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2520 /******************************************************************************
2521 * OleIsRunning [OLE32.@]
2523 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2525 IRunnableObject *pRunnable;
2529 TRACE("(%p)\n", pObject);
2531 hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2534 running = IRunnableObject_IsRunning(pRunnable);
2535 IRunnableObject_Release(pRunnable);
2539 /***********************************************************************
2540 * OLE_FreeClipDataArray [internal]
2543 * frees the data associated with an array of CLIPDATAs
2545 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2548 for (i = 0; i < count; i++)
2549 if (pClipDataArray[i].pClipData)
2550 CoTaskMemFree(pClipDataArray[i].pClipData);
2553 /***********************************************************************
2554 * PropSysAllocString [OLE32.@]
2556 * Basically a copy of SysAllocStringLen.
2558 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2562 WCHAR* stringBuffer;
2567 len = lstrlenW(str);
2569 * Find the length of the buffer passed-in in bytes.
2571 bufferSize = len * sizeof (WCHAR);
2574 * Allocate a new buffer to hold the string.
2575 * don't forget to keep an empty spot at the beginning of the
2576 * buffer for the character count and an extra character at the
2579 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2580 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2583 * If the memory allocation failed, return a null pointer.
2589 * Copy the length of the string in the placeholder.
2591 *newBuffer = bufferSize;
2594 * Skip the byte count.
2599 * Copy the information in the buffer.
2600 * Since it is valid to pass a NULL pointer here, we'll initialize the
2601 * buffer to nul if it is the case.
2604 memcpy(newBuffer, str, bufferSize);
2606 memset(newBuffer, 0, bufferSize);
2609 * Make sure that there is a nul character at the end of the
2612 stringBuffer = (WCHAR*)newBuffer;
2613 stringBuffer[len] = L'\0';
2615 return (LPWSTR)stringBuffer;
2618 /***********************************************************************
2619 * PropSysFreeString [OLE32.@]
2621 * Copy of SysFreeString.
2623 void WINAPI PropSysFreeString(LPOLESTR str)
2625 DWORD* bufferPointer;
2627 /* NULL is a valid parameter */
2631 * We have to be careful when we free a BSTR pointer, it points to
2632 * the beginning of the string but it skips the byte count contained
2633 * before the string.
2635 bufferPointer = (DWORD*)str;
2640 * Free the memory from its "real" origin.
2642 HeapFree(GetProcessHeap(), 0, bufferPointer);
2645 /******************************************************************************
2646 * Check if a PROPVARIANT's type is valid.
2648 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2674 case VT_STREAMED_OBJECT:
2675 case VT_STORED_OBJECT:
2676 case VT_BLOB_OBJECT:
2679 case VT_I2|VT_VECTOR:
2680 case VT_I4|VT_VECTOR:
2681 case VT_R4|VT_VECTOR:
2682 case VT_R8|VT_VECTOR:
2683 case VT_CY|VT_VECTOR:
2684 case VT_DATE|VT_VECTOR:
2685 case VT_BSTR|VT_VECTOR:
2686 case VT_ERROR|VT_VECTOR:
2687 case VT_BOOL|VT_VECTOR:
2688 case VT_VARIANT|VT_VECTOR:
2689 case VT_UI1|VT_VECTOR:
2690 case VT_UI2|VT_VECTOR:
2691 case VT_UI4|VT_VECTOR:
2692 case VT_I8|VT_VECTOR:
2693 case VT_UI8|VT_VECTOR:
2694 case VT_LPSTR|VT_VECTOR:
2695 case VT_LPWSTR|VT_VECTOR:
2696 case VT_FILETIME|VT_VECTOR:
2697 case VT_CF|VT_VECTOR:
2698 case VT_CLSID|VT_VECTOR:
2701 WARN("Bad type %d\n", vt);
2702 return STG_E_INVALIDPARAMETER;
2705 /***********************************************************************
2706 * PropVariantClear [OLE32.@]
2708 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2712 TRACE("(%p)\n", pvar);
2717 hr = PROPVARIANT_ValidateType(pvar->vt);
2724 case VT_STREAMED_OBJECT:
2726 case VT_STORED_OBJECT:
2727 if (pvar->u.pStream)
2728 IUnknown_Release(pvar->u.pStream);
2733 /* pick an arbitary typed pointer - we don't care about the type
2734 * as we are just freeing it */
2735 CoTaskMemFree(pvar->u.puuid);
2738 case VT_BLOB_OBJECT:
2739 CoTaskMemFree(pvar->u.blob.pBlobData);
2742 if (pvar->u.bstrVal)
2743 PropSysFreeString(pvar->u.bstrVal);
2746 if (pvar->u.pclipdata)
2748 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2749 CoTaskMemFree(pvar->u.pclipdata);
2753 if (pvar->vt & VT_VECTOR)
2757 switch (pvar->vt & ~VT_VECTOR)
2760 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2763 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2766 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2767 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2770 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2771 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2774 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2775 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2778 if (pvar->vt & ~VT_VECTOR)
2780 /* pick an arbitary VT_VECTOR structure - they all have the same
2782 CoTaskMemFree(pvar->u.capropvar.pElems);
2786 WARN("Invalid/unsupported type %d\n", pvar->vt);
2789 ZeroMemory(pvar, sizeof(*pvar));
2794 /***********************************************************************
2795 * PropVariantCopy [OLE32.@]
2797 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2798 const PROPVARIANT *pvarSrc) /* [in] */
2803 TRACE("(%p, %p)\n", pvarDest, pvarSrc);
2805 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2809 /* this will deal with most cases */
2810 CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2815 case VT_STREAMED_OBJECT:
2817 case VT_STORED_OBJECT:
2818 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2821 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2822 CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2825 len = strlen(pvarSrc->u.pszVal);
2826 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2827 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2830 len = lstrlenW(pvarSrc->u.pwszVal);
2831 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2832 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2835 case VT_BLOB_OBJECT:
2836 if (pvarSrc->u.blob.pBlobData)
2838 len = pvarSrc->u.blob.cbSize;
2839 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2840 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2844 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2847 if (pvarSrc->u.pclipdata)
2849 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2850 CoTaskMemAlloc(len);
2851 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2855 if (pvarSrc->vt & VT_VECTOR)
2860 switch(pvarSrc->vt & ~VT_VECTOR)
2862 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2863 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2864 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2865 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2866 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2867 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2868 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2869 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2870 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2871 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2872 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2873 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2874 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2875 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2876 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2877 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2878 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2879 case VT_BSTR: elemSize = sizeof(*pvarSrc->u.bstrVal); break;
2880 case VT_LPSTR: elemSize = sizeof(*pvarSrc->u.pszVal); break;
2881 case VT_LPWSTR: elemSize = sizeof(*pvarSrc->u.pwszVal); break;
2885 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2886 return E_INVALIDARG;
2888 len = pvarSrc->u.capropvar.cElems;
2889 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2890 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2892 for (i = 0; i < len; i++)
2893 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2895 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2897 FIXME("Copy clipformats\n");
2899 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2901 for (i = 0; i < len; i++)
2902 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2904 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2907 for (i = 0; i < len; i++)
2909 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2910 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2911 memcpy(pvarDest->u.calpstr.pElems[i],
2912 pvarSrc->u.calpstr.pElems[i], strLen);
2915 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2918 for (i = 0; i < len; i++)
2920 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2922 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2923 memcpy(pvarDest->u.calpstr.pElems[i],
2924 pvarSrc->u.calpstr.pElems[i], strLen);
2928 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2931 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2937 /***********************************************************************
2938 * FreePropVariantArray [OLE32.@]
2940 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2941 PROPVARIANT *rgvars) /* [in/out] */
2945 TRACE("(%lu, %p)\n", cVariants, rgvars);
2947 for(i = 0; i < cVariants; i++)
2948 PropVariantClear(&rgvars[i]);
2953 /******************************************************************************
2954 * DllDebugObjectRPCHook (OLE32.@)
2955 * turns on and off internal debugging, pointer is only used on macintosh
2958 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)