HTTP_DealWithProxy: Only add http:// to proxy string when needed.
[wine/multimedia.git] / dlls / ole32 / ole2.c
blob409f3b80b3064dc543a4d056571f08ccddabe404
2 /*
3 * OLE2 library
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1999 Francis Beaudet
7 * Copyright 1999 Noel Borthwick
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
32 #define NONAMELESSUNION
33 #define NONAMELESSSTRUCT
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winerror.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "winnls.h"
40 #include "winreg.h"
41 #include "commctrl.h"
42 #include "ole2.h"
43 #include "ole2ver.h"
44 #include "wownt32.h"
46 #include "wine/winbase16.h"
47 #include "wine/wingdi16.h"
48 #include "wine/winuser16.h"
49 #include "ole32_main.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(accel);
56 #define HICON_16(h32) (LOWORD(h32))
57 #define HICON_32(h16) ((HICON)(ULONG_PTR)(h16))
58 #define HINSTANCE_32(h16) ((HINSTANCE)(ULONG_PTR)(h16))
60 /******************************************************************************
61 * These are static/global variables and internal data structures that the
62 * OLE module uses to maintain it's state.
64 typedef struct tagDropTargetNode
66 HWND hwndTarget;
67 IDropTarget* dropTarget;
68 struct tagDropTargetNode* prevDropTarget;
69 struct tagDropTargetNode* nextDropTarget;
70 } DropTargetNode;
72 typedef struct tagTrackerWindowInfo
74 IDataObject* dataObject;
75 IDropSource* dropSource;
76 DWORD dwOKEffect;
77 DWORD* pdwEffect;
78 BOOL trackingDone;
79 HRESULT returnValue;
81 BOOL escPressed;
82 HWND curTargetHWND; /* window the mouse is hovering over */
83 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
84 IDropTarget* curDragTarget;
85 } TrackerWindowInfo;
87 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
89 HWND hwndFrame; /* The containers frame window */
90 HWND hwndActiveObject; /* The active objects window */
91 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
92 HMENU hmenuCombined; /* The combined menu */
93 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
94 } OleMenuDescriptor;
96 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
98 DWORD tid; /* Thread Id */
99 HANDLE hHeap; /* Heap this is allocated from */
100 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
101 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
102 struct tagOleMenuHookItem *next;
103 } OleMenuHookItem;
105 static OleMenuHookItem *hook_list;
108 * This is the lock count on the OLE library. It is controlled by the
109 * OLEInitialize/OLEUninitialize methods.
111 static ULONG OLE_moduleLockCount = 0;
114 * Name of our registered window class.
116 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
119 * This is the head of the Drop target container.
121 static DropTargetNode* targetListHead = NULL;
123 /******************************************************************************
124 * These are the prototypes of miscelaneous utility methods
126 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
128 /******************************************************************************
129 * These are the prototypes of the utility methods used to manage a shared menu
131 static void OLEMenu_Initialize();
132 static void OLEMenu_UnInitialize();
133 BOOL OLEMenu_InstallHooks( DWORD tid );
134 BOOL OLEMenu_UnInstallHooks( DWORD tid );
135 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
136 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
137 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
138 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
139 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
141 /******************************************************************************
142 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
144 void OLEClipbrd_UnInitialize();
145 void OLEClipbrd_Initialize();
147 /******************************************************************************
148 * These are the prototypes of the utility methods used for OLE Drag n Drop
150 static void OLEDD_Initialize();
151 static void OLEDD_UnInitialize();
152 static void OLEDD_InsertDropTarget(
153 DropTargetNode* nodeToAdd);
154 static DropTargetNode* OLEDD_ExtractDropTarget(
155 HWND hwndOfTarget);
156 static DropTargetNode* OLEDD_FindDropTarget(
157 HWND hwndOfTarget);
158 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
159 HWND hwnd,
160 UINT uMsg,
161 WPARAM wParam,
162 LPARAM lParam);
163 static void OLEDD_TrackMouseMove(
164 TrackerWindowInfo* trackerInfo,
165 POINT mousePos,
166 DWORD keyState);
167 static void OLEDD_TrackStateChange(
168 TrackerWindowInfo* trackerInfo,
169 POINT mousePos,
170 DWORD keyState);
171 static DWORD OLEDD_GetButtonState();
174 /******************************************************************************
175 * OleBuildVersion [OLE2.1]
176 * OleBuildVersion [OLE32.@]
178 DWORD WINAPI OleBuildVersion(void)
180 TRACE("Returning version %d, build %d.\n", rmm, rup);
181 return (rmm<<16)+rup;
184 /***********************************************************************
185 * OleInitialize (OLE2.2)
186 * OleInitialize (OLE32.@)
188 HRESULT WINAPI OleInitialize(LPVOID reserved)
190 HRESULT hr;
192 TRACE("(%p)\n", reserved);
195 * The first duty of the OleInitialize is to initialize the COM libraries.
197 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
200 * If the CoInitializeEx call failed, the OLE libraries can't be
201 * initialized.
203 if (FAILED(hr))
204 return hr;
207 * Then, it has to initialize the OLE specific modules.
208 * This includes:
209 * Clipboard
210 * Drag and Drop
211 * Object linking and Embedding
212 * In-place activation
214 if (OLE_moduleLockCount==0)
217 * Initialize the libraries.
219 TRACE("() - Initializing the OLE libraries\n");
222 * OLE Clipboard
224 OLEClipbrd_Initialize();
227 * Drag and Drop
229 OLEDD_Initialize();
232 * OLE shared menu
234 OLEMenu_Initialize();
238 * Then, we increase the lock count on the OLE module.
240 OLE_moduleLockCount++;
242 return hr;
245 /******************************************************************************
246 * CoGetCurrentProcess [COMPOBJ.34]
247 * CoGetCurrentProcess [OLE32.@]
249 * NOTES
250 * Is DWORD really the correct return type for this function?
252 DWORD WINAPI CoGetCurrentProcess(void)
254 return GetCurrentProcessId();
257 /******************************************************************************
258 * OleUninitialize [OLE2.3]
259 * OleUninitialize [OLE32.@]
261 void WINAPI OleUninitialize(void)
263 TRACE("()\n");
266 * Decrease the lock count on the OLE module.
268 OLE_moduleLockCount--;
271 * If we hit the bottom of the lock stack, free the libraries.
273 if (OLE_moduleLockCount==0)
276 * Actually free the libraries.
278 TRACE("() - Freeing the last reference count\n");
281 * OLE Clipboard
283 OLEClipbrd_UnInitialize();
286 * Drag and Drop
288 OLEDD_UnInitialize();
291 * OLE shared menu
293 OLEMenu_UnInitialize();
297 * Then, uninitialize the COM libraries.
299 CoUninitialize();
302 /******************************************************************************
303 * CoRegisterMessageFilter [OLE32.@]
305 HRESULT WINAPI CoRegisterMessageFilter(
306 LPMESSAGEFILTER lpMessageFilter, /* [in] Pointer to interface */
307 LPMESSAGEFILTER *lplpMessageFilter /* [out] Indirect pointer to prior instance if non-NULL */
309 FIXME("stub\n");
310 if (lplpMessageFilter) {
311 *lplpMessageFilter = NULL;
313 return S_OK;
316 /******************************************************************************
317 * OleInitializeWOW [OLE32.@]
319 HRESULT WINAPI OleInitializeWOW(DWORD x) {
320 FIXME("(0x%08lx),stub!\n",x);
321 return 0;
324 /***********************************************************************
325 * RegisterDragDrop (OLE32.@)
327 HRESULT WINAPI RegisterDragDrop(
328 HWND hwnd,
329 LPDROPTARGET pDropTarget)
331 DropTargetNode* dropTargetInfo;
333 TRACE("(%p,%p)\n", hwnd, pDropTarget);
336 * First, check if the window is already registered.
338 dropTargetInfo = OLEDD_FindDropTarget(hwnd);
340 if (dropTargetInfo!=NULL)
341 return DRAGDROP_E_ALREADYREGISTERED;
344 * If it's not there, we can add it. We first create a node for it.
346 dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
348 if (dropTargetInfo==NULL)
349 return E_OUTOFMEMORY;
351 dropTargetInfo->hwndTarget = hwnd;
352 dropTargetInfo->prevDropTarget = NULL;
353 dropTargetInfo->nextDropTarget = NULL;
356 * Don't forget that this is an interface pointer, need to nail it down since
357 * we keep a copy of it.
359 dropTargetInfo->dropTarget = pDropTarget;
360 IDropTarget_AddRef(dropTargetInfo->dropTarget);
362 OLEDD_InsertDropTarget(dropTargetInfo);
364 return S_OK;
367 /***********************************************************************
368 * RevokeDragDrop (OLE32.@)
370 HRESULT WINAPI RevokeDragDrop(
371 HWND hwnd)
373 DropTargetNode* dropTargetInfo;
375 TRACE("(%p)\n", hwnd);
378 * First, check if the window is already registered.
380 dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
383 * If it ain't in there, it's an error.
385 if (dropTargetInfo==NULL)
386 return DRAGDROP_E_NOTREGISTERED;
389 * If it's in there, clean-up it's used memory and
390 * references
392 IDropTarget_Release(dropTargetInfo->dropTarget);
393 HeapFree(GetProcessHeap(), 0, dropTargetInfo);
395 return S_OK;
398 /***********************************************************************
399 * OleRegGetUserType (OLE32.@)
401 * This implementation of OleRegGetUserType ignores the dwFormOfType
402 * parameter and always returns the full name of the object. This is
403 * not too bad since this is the case for many objects because of the
404 * way they are registered.
406 HRESULT WINAPI OleRegGetUserType(
407 REFCLSID clsid,
408 DWORD dwFormOfType,
409 LPOLESTR* pszUserType)
411 char keyName[60];
412 DWORD dwKeyType;
413 DWORD cbData;
414 HKEY clsidKey;
415 LONG hres;
416 LPBYTE buffer;
417 HRESULT retVal;
419 * Initialize the out parameter.
421 *pszUserType = NULL;
424 * Build the key name we're looking for
426 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
427 clsid->Data1, clsid->Data2, clsid->Data3,
428 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
429 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
431 TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
434 * Open the class id Key
436 hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
437 keyName,
438 &clsidKey);
440 if (hres != ERROR_SUCCESS)
441 return REGDB_E_CLASSNOTREG;
444 * Retrieve the size of the name string.
446 cbData = 0;
448 hres = RegQueryValueExA(clsidKey,
450 NULL,
451 &dwKeyType,
452 NULL,
453 &cbData);
455 if (hres!=ERROR_SUCCESS)
457 RegCloseKey(clsidKey);
458 return REGDB_E_READREGDB;
462 * Allocate a buffer for the registry value.
464 *pszUserType = CoTaskMemAlloc(cbData*2);
466 if (*pszUserType==NULL)
468 RegCloseKey(clsidKey);
469 return E_OUTOFMEMORY;
472 buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
474 if (buffer == NULL)
476 RegCloseKey(clsidKey);
477 CoTaskMemFree(*pszUserType);
478 *pszUserType=NULL;
479 return E_OUTOFMEMORY;
482 hres = RegQueryValueExA(clsidKey,
484 NULL,
485 &dwKeyType,
486 buffer,
487 &cbData);
489 RegCloseKey(clsidKey);
492 if (hres!=ERROR_SUCCESS)
494 CoTaskMemFree(*pszUserType);
495 *pszUserType=NULL;
497 retVal = REGDB_E_READREGDB;
499 else
501 MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
502 retVal = S_OK;
504 HeapFree(GetProcessHeap(), 0, buffer);
506 return retVal;
509 /***********************************************************************
510 * DoDragDrop [OLE32.@]
512 HRESULT WINAPI DoDragDrop (
513 IDataObject *pDataObject, /* [in] ptr to the data obj */
514 IDropSource* pDropSource, /* [in] ptr to the source obj */
515 DWORD dwOKEffect, /* [in] effects allowed by the source */
516 DWORD *pdwEffect) /* [out] ptr to effects of the source */
518 TrackerWindowInfo trackerInfo;
519 HWND hwndTrackWindow;
520 MSG msg;
522 TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
525 * Setup the drag n drop tracking window.
527 if (!IsValidInterface((LPUNKNOWN)pDropSource))
528 return E_INVALIDARG;
530 trackerInfo.dataObject = pDataObject;
531 trackerInfo.dropSource = pDropSource;
532 trackerInfo.dwOKEffect = dwOKEffect;
533 trackerInfo.pdwEffect = pdwEffect;
534 trackerInfo.trackingDone = FALSE;
535 trackerInfo.escPressed = FALSE;
536 trackerInfo.curDragTargetHWND = 0;
537 trackerInfo.curTargetHWND = 0;
538 trackerInfo.curDragTarget = 0;
540 hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
541 "TrackerWindow",
542 WS_POPUP,
543 CW_USEDEFAULT, CW_USEDEFAULT,
544 CW_USEDEFAULT, CW_USEDEFAULT,
548 (LPVOID)&trackerInfo);
550 if (hwndTrackWindow!=0)
553 * Capture the mouse input
555 SetCapture(hwndTrackWindow);
558 * Pump messages. All mouse input should go the the capture window.
560 while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
562 if ( (msg.message >= WM_KEYFIRST) &&
563 (msg.message <= WM_KEYLAST) )
566 * When keyboard messages are sent to windows on this thread, we
567 * want to ignore notify the drop source that the state changed.
568 * in the case of the Escape key, we also notify the drop source
569 * we give it a special meaning.
571 if ( (msg.message==WM_KEYDOWN) &&
572 (msg.wParam==VK_ESCAPE) )
574 trackerInfo.escPressed = TRUE;
578 * Notify the drop source.
580 OLEDD_TrackStateChange(&trackerInfo,
581 msg.pt,
582 OLEDD_GetButtonState());
584 else
587 * Dispatch the messages only when it's not a keyboard message.
589 DispatchMessageA(&msg);
594 * Destroy the temporary window.
596 DestroyWindow(hwndTrackWindow);
598 return trackerInfo.returnValue;
601 return E_FAIL;
604 /***********************************************************************
605 * OleQueryLinkFromData [OLE32.@]
607 HRESULT WINAPI OleQueryLinkFromData(
608 IDataObject* pSrcDataObject)
610 FIXME("(%p),stub!\n", pSrcDataObject);
611 return S_OK;
614 /***********************************************************************
615 * OleRegGetMiscStatus [OLE32.@]
617 HRESULT WINAPI OleRegGetMiscStatus(
618 REFCLSID clsid,
619 DWORD dwAspect,
620 DWORD* pdwStatus)
622 char keyName[60];
623 HKEY clsidKey;
624 HKEY miscStatusKey;
625 HKEY aspectKey;
626 LONG result;
629 * Initialize the out parameter.
631 *pdwStatus = 0;
634 * Build the key name we're looking for
636 sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
637 clsid->Data1, clsid->Data2, clsid->Data3,
638 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
639 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
641 TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
644 * Open the class id Key
646 result = RegOpenKeyA(HKEY_CLASSES_ROOT,
647 keyName,
648 &clsidKey);
650 if (result != ERROR_SUCCESS)
651 return REGDB_E_CLASSNOTREG;
654 * Get the MiscStatus
656 result = RegOpenKeyA(clsidKey,
657 "MiscStatus",
658 &miscStatusKey);
661 if (result != ERROR_SUCCESS)
663 RegCloseKey(clsidKey);
664 return REGDB_E_READREGDB;
668 * Read the default value
670 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
673 * Open the key specific to the requested aspect.
675 sprintf(keyName, "%ld", dwAspect);
677 result = RegOpenKeyA(miscStatusKey,
678 keyName,
679 &aspectKey);
681 if (result == ERROR_SUCCESS)
683 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
684 RegCloseKey(aspectKey);
688 * Cleanup
690 RegCloseKey(miscStatusKey);
691 RegCloseKey(clsidKey);
693 return S_OK;
696 /******************************************************************************
697 * OleSetContainedObject [OLE32.@]
699 HRESULT WINAPI OleSetContainedObject(
700 LPUNKNOWN pUnknown,
701 BOOL fContained)
703 IRunnableObject* runnable = NULL;
704 HRESULT hres;
706 TRACE("(%p,%x), stub!\n", pUnknown, fContained);
708 hres = IUnknown_QueryInterface(pUnknown,
709 &IID_IRunnableObject,
710 (void**)&runnable);
712 if (SUCCEEDED(hres))
714 hres = IRunnableObject_SetContainedObject(runnable, fContained);
716 IRunnableObject_Release(runnable);
718 return hres;
721 return S_OK;
724 /******************************************************************************
725 * OleLoad [OLE32.@]
727 HRESULT WINAPI OleLoad(
728 LPSTORAGE pStg,
729 REFIID riid,
730 LPOLECLIENTSITE pClientSite,
731 LPVOID* ppvObj)
733 IPersistStorage* persistStorage = NULL;
734 IOleObject* oleObject = NULL;
735 STATSTG storageInfo;
736 HRESULT hres;
738 TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
741 * TODO, Conversion ... OleDoAutoConvert
745 * Get the class ID for the object.
747 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
750 * Now, try and create the handler for the object
752 hres = CoCreateInstance(&storageInfo.clsid,
753 NULL,
754 CLSCTX_INPROC_HANDLER,
755 &IID_IOleObject,
756 (void**)&oleObject);
759 * If that fails, as it will most times, load the default
760 * OLE handler.
762 if (FAILED(hres))
764 hres = OleCreateDefaultHandler(&storageInfo.clsid,
765 NULL,
766 &IID_IOleObject,
767 (void**)&oleObject);
771 * If we couldn't find a handler... this is bad. Abort the whole thing.
773 if (FAILED(hres))
774 return hres;
777 * Inform the new object of it's client site.
779 hres = IOleObject_SetClientSite(oleObject, pClientSite);
782 * Initialize the object with it's IPersistStorage interface.
784 hres = IOleObject_QueryInterface(oleObject,
785 &IID_IPersistStorage,
786 (void**)&persistStorage);
788 if (SUCCEEDED(hres))
790 IPersistStorage_Load(persistStorage, pStg);
792 IPersistStorage_Release(persistStorage);
793 persistStorage = NULL;
797 * Return the requested interface to the caller.
799 hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
802 * Cleanup interfaces used internally
804 IOleObject_Release(oleObject);
806 return hres;
809 /***********************************************************************
810 * OleSave [OLE32.@]
812 HRESULT WINAPI OleSave(
813 LPPERSISTSTORAGE pPS,
814 LPSTORAGE pStg,
815 BOOL fSameAsLoad)
817 HRESULT hres;
818 CLSID objectClass;
820 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
823 * First, we transfer the class ID (if available)
825 hres = IPersistStorage_GetClassID(pPS, &objectClass);
827 if (SUCCEEDED(hres))
829 WriteClassStg(pStg, &objectClass);
833 * Then, we ask the object to save itself to the
834 * storage. If it is successful, we commit the storage.
836 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
838 if (SUCCEEDED(hres))
840 IStorage_Commit(pStg,
841 STGC_DEFAULT);
844 return hres;
848 /******************************************************************************
849 * OleLockRunning [OLE32.@]
851 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
853 IRunnableObject* runnable = NULL;
854 HRESULT hres;
856 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
858 hres = IUnknown_QueryInterface(pUnknown,
859 &IID_IRunnableObject,
860 (void**)&runnable);
862 if (SUCCEEDED(hres))
864 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
866 IRunnableObject_Release(runnable);
868 return hres;
870 else
871 return E_INVALIDARG;
875 /**************************************************************************
876 * Internal methods to manage the shared OLE menu in response to the
877 * OLE***MenuDescriptor API
880 /***
881 * OLEMenu_Initialize()
883 * Initializes the OLEMENU data structures.
885 static void OLEMenu_Initialize()
889 /***
890 * OLEMenu_UnInitialize()
892 * Releases the OLEMENU data structures.
894 static void OLEMenu_UnInitialize()
898 /*************************************************************************
899 * OLEMenu_InstallHooks
900 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
902 * RETURNS: TRUE if message hooks were successfully installed
903 * FALSE on failure
905 BOOL OLEMenu_InstallHooks( DWORD tid )
907 OleMenuHookItem *pHookItem = NULL;
909 /* Create an entry for the hook table */
910 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
911 sizeof(OleMenuHookItem)) ) )
912 return FALSE;
914 pHookItem->tid = tid;
915 pHookItem->hHeap = GetProcessHeap();
917 /* Install a thread scope message hook for WH_GETMESSAGE */
918 pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
919 0, GetCurrentThreadId() );
920 if ( !pHookItem->GetMsg_hHook )
921 goto CLEANUP;
923 /* Install a thread scope message hook for WH_CALLWNDPROC */
924 pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
925 0, GetCurrentThreadId() );
926 if ( !pHookItem->CallWndProc_hHook )
927 goto CLEANUP;
929 /* Insert the hook table entry */
930 pHookItem->next = hook_list;
931 hook_list = pHookItem;
933 return TRUE;
935 CLEANUP:
936 /* Unhook any hooks */
937 if ( pHookItem->GetMsg_hHook )
938 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
939 if ( pHookItem->CallWndProc_hHook )
940 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
941 /* Release the hook table entry */
942 HeapFree(pHookItem->hHeap, 0, pHookItem );
944 return FALSE;
947 /*************************************************************************
948 * OLEMenu_UnInstallHooks
949 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
951 * RETURNS: TRUE if message hooks were successfully installed
952 * FALSE on failure
954 BOOL OLEMenu_UnInstallHooks( DWORD tid )
956 OleMenuHookItem *pHookItem = NULL;
957 OleMenuHookItem **ppHook = &hook_list;
959 while (*ppHook)
961 if ((*ppHook)->tid == tid)
963 pHookItem = *ppHook;
964 *ppHook = pHookItem->next;
965 break;
967 ppHook = &(*ppHook)->next;
969 if (!pHookItem) return FALSE;
971 /* Uninstall the hooks installed for this thread */
972 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
973 goto CLEANUP;
974 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
975 goto CLEANUP;
977 /* Release the hook table entry */
978 HeapFree(pHookItem->hHeap, 0, pHookItem );
980 return TRUE;
982 CLEANUP:
983 /* Release the hook table entry */
984 if (pHookItem)
985 HeapFree(pHookItem->hHeap, 0, pHookItem );
987 return FALSE;
990 /*************************************************************************
991 * OLEMenu_IsHookInstalled
992 * Tests if OLEMenu hooks have been installed for a thread
994 * RETURNS: The pointer and index of the hook table entry for the tid
995 * NULL and -1 for the index if no hooks were installed for this thread
997 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
999 OleMenuHookItem *pHookItem = NULL;
1001 /* Do a simple linear search for an entry whose tid matches ours.
1002 * We really need a map but efficiency is not a concern here. */
1003 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1005 if ( tid == pHookItem->tid )
1006 return pHookItem;
1009 return NULL;
1012 /***********************************************************************
1013 * OLEMenu_FindMainMenuIndex
1015 * Used by OLEMenu API to find the top level group a menu item belongs to.
1016 * On success pnPos contains the index of the item in the top level menu group
1018 * RETURNS: TRUE if the ID was found, FALSE on failure
1020 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1022 UINT i, nItems;
1024 nItems = GetMenuItemCount( hMainMenu );
1026 for (i = 0; i < nItems; i++)
1028 HMENU hsubmenu;
1030 /* Is the current item a submenu? */
1031 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1033 /* If the handle is the same we're done */
1034 if ( hsubmenu == hPopupMenu )
1036 if (pnPos)
1037 *pnPos = i;
1038 return TRUE;
1040 /* Recursively search without updating pnPos */
1041 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1043 if (pnPos)
1044 *pnPos = i;
1045 return TRUE;
1050 return FALSE;
1053 /***********************************************************************
1054 * OLEMenu_SetIsServerMenu
1056 * Checks whether a popup menu belongs to a shared menu group which is
1057 * owned by the server, and sets the menu descriptor state accordingly.
1058 * All menu messages from these groups should be routed to the server.
1060 * RETURNS: TRUE if the popup menu is part of a server owned group
1061 * FASE if the popup menu is part of a container owned group
1063 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1065 UINT nPos = 0, nWidth, i;
1067 pOleMenuDescriptor->bIsServerItem = FALSE;
1069 /* Don't bother searching if the popup is the combined menu itself */
1070 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1071 return FALSE;
1073 /* Find the menu item index in the shared OLE menu that this item belongs to */
1074 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1075 return FALSE;
1077 /* The group widths array has counts for the number of elements
1078 * in the groups File, Edit, Container, Object, Window, Help.
1079 * The Edit, Object & Help groups belong to the server object
1080 * and the other three belong to the container.
1081 * Loop through the group widths and locate the group we are a member of.
1083 for ( i = 0, nWidth = 0; i < 6; i++ )
1085 nWidth += pOleMenuDescriptor->mgw.width[i];
1086 if ( nPos < nWidth )
1088 /* Odd elements are server menu widths */
1089 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1090 break;
1094 return pOleMenuDescriptor->bIsServerItem;
1097 /*************************************************************************
1098 * OLEMenu_CallWndProc
1099 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1100 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1102 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1104 LPCWPSTRUCT pMsg = NULL;
1105 HOLEMENU hOleMenu = 0;
1106 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1107 OleMenuHookItem *pHookItem = NULL;
1108 WORD fuFlags;
1110 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1112 /* Check if we're being asked to process the message */
1113 if ( HC_ACTION != code )
1114 goto NEXTHOOK;
1116 /* Retrieve the current message being dispatched from lParam */
1117 pMsg = (LPCWPSTRUCT)lParam;
1119 /* Check if the message is destined for a window we are interested in:
1120 * If the window has an OLEMenu property we may need to dispatch
1121 * the menu message to its active objects window instead. */
1123 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1124 if ( !hOleMenu )
1125 goto NEXTHOOK;
1127 /* Get the menu descriptor */
1128 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1129 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1130 goto NEXTHOOK;
1132 /* Process menu messages */
1133 switch( pMsg->message )
1135 case WM_INITMENU:
1137 /* Reset the menu descriptor state */
1138 pOleMenuDescriptor->bIsServerItem = FALSE;
1140 /* Send this message to the server as well */
1141 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1142 pMsg->message, pMsg->wParam, pMsg->lParam );
1143 goto NEXTHOOK;
1146 case WM_INITMENUPOPUP:
1148 /* Save the state for whether this is a server owned menu */
1149 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1150 break;
1153 case WM_MENUSELECT:
1155 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1156 if ( fuFlags & MF_SYSMENU )
1157 goto NEXTHOOK;
1159 /* Save the state for whether this is a server owned popup menu */
1160 else if ( fuFlags & MF_POPUP )
1161 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1163 break;
1166 case WM_DRAWITEM:
1168 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1169 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1170 goto NEXTHOOK; /* Not a menu message */
1172 break;
1175 default:
1176 goto NEXTHOOK;
1179 /* If the message was for the server dispatch it accordingly */
1180 if ( pOleMenuDescriptor->bIsServerItem )
1182 SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1183 pMsg->message, pMsg->wParam, pMsg->lParam );
1186 NEXTHOOK:
1187 if ( pOleMenuDescriptor )
1188 GlobalUnlock( hOleMenu );
1190 /* Lookup the hook item for the current thread */
1191 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1193 /* This should never fail!! */
1194 WARN("could not retrieve hHook for current thread!\n" );
1195 return 0;
1198 /* Pass on the message to the next hooker */
1199 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1202 /*************************************************************************
1203 * OLEMenu_GetMsgProc
1204 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1205 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1207 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1209 LPMSG pMsg = NULL;
1210 HOLEMENU hOleMenu = 0;
1211 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1212 OleMenuHookItem *pHookItem = NULL;
1213 WORD wCode;
1215 TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1217 /* Check if we're being asked to process a messages */
1218 if ( HC_ACTION != code )
1219 goto NEXTHOOK;
1221 /* Retrieve the current message being dispatched from lParam */
1222 pMsg = (LPMSG)lParam;
1224 /* Check if the message is destined for a window we are interested in:
1225 * If the window has an OLEMenu property we may need to dispatch
1226 * the menu message to its active objects window instead. */
1228 hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1229 if ( !hOleMenu )
1230 goto NEXTHOOK;
1232 /* Process menu messages */
1233 switch( pMsg->message )
1235 case WM_COMMAND:
1237 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1238 if ( wCode )
1239 goto NEXTHOOK; /* Not a menu message */
1240 break;
1242 default:
1243 goto NEXTHOOK;
1246 /* Get the menu descriptor */
1247 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1248 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1249 goto NEXTHOOK;
1251 /* If the message was for the server dispatch it accordingly */
1252 if ( pOleMenuDescriptor->bIsServerItem )
1254 /* Change the hWnd in the message to the active objects hWnd.
1255 * The message loop which reads this message will automatically
1256 * dispatch it to the embedded objects window. */
1257 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1260 NEXTHOOK:
1261 if ( pOleMenuDescriptor )
1262 GlobalUnlock( hOleMenu );
1264 /* Lookup the hook item for the current thread */
1265 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1267 /* This should never fail!! */
1268 WARN("could not retrieve hHook for current thread!\n" );
1269 return FALSE;
1272 /* Pass on the message to the next hooker */
1273 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1276 /***********************************************************************
1277 * OleCreateMenuDescriptor [OLE32.@]
1278 * Creates an OLE menu descriptor for OLE to use when dispatching
1279 * menu messages and commands.
1281 * PARAMS:
1282 * hmenuCombined - Handle to the objects combined menu
1283 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1286 HOLEMENU WINAPI OleCreateMenuDescriptor(
1287 HMENU hmenuCombined,
1288 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1290 HOLEMENU hOleMenu;
1291 OleMenuDescriptor *pOleMenuDescriptor;
1292 int i;
1294 if ( !hmenuCombined || !lpMenuWidths )
1295 return 0;
1297 /* Create an OLE menu descriptor */
1298 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1299 sizeof(OleMenuDescriptor) ) ) )
1300 return 0;
1302 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1303 if ( !pOleMenuDescriptor )
1304 return 0;
1306 /* Initialize menu group widths and hmenu */
1307 for ( i = 0; i < 6; i++ )
1308 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1310 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1311 pOleMenuDescriptor->bIsServerItem = FALSE;
1312 GlobalUnlock( hOleMenu );
1314 return hOleMenu;
1317 /***********************************************************************
1318 * OleDestroyMenuDescriptor [OLE32.@]
1319 * Destroy the shared menu descriptor
1321 HRESULT WINAPI OleDestroyMenuDescriptor(
1322 HOLEMENU hmenuDescriptor)
1324 if ( hmenuDescriptor )
1325 GlobalFree( hmenuDescriptor );
1326 return S_OK;
1329 /***********************************************************************
1330 * OleSetMenuDescriptor [OLE32.@]
1331 * Installs or removes OLE dispatching code for the containers frame window
1332 * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1333 * OLE should install context sensitive help F1 filtering for the app when
1334 * these are non null.
1336 * PARAMS:
1337 * hOleMenu Handle to composite menu descriptor
1338 * hwndFrame Handle to containers frame window
1339 * hwndActiveObject Handle to objects in-place activation window
1340 * lpFrame Pointer to IOleInPlaceFrame on containers window
1341 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1343 * RETURNS:
1344 * S_OK - menu installed correctly
1345 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1347 HRESULT WINAPI OleSetMenuDescriptor(
1348 HOLEMENU hOleMenu,
1349 HWND hwndFrame,
1350 HWND hwndActiveObject,
1351 LPOLEINPLACEFRAME lpFrame,
1352 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1354 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1356 /* Check args */
1357 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1358 return E_INVALIDARG;
1360 if ( lpFrame || lpActiveObject )
1362 FIXME("(%x, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1363 (unsigned int)hOleMenu,
1364 hwndFrame,
1365 hwndActiveObject,
1366 lpFrame,
1367 lpActiveObject);
1370 /* Set up a message hook to intercept the containers frame window messages.
1371 * The message filter is responsible for dispatching menu messages from the
1372 * shared menu which are intended for the object.
1375 if ( hOleMenu ) /* Want to install dispatching code */
1377 /* If OLEMenu hooks are already installed for this thread, fail
1378 * Note: This effectively means that OleSetMenuDescriptor cannot
1379 * be called twice in succession on the same frame window
1380 * without first calling it with a null hOleMenu to uninstall */
1381 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1382 return E_FAIL;
1384 /* Get the menu descriptor */
1385 pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1386 if ( !pOleMenuDescriptor )
1387 return E_UNEXPECTED;
1389 /* Update the menu descriptor */
1390 pOleMenuDescriptor->hwndFrame = hwndFrame;
1391 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1393 GlobalUnlock( hOleMenu );
1394 pOleMenuDescriptor = NULL;
1396 /* Add a menu descriptor windows property to the frame window */
1397 SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1399 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1400 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1401 return E_FAIL;
1403 else /* Want to uninstall dispatching code */
1405 /* Uninstall the hooks */
1406 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1407 return E_FAIL;
1409 /* Remove the menu descriptor property from the frame window */
1410 RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1413 return S_OK;
1416 /******************************************************************************
1417 * IsAccelerator [OLE32.@]
1418 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1420 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1422 /* YES, Accel16! */
1423 LPACCEL16 lpAccelTbl;
1424 int i;
1426 if(!lpMsg) return FALSE;
1427 if (!hAccel || !(lpAccelTbl = (LPACCEL16)LockResource16(HACCEL_16(hAccel))))
1429 WARN_(accel)("invalid accel handle=%p\n", hAccel);
1430 return FALSE;
1432 if((lpMsg->message != WM_KEYDOWN &&
1433 lpMsg->message != WM_KEYUP &&
1434 lpMsg->message != WM_SYSKEYDOWN &&
1435 lpMsg->message != WM_SYSKEYUP &&
1436 lpMsg->message != WM_CHAR)) return FALSE;
1438 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1439 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1440 hAccel, cAccelEntries,
1441 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1442 for(i = 0; i < cAccelEntries; i++)
1444 if(lpAccelTbl[i].key != lpMsg->wParam)
1445 continue;
1447 if(lpMsg->message == WM_CHAR)
1449 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1451 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1452 goto found;
1455 else
1457 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1459 INT mask = 0;
1460 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1461 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1462 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1463 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1464 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1465 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1466 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1468 else
1470 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1472 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1473 { /* ^^ ALT pressed */
1474 TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1475 goto found;
1482 WARN_(accel)("couldn't translate accelerator key\n");
1483 return FALSE;
1485 found:
1486 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1487 return TRUE;
1490 /***********************************************************************
1491 * ReleaseStgMedium [OLE32.@]
1493 void WINAPI ReleaseStgMedium(
1494 STGMEDIUM* pmedium)
1496 switch (pmedium->tymed)
1498 case TYMED_HGLOBAL:
1500 if ( (pmedium->pUnkForRelease==0) &&
1501 (pmedium->u.hGlobal!=0) )
1502 GlobalFree(pmedium->u.hGlobal);
1503 break;
1505 case TYMED_FILE:
1507 if (pmedium->u.lpszFileName!=0)
1509 if (pmedium->pUnkForRelease==0)
1511 DeleteFileW(pmedium->u.lpszFileName);
1514 CoTaskMemFree(pmedium->u.lpszFileName);
1516 break;
1518 case TYMED_ISTREAM:
1520 if (pmedium->u.pstm!=0)
1522 IStream_Release(pmedium->u.pstm);
1524 break;
1526 case TYMED_ISTORAGE:
1528 if (pmedium->u.pstg!=0)
1530 IStorage_Release(pmedium->u.pstg);
1532 break;
1534 case TYMED_GDI:
1536 if ( (pmedium->pUnkForRelease==0) &&
1537 (pmedium->u.hBitmap!=0) )
1538 DeleteObject(pmedium->u.hBitmap);
1539 break;
1541 case TYMED_MFPICT:
1543 if ( (pmedium->pUnkForRelease==0) &&
1544 (pmedium->u.hMetaFilePict!=0) )
1546 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1547 DeleteMetaFile(pMP->hMF);
1548 GlobalUnlock(pmedium->u.hMetaFilePict);
1549 GlobalFree(pmedium->u.hMetaFilePict);
1551 break;
1553 case TYMED_ENHMF:
1555 if ( (pmedium->pUnkForRelease==0) &&
1556 (pmedium->u.hEnhMetaFile!=0) )
1558 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1560 break;
1562 case TYMED_NULL:
1563 default:
1564 break;
1566 pmedium->tymed=TYMED_NULL;
1569 * After cleaning up, the unknown is released
1571 if (pmedium->pUnkForRelease!=0)
1573 IUnknown_Release(pmedium->pUnkForRelease);
1574 pmedium->pUnkForRelease = 0;
1578 /***
1579 * OLEDD_Initialize()
1581 * Initializes the OLE drag and drop data structures.
1583 static void OLEDD_Initialize()
1585 WNDCLASSA wndClass;
1587 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1588 wndClass.style = CS_GLOBALCLASS;
1589 wndClass.lpfnWndProc = (WNDPROC)OLEDD_DragTrackerWindowProc;
1590 wndClass.cbClsExtra = 0;
1591 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
1592 wndClass.hCursor = 0;
1593 wndClass.hbrBackground = 0;
1594 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1596 RegisterClassA (&wndClass);
1599 /***
1600 * OLEDD_UnInitialize()
1602 * Releases the OLE drag and drop data structures.
1604 static void OLEDD_UnInitialize()
1607 * Simply empty the list.
1609 while (targetListHead!=NULL)
1611 RevokeDragDrop(targetListHead->hwndTarget);
1615 /***
1616 * OLEDD_InsertDropTarget()
1618 * Insert the target node in the tree.
1620 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1622 DropTargetNode* curNode;
1623 DropTargetNode** parentNodeLink;
1626 * Iterate the tree to find the insertion point.
1628 curNode = targetListHead;
1629 parentNodeLink = &targetListHead;
1631 while (curNode!=NULL)
1633 if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1636 * If the node we want to add has a smaller HWND, go left
1638 parentNodeLink = &curNode->prevDropTarget;
1639 curNode = curNode->prevDropTarget;
1641 else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1644 * If the node we want to add has a larger HWND, go right
1646 parentNodeLink = &curNode->nextDropTarget;
1647 curNode = curNode->nextDropTarget;
1649 else
1652 * The item was found in the list. It shouldn't have been there
1654 assert(FALSE);
1655 return;
1660 * If we get here, we have found a spot for our item. The parentNodeLink
1661 * pointer points to the pointer that we have to modify.
1662 * The curNode should be NULL. We just have to establish the link and Voila!
1664 assert(curNode==NULL);
1665 assert(parentNodeLink!=NULL);
1666 assert(*parentNodeLink==NULL);
1668 *parentNodeLink=nodeToAdd;
1671 /***
1672 * OLEDD_ExtractDropTarget()
1674 * Removes the target node from the tree.
1676 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1678 DropTargetNode* curNode;
1679 DropTargetNode** parentNodeLink;
1682 * Iterate the tree to find the insertion point.
1684 curNode = targetListHead;
1685 parentNodeLink = &targetListHead;
1687 while (curNode!=NULL)
1689 if (hwndOfTarget<curNode->hwndTarget)
1692 * If the node we want to add has a smaller HWND, go left
1694 parentNodeLink = &curNode->prevDropTarget;
1695 curNode = curNode->prevDropTarget;
1697 else if (hwndOfTarget>curNode->hwndTarget)
1700 * If the node we want to add has a larger HWND, go right
1702 parentNodeLink = &curNode->nextDropTarget;
1703 curNode = curNode->nextDropTarget;
1705 else
1708 * The item was found in the list. Detach it from it's parent and
1709 * re-insert it's kids in the tree.
1711 assert(parentNodeLink!=NULL);
1712 assert(*parentNodeLink==curNode);
1715 * We arbitrately re-attach the left sub-tree to the parent.
1717 *parentNodeLink = curNode->prevDropTarget;
1720 * And we re-insert the right subtree
1722 if (curNode->nextDropTarget!=NULL)
1724 OLEDD_InsertDropTarget(curNode->nextDropTarget);
1728 * The node we found is still a valid node once we complete
1729 * the unlinking of the kids.
1731 curNode->nextDropTarget=NULL;
1732 curNode->prevDropTarget=NULL;
1734 return curNode;
1739 * If we get here, the node is not in the tree
1741 return NULL;
1744 /***
1745 * OLEDD_FindDropTarget()
1747 * Finds information about the drop target.
1749 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1751 DropTargetNode* curNode;
1754 * Iterate the tree to find the HWND value.
1756 curNode = targetListHead;
1758 while (curNode!=NULL)
1760 if (hwndOfTarget<curNode->hwndTarget)
1763 * If the node we want to add has a smaller HWND, go left
1765 curNode = curNode->prevDropTarget;
1767 else if (hwndOfTarget>curNode->hwndTarget)
1770 * If the node we want to add has a larger HWND, go right
1772 curNode = curNode->nextDropTarget;
1774 else
1777 * The item was found in the list.
1779 return curNode;
1784 * If we get here, the item is not in the list
1786 return NULL;
1789 /***
1790 * OLEDD_DragTrackerWindowProc()
1792 * This method is the WindowProcedure of the drag n drop tracking
1793 * window. During a drag n Drop operation, an invisible window is created
1794 * to receive the user input and act upon it. This procedure is in charge
1795 * of this behavior.
1797 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1798 HWND hwnd,
1799 UINT uMsg,
1800 WPARAM wParam,
1801 LPARAM lParam)
1803 switch (uMsg)
1805 case WM_CREATE:
1807 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1809 SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1812 break;
1814 case WM_MOUSEMOVE:
1816 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1817 POINT mousePos;
1820 * Get the current mouse position in screen coordinates.
1822 mousePos.x = LOWORD(lParam);
1823 mousePos.y = HIWORD(lParam);
1824 ClientToScreen(hwnd, &mousePos);
1827 * Track the movement of the mouse.
1829 OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1831 break;
1833 case WM_LBUTTONUP:
1834 case WM_MBUTTONUP:
1835 case WM_RBUTTONUP:
1836 case WM_LBUTTONDOWN:
1837 case WM_MBUTTONDOWN:
1838 case WM_RBUTTONDOWN:
1840 TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1841 POINT mousePos;
1844 * Get the current mouse position in screen coordinates.
1846 mousePos.x = LOWORD(lParam);
1847 mousePos.y = HIWORD(lParam);
1848 ClientToScreen(hwnd, &mousePos);
1851 * Notify everyone that the button state changed
1852 * TODO: Check if the "escape" key was pressed.
1854 OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1856 break;
1861 * This is a window proc after all. Let's call the default.
1863 return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1866 /***
1867 * OLEDD_TrackMouseMove()
1869 * This method is invoked while a drag and drop operation is in effect.
1870 * it will generate the appropriate callbacks in the drop source
1871 * and drop target. It will also provide the expected feedback to
1872 * the user.
1874 * params:
1875 * trackerInfo - Pointer to the structure identifying the
1876 * drag & drop operation that is currently
1877 * active.
1878 * mousePos - Current position of the mouse in screen
1879 * coordinates.
1880 * keyState - Contains the state of the shift keys and the
1881 * mouse buttons (MK_LBUTTON and the like)
1883 static void OLEDD_TrackMouseMove(
1884 TrackerWindowInfo* trackerInfo,
1885 POINT mousePos,
1886 DWORD keyState)
1888 HWND hwndNewTarget = 0;
1889 HRESULT hr = S_OK;
1892 * Get the handle of the window under the mouse
1894 hwndNewTarget = WindowFromPoint(mousePos);
1897 * Every time, we re-initialize the effects passed to the
1898 * IDropTarget to the effects allowed by the source.
1900 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1903 * If we are hovering over the same target as before, send the
1904 * DragOver notification
1906 if ( (trackerInfo->curDragTarget != 0) &&
1907 (trackerInfo->curTargetHWND == hwndNewTarget) )
1909 POINTL mousePosParam;
1912 * The documentation tells me that the coordinate should be in the target
1913 * window's coordinate space. However, the tests I made tell me the
1914 * coordinates should be in screen coordinates.
1916 mousePosParam.x = mousePos.x;
1917 mousePosParam.y = mousePos.y;
1919 IDropTarget_DragOver(trackerInfo->curDragTarget,
1920 keyState,
1921 mousePosParam,
1922 trackerInfo->pdwEffect);
1924 else
1926 DropTargetNode* newDropTargetNode = 0;
1929 * If we changed window, we have to notify our old target and check for
1930 * the new one.
1932 if (trackerInfo->curDragTarget!=0)
1934 IDropTarget_DragLeave(trackerInfo->curDragTarget);
1938 * Make sure we're hovering over a window.
1940 if (hwndNewTarget!=0)
1943 * Find-out if there is a drag target under the mouse
1945 HWND nexttar = hwndNewTarget;
1946 trackerInfo->curTargetHWND = hwndNewTarget;
1948 do {
1949 newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1950 } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1951 if(nexttar) hwndNewTarget = nexttar;
1953 trackerInfo->curDragTargetHWND = hwndNewTarget;
1954 trackerInfo->curDragTarget = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1957 * If there is, notify it that we just dragged-in
1959 if (trackerInfo->curDragTarget!=0)
1961 POINTL mousePosParam;
1964 * The documentation tells me that the coordinate should be in the target
1965 * window's coordinate space. However, the tests I made tell me the
1966 * coordinates should be in screen coordinates.
1968 mousePosParam.x = mousePos.x;
1969 mousePosParam.y = mousePos.y;
1971 IDropTarget_DragEnter(trackerInfo->curDragTarget,
1972 trackerInfo->dataObject,
1973 keyState,
1974 mousePosParam,
1975 trackerInfo->pdwEffect);
1978 else
1981 * The mouse is not over a window so we don't track anything.
1983 trackerInfo->curDragTargetHWND = 0;
1984 trackerInfo->curTargetHWND = 0;
1985 trackerInfo->curDragTarget = 0;
1990 * Now that we have done that, we have to tell the source to give
1991 * us feedback on the work being done by the target. If we don't
1992 * have a target, simulate no effect.
1994 if (trackerInfo->curDragTarget==0)
1996 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1999 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2000 *trackerInfo->pdwEffect);
2003 * When we ask for feedback from the drop source, sometimes it will
2004 * do all the necessary work and sometimes it will not handle it
2005 * when that's the case, we must display the standard drag and drop
2006 * cursors.
2008 if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2010 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2012 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2014 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2016 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2018 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2020 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2022 else
2024 SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2029 /***
2030 * OLEDD_TrackStateChange()
2032 * This method is invoked while a drag and drop operation is in effect.
2033 * It is used to notify the drop target/drop source callbacks when
2034 * the state of the keyboard or mouse button change.
2036 * params:
2037 * trackerInfo - Pointer to the structure identifying the
2038 * drag & drop operation that is currently
2039 * active.
2040 * mousePos - Current position of the mouse in screen
2041 * coordinates.
2042 * keyState - Contains the state of the shift keys and the
2043 * mouse buttons (MK_LBUTTON and the like)
2045 static void OLEDD_TrackStateChange(
2046 TrackerWindowInfo* trackerInfo,
2047 POINT mousePos,
2048 DWORD keyState)
2051 * Ask the drop source what to do with the operation.
2053 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2054 trackerInfo->dropSource,
2055 trackerInfo->escPressed,
2056 keyState);
2059 * All the return valued will stop the operation except the S_OK
2060 * return value.
2062 if (trackerInfo->returnValue!=S_OK)
2065 * Make sure the message loop in DoDragDrop stops
2067 trackerInfo->trackingDone = TRUE;
2070 * Release the mouse in case the drop target decides to show a popup
2071 * or a menu or something.
2073 ReleaseCapture();
2076 * If we end-up over a target, drop the object in the target or
2077 * inform the target that the operation was cancelled.
2079 if (trackerInfo->curDragTarget!=0)
2081 switch (trackerInfo->returnValue)
2084 * If the source wants us to complete the operation, we tell
2085 * the drop target that we just dropped the object in it.
2087 case DRAGDROP_S_DROP:
2089 POINTL mousePosParam;
2092 * The documentation tells me that the coordinate should be
2093 * in the target window's coordinate space. However, the tests
2094 * I made tell me the coordinates should be in screen coordinates.
2096 mousePosParam.x = mousePos.x;
2097 mousePosParam.y = mousePos.y;
2099 IDropTarget_Drop(trackerInfo->curDragTarget,
2100 trackerInfo->dataObject,
2101 keyState,
2102 mousePosParam,
2103 trackerInfo->pdwEffect);
2104 break;
2107 * If the source told us that we should cancel, fool the drop
2108 * target by telling it that the mouse left it's window.
2109 * Also set the drop effect to "NONE" in case the application
2110 * ignores the result of DoDragDrop.
2112 case DRAGDROP_S_CANCEL:
2113 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2114 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2115 break;
2121 /***
2122 * OLEDD_GetButtonState()
2124 * This method will use the current state of the keyboard to build
2125 * a button state mask equivalent to the one passed in the
2126 * WM_MOUSEMOVE wParam.
2128 static DWORD OLEDD_GetButtonState()
2130 BYTE keyboardState[256];
2131 DWORD keyMask = 0;
2133 GetKeyboardState(keyboardState);
2135 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2136 keyMask |= MK_SHIFT;
2138 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2139 keyMask |= MK_CONTROL;
2141 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2142 keyMask |= MK_LBUTTON;
2144 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2145 keyMask |= MK_RBUTTON;
2147 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2148 keyMask |= MK_MBUTTON;
2150 return keyMask;
2153 /***
2154 * OLEDD_GetButtonState()
2156 * This method will read the default value of the registry key in
2157 * parameter and extract a DWORD value from it. The registry key value
2158 * can be in a string key or a DWORD key.
2160 * params:
2161 * regKey - Key to read the default value from
2162 * pdwValue - Pointer to the location where the DWORD
2163 * value is returned. This value is not modified
2164 * if the value is not found.
2167 static void OLEUTL_ReadRegistryDWORDValue(
2168 HKEY regKey,
2169 DWORD* pdwValue)
2171 char buffer[20];
2172 DWORD dwKeyType;
2173 DWORD cbData = 20;
2174 LONG lres;
2176 lres = RegQueryValueExA(regKey,
2178 NULL,
2179 &dwKeyType,
2180 (LPBYTE)buffer,
2181 &cbData);
2183 if (lres==ERROR_SUCCESS)
2185 switch (dwKeyType)
2187 case REG_DWORD:
2188 *pdwValue = *(DWORD*)buffer;
2189 break;
2190 case REG_EXPAND_SZ:
2191 case REG_MULTI_SZ:
2192 case REG_SZ:
2193 *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2194 break;
2199 /******************************************************************************
2200 * OleDraw (OLE32.@)
2202 * The operation of this function is documented literally in the WinAPI
2203 * documentation to involve a QueryInterface for the IViewObject interface,
2204 * followed by a call to IViewObject::Draw.
2206 HRESULT WINAPI OleDraw(
2207 IUnknown *pUnk,
2208 DWORD dwAspect,
2209 HDC hdcDraw,
2210 LPCRECT lprcBounds)
2212 HRESULT hres;
2213 IViewObject *viewobject;
2215 hres = IUnknown_QueryInterface(pUnk,
2216 &IID_IViewObject,
2217 (void**)&viewobject);
2219 if (SUCCEEDED(hres))
2221 RECTL rectl;
2223 rectl.left = lprcBounds->left;
2224 rectl.right = lprcBounds->right;
2225 rectl.top = lprcBounds->top;
2226 rectl.bottom = lprcBounds->bottom;
2227 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2229 IViewObject_Release(viewobject);
2230 return hres;
2232 else
2234 return DV_E_NOIVIEWOBJECT;
2238 /***********************************************************************
2239 * OleTranslateAccelerator [OLE32.@]
2241 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2242 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2244 WORD wID;
2246 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2248 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2249 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2251 return S_FALSE;
2254 /******************************************************************************
2255 * OleCreate [OLE32.@]
2258 HRESULT WINAPI OleCreate(
2259 REFCLSID rclsid,
2260 REFIID riid,
2261 DWORD renderopt,
2262 LPFORMATETC pFormatEtc,
2263 LPOLECLIENTSITE pClientSite,
2264 LPSTORAGE pStg,
2265 LPVOID* ppvObj)
2267 HRESULT hres, hres1;
2268 IUnknown * pUnk = NULL;
2270 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2272 if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk))))
2274 if (pClientSite)
2276 IOleObject * pOE;
2277 IPersistStorage * pPS;
2278 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE))))
2280 TRACE("trying to set clientsite %p\n", pClientSite);
2281 hres1 = IOleObject_SetClientSite(pOE, pClientSite);
2282 TRACE("-- result 0x%08lx\n", hres1);
2283 IOleObject_Release(pOE);
2285 if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2287 TRACE("trying to set stg %p\n", pStg);
2288 hres1 = IPersistStorage_InitNew(pPS, pStg);
2289 TRACE("-- result 0x%08lx\n", hres1);
2290 IPersistStorage_Release(pPS);
2295 *ppvObj = pUnk;
2297 TRACE("-- %p \n", pUnk);
2298 return hres;
2301 /***********************************************************************
2302 * OLE_FreeClipDataArray [internal]
2304 * NOTES:
2305 * frees the data associated with an array of CLIPDATAs
2307 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2309 ULONG i;
2310 for (i = 0; i < count; i++)
2311 if (pClipDataArray[i].pClipData)
2312 CoTaskMemFree(pClipDataArray[i].pClipData);
2315 HRESULT WINAPI FreePropVariantArray(ULONG,PROPVARIANT*);
2317 /***********************************************************************
2318 * PropVariantClear [OLE32.@]
2320 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2322 TRACE("(%p)\n", pvar);
2324 if (!pvar)
2325 return S_OK;
2327 switch(pvar->vt)
2329 case VT_STREAM:
2330 case VT_STREAMED_OBJECT:
2331 case VT_STORAGE:
2332 case VT_STORED_OBJECT:
2333 IUnknown_Release((LPUNKNOWN)pvar->u.pStream);
2334 break;
2335 case VT_CLSID:
2336 case VT_LPSTR:
2337 case VT_LPWSTR:
2338 /* pick an arbitary typed pointer - we don't care about the type
2339 * as we are just freeing it */
2340 CoTaskMemFree(pvar->u.puuid);
2341 break;
2342 case VT_BLOB:
2343 case VT_BLOB_OBJECT:
2344 CoTaskMemFree(pvar->u.blob.pBlobData);
2345 break;
2346 case VT_BSTR:
2347 FIXME("Need to load OLEAUT32 for SysFreeString\n");
2348 /* SysFreeString(pvar->u.bstrVal); */
2349 break;
2350 case VT_CF:
2351 if (pvar->u.pclipdata)
2353 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2354 CoTaskMemFree(pvar->u.pclipdata);
2356 break;
2357 default:
2358 if (pvar->vt & VT_ARRAY)
2360 FIXME("Need to call SafeArrayDestroy\n");
2361 /* SafeArrayDestroy(pvar->u.caub); */
2363 switch (pvar->vt & VT_VECTOR)
2365 case VT_VARIANT:
2366 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2367 break;
2368 case VT_CF:
2369 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2370 break;
2371 case VT_BSTR:
2372 case VT_LPSTR:
2373 case VT_LPWSTR:
2374 FIXME("Freeing of vector sub-type not supported yet\n");
2376 if (pvar->vt & VT_VECTOR)
2378 /* pick an arbitary VT_VECTOR structure - they all have the same
2379 * memory layout */
2380 CoTaskMemFree(pvar->u.capropvar.pElems);
2384 ZeroMemory(pvar, sizeof(*pvar));
2386 return S_OK;
2389 /***********************************************************************
2390 * PropVariantCopy [OLE32.@]
2392 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2393 const PROPVARIANT *pvarSrc) /* [in] */
2395 ULONG len;
2396 TRACE("(%p, %p): stub:\n", pvarDest, pvarSrc);
2398 /* this will deal with most cases */
2399 CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2401 switch(pvarSrc->vt)
2403 case VT_STREAM:
2404 case VT_STREAMED_OBJECT:
2405 case VT_STORAGE:
2406 case VT_STORED_OBJECT:
2407 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2408 break;
2409 case VT_CLSID:
2410 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2411 CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2412 break;
2413 case VT_LPSTR:
2414 len = strlen(pvarSrc->u.pszVal);
2415 pvarDest->u.pszVal = CoTaskMemAlloc(len);
2416 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, len);
2417 break;
2418 case VT_LPWSTR:
2419 len = lstrlenW(pvarSrc->u.pwszVal);
2420 pvarDest->u.pwszVal = CoTaskMemAlloc(len);
2421 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, len);
2422 break;
2423 case VT_BLOB:
2424 case VT_BLOB_OBJECT:
2425 if (pvarSrc->u.blob.pBlobData)
2427 len = pvarSrc->u.blob.cbSize;
2428 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2429 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2431 break;
2432 case VT_BSTR:
2433 FIXME("Need to copy BSTR\n");
2434 break;
2435 case VT_CF:
2436 if (pvarSrc->u.pclipdata)
2438 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2439 CoTaskMemAlloc(len);
2440 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2442 break;
2443 default:
2444 if (pvarSrc->vt & VT_ARRAY)
2446 FIXME("Need to call SafeArrayCopy\n");
2447 /* SafeArrayCopy(...); */
2449 if (pvarSrc->vt & VT_VECTOR)
2451 int elemSize;
2452 switch(pvarSrc->vt & VT_VECTOR)
2454 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
2455 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
2456 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
2457 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
2458 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
2459 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
2460 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
2461 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
2462 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
2463 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
2464 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
2465 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
2466 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
2467 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
2468 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2469 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
2470 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2472 case VT_BSTR:
2473 case VT_LPSTR:
2474 case VT_LPWSTR:
2475 case VT_VARIANT:
2476 default:
2477 FIXME("Invalid element type: %ul\n", pvarSrc->vt & VT_VECTOR);
2478 return E_INVALIDARG;
2480 len = pvarSrc->u.capropvar.cElems;
2481 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2482 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2484 ULONG i;
2485 for (i = 0; i < len; i++)
2486 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2488 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2490 FIXME("Copy clipformats\n");
2492 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2494 FIXME("Copy BSTRs\n");
2496 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2498 FIXME("Copy LPSTRs\n");
2500 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2502 FIXME("Copy LPWSTRs\n");
2504 else
2505 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2509 return S_OK;
2512 /***********************************************************************
2513 * FreePropVariantArray [OLE32.@]
2515 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2516 PROPVARIANT *rgvars) /* [in/out] */
2518 ULONG i;
2520 TRACE("(%lu, %p)\n", cVariants, rgvars);
2522 for(i = 0; i < cVariants; i++)
2523 PropVariantClear(&rgvars[i]);
2525 return S_OK;
2528 /******************************************************************************
2529 * DllDebugObjectRPCHook (OLE32.@)
2530 * turns on and off internal debugging, pointer is only used on macintosh
2533 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
2535 FIXME("stub\n");
2536 return TRUE;