ole32: Handle null argument in OleIsRunning().
[wine/multimedia.git] / dlls / ole32 / ole2.c
blob3254619eab229adedb24bf7848d267237a6f1eee
1 /*
2 * OLE2 library
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
7 * Copyright 1999, 2000 Marcus Meissner
8 * Copyright 2005 Juan Lang
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winnls.h"
43 #include "winreg.h"
44 #include "ole2.h"
45 #include "ole2ver.h"
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
49 #include "wine/list.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole);
54 WINE_DECLARE_DEBUG_CHANNEL(accel);
56 /******************************************************************************
57 * These are static/global variables and internal data structures that the
58 * OLE module uses to maintain it's state.
60 typedef struct tagTrackerWindowInfo
62 IDataObject* dataObject;
63 IDropSource* dropSource;
64 DWORD dwOKEffect;
65 DWORD* pdwEffect;
66 BOOL trackingDone;
67 HRESULT returnValue;
69 BOOL escPressed;
70 HWND curTargetHWND; /* window the mouse is hovering over */
71 HWND curDragTargetHWND; /* might be a ancestor of curTargetHWND */
72 IDropTarget* curDragTarget;
73 POINTL curMousePos; /* current position of the mouse in screen coordinates */
74 DWORD dwKeyState; /* current state of the shift and ctrl keys and the mouse buttons */
75 } TrackerWindowInfo;
77 typedef struct tagOleMenuDescriptor /* OleMenuDescriptor */
79 HWND hwndFrame; /* The containers frame window */
80 HWND hwndActiveObject; /* The active objects window */
81 OLEMENUGROUPWIDTHS mgw; /* OLE menu group widths for the shared menu */
82 HMENU hmenuCombined; /* The combined menu */
83 BOOL bIsServerItem; /* True if the currently open popup belongs to the server */
84 } OleMenuDescriptor;
86 typedef struct tagOleMenuHookItem /* OleMenu hook item in per thread hook list */
88 DWORD tid; /* Thread Id */
89 HANDLE hHeap; /* Heap this is allocated from */
90 HHOOK GetMsg_hHook; /* message hook for WH_GETMESSAGE */
91 HHOOK CallWndProc_hHook; /* message hook for WH_CALLWNDPROC */
92 struct tagOleMenuHookItem *next;
93 } OleMenuHookItem;
95 static OleMenuHookItem *hook_list;
98 * This is the lock count on the OLE library. It is controlled by the
99 * OLEInitialize/OLEUninitialize methods.
101 static LONG OLE_moduleLockCount = 0;
104 * Name of our registered window class.
106 static const WCHAR OLEDD_DRAGTRACKERCLASS[] =
107 {'W','i','n','e','D','r','a','g','D','r','o','p','T','r','a','c','k','e','r','3','2',0};
110 * Name of menu descriptor property.
112 static const WCHAR prop_olemenuW[] =
113 {'P','R','O','P','_','O','L','E','M','e','n','u','D','e','s','c','r','i','p','t','o','r',0};
115 /* property to store IDropTarget pointer */
116 static const WCHAR prop_oledroptarget[] =
117 {'O','l','e','D','r','o','p','T','a','r','g','e','t','I','n','t','e','r','f','a','c','e',0};
119 /* property to store Marshalled IDropTarget pointer */
120 static const WCHAR prop_marshalleddroptarget[] =
121 {'W','i','n','e','M','a','r','s','h','a','l','l','e','d','D','r','o','p','T','a','r','g','e','t',0};
123 static const WCHAR clsidfmtW[] =
124 {'C','L','S','I','D','\\','{','%','0','8','x','-','%','0','4','x','-','%','0','4','x','-',
125 '%','0','2','x','%','0','2','x','-','%','0','2','x','%','0','2','x','%','0','2','x','%','0','2','x',
126 '%','0','2','x','%','0','2','x','}','\\',0};
128 static const WCHAR emptyW[] = { 0 };
130 /******************************************************************************
131 * These are the prototypes of miscellaneous utility methods
133 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
135 /******************************************************************************
136 * These are the prototypes of the utility methods used to manage a shared menu
138 static void OLEMenu_Initialize(void);
139 static void OLEMenu_UnInitialize(void);
140 static BOOL OLEMenu_InstallHooks( DWORD tid );
141 static BOOL OLEMenu_UnInstallHooks( DWORD tid );
142 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
143 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
144 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
145 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
146 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
148 /******************************************************************************
149 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
151 extern void OLEClipbrd_UnInitialize(void);
152 extern void OLEClipbrd_Initialize(void);
154 /******************************************************************************
155 * These are the prototypes of the utility methods used for OLE Drag n Drop
157 static void OLEDD_Initialize(void);
158 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
159 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo);
160 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo);
161 static DWORD OLEDD_GetButtonState(void);
163 /******************************************************************************
164 * OleBuildVersion [OLE32.@]
166 DWORD WINAPI OleBuildVersion(void)
168 TRACE("Returning version %d, build %d.\n", rmm, rup);
169 return (rmm<<16)+rup;
172 /***********************************************************************
173 * OleInitialize (OLE32.@)
175 HRESULT WINAPI OleInitialize(LPVOID reserved)
177 HRESULT hr;
179 TRACE("(%p)\n", reserved);
182 * The first duty of the OleInitialize is to initialize the COM libraries.
184 hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
187 * If the CoInitializeEx call failed, the OLE libraries can't be
188 * initialized.
190 if (FAILED(hr))
191 return hr;
193 if (!COM_CurrentInfo()->ole_inits)
194 hr = S_OK;
197 * Then, it has to initialize the OLE specific modules.
198 * This includes:
199 * Clipboard
200 * Drag and Drop
201 * Object linking and Embedding
202 * In-place activation
204 if (!COM_CurrentInfo()->ole_inits++ &&
205 InterlockedIncrement(&OLE_moduleLockCount) == 1)
208 * Initialize the libraries.
210 TRACE("() - Initializing the OLE libraries\n");
213 * OLE Clipboard
215 OLEClipbrd_Initialize();
218 * Drag and Drop
220 OLEDD_Initialize();
223 * OLE shared menu
225 OLEMenu_Initialize();
228 return hr;
231 /******************************************************************************
232 * OleUninitialize [OLE32.@]
234 void WINAPI OleUninitialize(void)
236 TRACE("()\n");
239 * If we hit the bottom of the lock stack, free the libraries.
241 if (!--COM_CurrentInfo()->ole_inits && !InterlockedDecrement(&OLE_moduleLockCount))
244 * Actually free the libraries.
246 TRACE("() - Freeing the last reference count\n");
249 * OLE Clipboard
251 OLEClipbrd_UnInitialize();
254 * OLE shared menu
256 OLEMenu_UnInitialize();
260 * Then, uninitialize the COM libraries.
262 CoUninitialize();
265 /******************************************************************************
266 * OleInitializeWOW [OLE32.@]
268 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
269 FIXME("(0x%08x, 0x%08x),stub!\n",x, y);
270 return 0;
273 /*************************************************************
274 * get_droptarget_handle
276 * Retrieve a handle to the map containing the marshalled IDropTarget.
277 * This handle belongs to the process that called RegisterDragDrop.
278 * See get_droptarget_local_handle().
280 static inline HANDLE get_droptarget_handle(HWND hwnd)
282 return GetPropW(hwnd, prop_marshalleddroptarget);
285 /*************************************************************
286 * is_droptarget
288 * Is the window a droptarget.
290 static inline BOOL is_droptarget(HWND hwnd)
292 return get_droptarget_handle(hwnd) ? TRUE : FALSE;
295 /*************************************************************
296 * get_droptarget_local_handle
298 * Retrieve a handle to the map containing the marshalled IDropTarget.
299 * The handle should be closed when finished with.
301 static HANDLE get_droptarget_local_handle(HWND hwnd)
303 HANDLE handle, local_handle = 0;
305 handle = get_droptarget_handle(hwnd);
307 if(handle)
309 DWORD pid;
310 HANDLE process;
312 GetWindowThreadProcessId(hwnd, &pid);
313 process = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid);
314 if(process)
316 DuplicateHandle(process, handle, GetCurrentProcess(), &local_handle, 0, FALSE, DUPLICATE_SAME_ACCESS);
317 CloseHandle(process);
320 return local_handle;
323 /***********************************************************************
324 * create_map_from_stream
326 * Helper for RegisterDragDrop. Creates a file mapping object
327 * with the contents of the provided stream. The stream must
328 * be a global memory backed stream.
330 static HRESULT create_map_from_stream(IStream *stream, HANDLE *map)
332 HGLOBAL hmem;
333 DWORD size;
334 HRESULT hr;
335 void *data;
337 hr = GetHGlobalFromStream(stream, &hmem);
338 if(FAILED(hr)) return hr;
340 size = GlobalSize(hmem);
341 *map = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL);
342 if(!*map) return E_OUTOFMEMORY;
344 data = MapViewOfFile(*map, FILE_MAP_WRITE, 0, 0, size);
345 memcpy(data, GlobalLock(hmem), size);
346 GlobalUnlock(hmem);
347 UnmapViewOfFile(data);
348 return S_OK;
351 /***********************************************************************
352 * create_stream_from_map
354 * Creates a stream from the provided map.
356 static HRESULT create_stream_from_map(HANDLE map, IStream **stream)
358 HRESULT hr = E_OUTOFMEMORY;
359 HGLOBAL hmem;
360 void *data;
361 MEMORY_BASIC_INFORMATION info;
363 data = MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
364 if(!data) return hr;
366 VirtualQuery(data, &info, sizeof(info));
367 TRACE("size %d\n", (int)info.RegionSize);
369 hmem = GlobalAlloc(GMEM_MOVEABLE, info.RegionSize);
370 if(hmem)
372 memcpy(GlobalLock(hmem), data, info.RegionSize);
373 GlobalUnlock(hmem);
374 hr = CreateStreamOnHGlobal(hmem, TRUE, stream);
376 UnmapViewOfFile(data);
377 return hr;
380 /***********************************************************************
381 * get_droptarget_pointer
383 * Retrieves the marshalled IDropTarget from the window.
385 static IDropTarget* get_droptarget_pointer(HWND hwnd)
387 IDropTarget *droptarget = NULL;
388 HANDLE map;
389 IStream *stream;
391 map = get_droptarget_local_handle(hwnd);
392 if(!map) return NULL;
394 if(SUCCEEDED(create_stream_from_map(map, &stream)))
396 CoUnmarshalInterface(stream, &IID_IDropTarget, (void**)&droptarget);
397 IStream_Release(stream);
399 CloseHandle(map);
400 return droptarget;
403 /***********************************************************************
404 * RegisterDragDrop (OLE32.@)
406 HRESULT WINAPI RegisterDragDrop(HWND hwnd, LPDROPTARGET pDropTarget)
408 DWORD pid = 0;
409 HRESULT hr;
410 IStream *stream;
411 HANDLE map;
412 IUnknown *unk;
414 TRACE("(%p,%p)\n", hwnd, pDropTarget);
416 if (!COM_CurrentApt())
418 ERR("COM not initialized\n");
419 return E_OUTOFMEMORY;
422 if (!pDropTarget)
423 return E_INVALIDARG;
425 if (!IsWindow(hwnd))
427 ERR("invalid hwnd %p\n", hwnd);
428 return DRAGDROP_E_INVALIDHWND;
431 /* block register for other processes windows */
432 GetWindowThreadProcessId(hwnd, &pid);
433 if (pid != GetCurrentProcessId())
435 FIXME("register for another process windows is disabled\n");
436 return DRAGDROP_E_INVALIDHWND;
439 /* check if the window is already registered */
440 if (is_droptarget(hwnd))
441 return DRAGDROP_E_ALREADYREGISTERED;
444 * Marshal the drop target pointer into a shared memory map and
445 * store the map's handle in a Wine specific window prop. We also
446 * store the drop target pointer itself in the
447 * "OleDropTargetInterface" prop for compatibility with Windows.
450 hr = CreateStreamOnHGlobal(NULL, TRUE, &stream);
451 if(FAILED(hr)) return hr;
453 unk = NULL;
454 hr = IDropTarget_QueryInterface(pDropTarget, &IID_IUnknown, (void**)&unk);
455 if (SUCCEEDED(hr) && !unk) hr = E_NOINTERFACE;
456 if(FAILED(hr))
458 IStream_Release(stream);
459 return hr;
461 hr = CoMarshalInterface(stream, &IID_IDropTarget, unk, MSHCTX_LOCAL, NULL, MSHLFLAGS_TABLESTRONG);
462 IUnknown_Release(unk);
464 if(SUCCEEDED(hr))
466 hr = create_map_from_stream(stream, &map);
467 if(SUCCEEDED(hr))
469 IDropTarget_AddRef(pDropTarget);
470 SetPropW(hwnd, prop_oledroptarget, pDropTarget);
471 SetPropW(hwnd, prop_marshalleddroptarget, map);
473 else
475 LARGE_INTEGER zero;
476 zero.QuadPart = 0;
477 IStream_Seek(stream, zero, STREAM_SEEK_SET, NULL);
478 CoReleaseMarshalData(stream);
481 IStream_Release(stream);
483 return hr;
486 /***********************************************************************
487 * RevokeDragDrop (OLE32.@)
489 HRESULT WINAPI RevokeDragDrop(HWND hwnd)
491 HANDLE map;
492 IStream *stream;
493 IDropTarget *drop_target;
494 HRESULT hr;
496 TRACE("(%p)\n", hwnd);
498 if (!IsWindow(hwnd))
500 ERR("invalid hwnd %p\n", hwnd);
501 return DRAGDROP_E_INVALIDHWND;
504 /* no registration data */
505 if (!(map = get_droptarget_handle(hwnd)))
506 return DRAGDROP_E_NOTREGISTERED;
508 drop_target = GetPropW(hwnd, prop_oledroptarget);
509 if(drop_target) IDropTarget_Release(drop_target);
511 RemovePropW(hwnd, prop_oledroptarget);
512 RemovePropW(hwnd, prop_marshalleddroptarget);
514 hr = create_stream_from_map(map, &stream);
515 if(SUCCEEDED(hr))
517 CoReleaseMarshalData(stream);
518 IStream_Release(stream);
520 CloseHandle(map);
522 return hr;
525 /***********************************************************************
526 * OleRegGetUserType (OLE32.@)
528 * This implementation of OleRegGetUserType ignores the dwFormOfType
529 * parameter and always returns the full name of the object. This is
530 * not too bad since this is the case for many objects because of the
531 * way they are registered.
533 HRESULT WINAPI OleRegGetUserType(
534 REFCLSID clsid,
535 DWORD dwFormOfType,
536 LPOLESTR* pszUserType)
538 WCHAR keyName[60];
539 DWORD dwKeyType;
540 DWORD cbData;
541 HKEY clsidKey;
542 LONG hres;
545 * Initialize the out parameter.
547 *pszUserType = NULL;
550 * Build the key name we're looking for
552 sprintfW( keyName, clsidfmtW,
553 clsid->Data1, clsid->Data2, clsid->Data3,
554 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
555 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
557 TRACE("(%s, %d, %p)\n", debugstr_w(keyName), dwFormOfType, pszUserType);
560 * Open the class id Key
562 hres = RegOpenKeyW(HKEY_CLASSES_ROOT,
563 keyName,
564 &clsidKey);
566 if (hres != ERROR_SUCCESS)
567 return REGDB_E_CLASSNOTREG;
570 * Retrieve the size of the name string.
572 cbData = 0;
574 hres = RegQueryValueExW(clsidKey,
575 emptyW,
576 NULL,
577 &dwKeyType,
578 NULL,
579 &cbData);
581 if (hres!=ERROR_SUCCESS)
583 RegCloseKey(clsidKey);
584 return REGDB_E_READREGDB;
588 * Allocate a buffer for the registry value.
590 *pszUserType = CoTaskMemAlloc(cbData);
592 if (*pszUserType==NULL)
594 RegCloseKey(clsidKey);
595 return E_OUTOFMEMORY;
598 hres = RegQueryValueExW(clsidKey,
599 emptyW,
600 NULL,
601 &dwKeyType,
602 (LPBYTE) *pszUserType,
603 &cbData);
605 RegCloseKey(clsidKey);
607 if (hres != ERROR_SUCCESS)
609 CoTaskMemFree(*pszUserType);
610 *pszUserType = NULL;
612 return REGDB_E_READREGDB;
615 return S_OK;
618 /***********************************************************************
619 * DoDragDrop [OLE32.@]
621 HRESULT WINAPI DoDragDrop (
622 IDataObject *pDataObject, /* [in] ptr to the data obj */
623 IDropSource* pDropSource, /* [in] ptr to the source obj */
624 DWORD dwOKEffect, /* [in] effects allowed by the source */
625 DWORD *pdwEffect) /* [out] ptr to effects of the source */
627 static const WCHAR trackerW[] = {'T','r','a','c','k','e','r','W','i','n','d','o','w',0};
628 TrackerWindowInfo trackerInfo;
629 HWND hwndTrackWindow;
630 MSG msg;
632 TRACE("(%p, %p, %d, %p)\n", pDataObject, pDropSource, dwOKEffect, pdwEffect);
634 if (!pDataObject || !pDropSource || !pdwEffect)
635 return E_INVALIDARG;
638 * Setup the drag n drop tracking window.
641 trackerInfo.dataObject = pDataObject;
642 trackerInfo.dropSource = pDropSource;
643 trackerInfo.dwOKEffect = dwOKEffect;
644 trackerInfo.pdwEffect = pdwEffect;
645 trackerInfo.trackingDone = FALSE;
646 trackerInfo.escPressed = FALSE;
647 trackerInfo.curDragTargetHWND = 0;
648 trackerInfo.curTargetHWND = 0;
649 trackerInfo.curDragTarget = 0;
651 hwndTrackWindow = CreateWindowW(OLEDD_DRAGTRACKERCLASS, trackerW,
652 WS_POPUP, CW_USEDEFAULT, CW_USEDEFAULT,
653 CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, 0,
654 &trackerInfo);
656 if (hwndTrackWindow)
659 * Capture the mouse input
661 SetCapture(hwndTrackWindow);
663 msg.message = 0;
666 * Pump messages. All mouse input should go to the capture window.
668 while (!trackerInfo.trackingDone && GetMessageW(&msg, 0, 0, 0) )
670 trackerInfo.curMousePos.x = msg.pt.x;
671 trackerInfo.curMousePos.y = msg.pt.y;
672 trackerInfo.dwKeyState = OLEDD_GetButtonState();
674 if ( (msg.message >= WM_KEYFIRST) &&
675 (msg.message <= WM_KEYLAST) )
678 * When keyboard messages are sent to windows on this thread, we
679 * want to ignore notify the drop source that the state changed.
680 * in the case of the Escape key, we also notify the drop source
681 * we give it a special meaning.
683 if ( (msg.message==WM_KEYDOWN) &&
684 (msg.wParam==VK_ESCAPE) )
686 trackerInfo.escPressed = TRUE;
690 * Notify the drop source.
692 OLEDD_TrackStateChange(&trackerInfo);
694 else
697 * Dispatch the messages only when it's not a keyboard message.
699 DispatchMessageW(&msg);
703 /* re-post the quit message to outer message loop */
704 if (msg.message == WM_QUIT)
705 PostQuitMessage(msg.wParam);
707 * Destroy the temporary window.
709 DestroyWindow(hwndTrackWindow);
711 return trackerInfo.returnValue;
714 return E_FAIL;
717 /***********************************************************************
718 * OleQueryLinkFromData [OLE32.@]
720 HRESULT WINAPI OleQueryLinkFromData(
721 IDataObject* pSrcDataObject)
723 FIXME("(%p),stub!\n", pSrcDataObject);
724 return S_FALSE;
727 /***********************************************************************
728 * OleRegGetMiscStatus [OLE32.@]
730 HRESULT WINAPI OleRegGetMiscStatus(
731 REFCLSID clsid,
732 DWORD dwAspect,
733 DWORD* pdwStatus)
735 static const WCHAR miscstatusW[] = {'M','i','s','c','S','t','a','t','u','s',0};
736 static const WCHAR dfmtW[] = {'%','d',0};
737 WCHAR keyName[60];
738 HKEY clsidKey;
739 HKEY miscStatusKey;
740 HKEY aspectKey;
741 LONG result;
744 * Initialize the out parameter.
746 *pdwStatus = 0;
749 * Build the key name we're looking for
751 sprintfW( keyName, clsidfmtW,
752 clsid->Data1, clsid->Data2, clsid->Data3,
753 clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
754 clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
756 TRACE("(%s, %d, %p)\n", debugstr_w(keyName), dwAspect, pdwStatus);
759 * Open the class id Key
761 result = RegOpenKeyW(HKEY_CLASSES_ROOT,
762 keyName,
763 &clsidKey);
765 if (result != ERROR_SUCCESS)
766 return REGDB_E_CLASSNOTREG;
769 * Get the MiscStatus
771 result = RegOpenKeyW(clsidKey,
772 miscstatusW,
773 &miscStatusKey);
776 if (result != ERROR_SUCCESS)
778 RegCloseKey(clsidKey);
779 return REGDB_E_READREGDB;
783 * Read the default value
785 OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
788 * Open the key specific to the requested aspect.
790 sprintfW(keyName, dfmtW, dwAspect);
792 result = RegOpenKeyW(miscStatusKey,
793 keyName,
794 &aspectKey);
796 if (result == ERROR_SUCCESS)
798 OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
799 RegCloseKey(aspectKey);
803 * Cleanup
805 RegCloseKey(miscStatusKey);
806 RegCloseKey(clsidKey);
808 return S_OK;
811 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum);
813 typedef struct
815 IEnumOLEVERB IEnumOLEVERB_iface;
816 LONG ref;
818 HKEY hkeyVerb;
819 ULONG index;
820 } EnumOLEVERB;
822 static inline EnumOLEVERB *impl_from_IEnumOLEVERB(IEnumOLEVERB *iface)
824 return CONTAINING_RECORD(iface, EnumOLEVERB, IEnumOLEVERB_iface);
827 static HRESULT WINAPI EnumOLEVERB_QueryInterface(
828 IEnumOLEVERB *iface, REFIID riid, void **ppv)
830 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
831 if (IsEqualIID(riid, &IID_IUnknown) ||
832 IsEqualIID(riid, &IID_IEnumOLEVERB))
834 IUnknown_AddRef(iface);
835 *ppv = iface;
836 return S_OK;
838 return E_NOINTERFACE;
841 static ULONG WINAPI EnumOLEVERB_AddRef(
842 IEnumOLEVERB *iface)
844 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
845 TRACE("()\n");
846 return InterlockedIncrement(&This->ref);
849 static ULONG WINAPI EnumOLEVERB_Release(
850 IEnumOLEVERB *iface)
852 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
853 LONG refs = InterlockedDecrement(&This->ref);
854 TRACE("()\n");
855 if (!refs)
857 RegCloseKey(This->hkeyVerb);
858 HeapFree(GetProcessHeap(), 0, This);
860 return refs;
863 static HRESULT WINAPI EnumOLEVERB_Next(
864 IEnumOLEVERB *iface, ULONG celt, LPOLEVERB rgelt,
865 ULONG *pceltFetched)
867 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
868 HRESULT hr = S_OK;
870 TRACE("(%d, %p, %p)\n", celt, rgelt, pceltFetched);
872 if (pceltFetched)
873 *pceltFetched = 0;
875 for (; celt; celt--, rgelt++)
877 WCHAR wszSubKey[20];
878 LONG cbData;
879 LPWSTR pwszOLEVERB;
880 LPWSTR pwszMenuFlags;
881 LPWSTR pwszAttribs;
882 LONG res = RegEnumKeyW(This->hkeyVerb, This->index, wszSubKey, sizeof(wszSubKey)/sizeof(wszSubKey[0]));
883 if (res == ERROR_NO_MORE_ITEMS)
885 hr = S_FALSE;
886 break;
888 else if (res != ERROR_SUCCESS)
890 ERR("RegEnumKeyW failed with error %d\n", res);
891 hr = REGDB_E_READREGDB;
892 break;
894 res = RegQueryValueW(This->hkeyVerb, wszSubKey, NULL, &cbData);
895 if (res != ERROR_SUCCESS)
897 ERR("RegQueryValueW failed with error %d\n", res);
898 hr = REGDB_E_READREGDB;
899 break;
901 pwszOLEVERB = CoTaskMemAlloc(cbData);
902 if (!pwszOLEVERB)
904 hr = E_OUTOFMEMORY;
905 break;
907 res = RegQueryValueW(This->hkeyVerb, wszSubKey, pwszOLEVERB, &cbData);
908 if (res != ERROR_SUCCESS)
910 ERR("RegQueryValueW failed with error %d\n", res);
911 hr = REGDB_E_READREGDB;
912 CoTaskMemFree(pwszOLEVERB);
913 break;
916 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB));
917 pwszMenuFlags = strchrW(pwszOLEVERB, ',');
918 if (!pwszMenuFlags)
920 hr = OLEOBJ_E_INVALIDVERB;
921 CoTaskMemFree(pwszOLEVERB);
922 break;
924 /* nul terminate the name string and advance to first character */
925 *pwszMenuFlags = '\0';
926 pwszMenuFlags++;
927 pwszAttribs = strchrW(pwszMenuFlags, ',');
928 if (!pwszAttribs)
930 hr = OLEOBJ_E_INVALIDVERB;
931 CoTaskMemFree(pwszOLEVERB);
932 break;
934 /* nul terminate the menu string and advance to first character */
935 *pwszAttribs = '\0';
936 pwszAttribs++;
938 /* fill out structure for this verb */
939 rgelt->lVerb = atolW(wszSubKey);
940 rgelt->lpszVerbName = pwszOLEVERB; /* user should free */
941 rgelt->fuFlags = atolW(pwszMenuFlags);
942 rgelt->grfAttribs = atolW(pwszAttribs);
944 if (pceltFetched)
945 (*pceltFetched)++;
946 This->index++;
948 return hr;
951 static HRESULT WINAPI EnumOLEVERB_Skip(
952 IEnumOLEVERB *iface, ULONG celt)
954 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
956 TRACE("(%d)\n", celt);
958 This->index += celt;
959 return S_OK;
962 static HRESULT WINAPI EnumOLEVERB_Reset(
963 IEnumOLEVERB *iface)
965 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
967 TRACE("()\n");
969 This->index = 0;
970 return S_OK;
973 static HRESULT WINAPI EnumOLEVERB_Clone(
974 IEnumOLEVERB *iface,
975 IEnumOLEVERB **ppenum)
977 EnumOLEVERB *This = impl_from_IEnumOLEVERB(iface);
978 HKEY hkeyVerb;
979 TRACE("(%p)\n", ppenum);
980 if (!DuplicateHandle(GetCurrentProcess(), This->hkeyVerb, GetCurrentProcess(), (HANDLE *)&hkeyVerb, 0, FALSE, DUPLICATE_SAME_ACCESS))
981 return HRESULT_FROM_WIN32(GetLastError());
982 return EnumOLEVERB_Construct(hkeyVerb, This->index, ppenum);
985 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable =
987 EnumOLEVERB_QueryInterface,
988 EnumOLEVERB_AddRef,
989 EnumOLEVERB_Release,
990 EnumOLEVERB_Next,
991 EnumOLEVERB_Skip,
992 EnumOLEVERB_Reset,
993 EnumOLEVERB_Clone
996 static HRESULT EnumOLEVERB_Construct(HKEY hkeyVerb, ULONG index, IEnumOLEVERB **ppenum)
998 EnumOLEVERB *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
999 if (!This)
1001 RegCloseKey(hkeyVerb);
1002 return E_OUTOFMEMORY;
1004 This->IEnumOLEVERB_iface.lpVtbl = &EnumOLEVERB_VTable;
1005 This->ref = 1;
1006 This->index = index;
1007 This->hkeyVerb = hkeyVerb;
1008 *ppenum = &This->IEnumOLEVERB_iface;
1009 return S_OK;
1012 /***********************************************************************
1013 * OleRegEnumVerbs [OLE32.@]
1015 * Enumerates verbs associated with a class stored in the registry.
1017 * PARAMS
1018 * clsid [I] Class ID to enumerate the verbs for.
1019 * ppenum [O] Enumerator.
1021 * RETURNS
1022 * S_OK: Success.
1023 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
1024 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
1025 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
1026 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
1028 HRESULT WINAPI OleRegEnumVerbs (REFCLSID clsid, LPENUMOLEVERB* ppenum)
1030 LONG res;
1031 HKEY hkeyVerb;
1032 DWORD dwSubKeys;
1033 static const WCHAR wszVerb[] = {'V','e','r','b',0};
1035 TRACE("(%s, %p)\n", debugstr_guid(clsid), ppenum);
1037 res = COM_OpenKeyForCLSID(clsid, wszVerb, KEY_READ, &hkeyVerb);
1038 if (FAILED(res))
1040 if (res == REGDB_E_CLASSNOTREG)
1041 ERR("CLSID %s not registered\n", debugstr_guid(clsid));
1042 else if (res == REGDB_E_KEYMISSING)
1043 ERR("no Verbs key for class %s\n", debugstr_guid(clsid));
1044 else
1045 ERR("failed to open Verbs key for CLSID %s with error %d\n",
1046 debugstr_guid(clsid), res);
1047 return res;
1050 res = RegQueryInfoKeyW(hkeyVerb, NULL, NULL, NULL, &dwSubKeys, NULL,
1051 NULL, NULL, NULL, NULL, NULL, NULL);
1052 if (res != ERROR_SUCCESS)
1054 ERR("failed to get subkey count with error %d\n", GetLastError());
1055 return REGDB_E_READREGDB;
1058 if (!dwSubKeys)
1060 WARN("class %s has no verbs\n", debugstr_guid(clsid));
1061 RegCloseKey(hkeyVerb);
1062 return OLEOBJ_E_NOVERBS;
1065 return EnumOLEVERB_Construct(hkeyVerb, 0, ppenum);
1068 /******************************************************************************
1069 * OleSetContainedObject [OLE32.@]
1071 HRESULT WINAPI OleSetContainedObject(
1072 LPUNKNOWN pUnknown,
1073 BOOL fContained)
1075 IRunnableObject* runnable = NULL;
1076 HRESULT hres;
1078 TRACE("(%p,%x)\n", pUnknown, fContained);
1080 hres = IUnknown_QueryInterface(pUnknown,
1081 &IID_IRunnableObject,
1082 (void**)&runnable);
1084 if (SUCCEEDED(hres))
1086 hres = IRunnableObject_SetContainedObject(runnable, fContained);
1088 IRunnableObject_Release(runnable);
1090 return hres;
1093 return S_OK;
1096 /******************************************************************************
1097 * OleRun [OLE32.@]
1099 * Set the OLE object to the running state.
1101 * PARAMS
1102 * pUnknown [I] OLE object to run.
1104 * RETURNS
1105 * Success: S_OK.
1106 * Failure: Any HRESULT code.
1108 HRESULT WINAPI OleRun(LPUNKNOWN pUnknown)
1110 IRunnableObject *runable;
1111 HRESULT hres;
1113 TRACE("(%p)\n", pUnknown);
1115 hres = IUnknown_QueryInterface(pUnknown, &IID_IRunnableObject, (void**)&runable);
1116 if (FAILED(hres))
1117 return S_OK; /* Appears to return no error. */
1119 hres = IRunnableObject_Run(runable, NULL);
1120 IRunnableObject_Release(runable);
1121 return hres;
1124 /******************************************************************************
1125 * OleLoad [OLE32.@]
1127 HRESULT WINAPI OleLoad(
1128 LPSTORAGE pStg,
1129 REFIID riid,
1130 LPOLECLIENTSITE pClientSite,
1131 LPVOID* ppvObj)
1133 IPersistStorage* persistStorage = NULL;
1134 IUnknown* pUnk;
1135 IOleObject* pOleObject = NULL;
1136 STATSTG storageInfo;
1137 HRESULT hres;
1139 TRACE("(%p, %s, %p, %p)\n", pStg, debugstr_guid(riid), pClientSite, ppvObj);
1141 *ppvObj = NULL;
1144 * TODO, Conversion ... OleDoAutoConvert
1148 * Get the class ID for the object.
1150 hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
1153 * Now, try and create the handler for the object
1155 hres = CoCreateInstance(&storageInfo.clsid,
1156 NULL,
1157 CLSCTX_INPROC_HANDLER|CLSCTX_INPROC_SERVER,
1158 riid,
1159 (void**)&pUnk);
1162 * If that fails, as it will most times, load the default
1163 * OLE handler.
1165 if (FAILED(hres))
1167 hres = OleCreateDefaultHandler(&storageInfo.clsid,
1168 NULL,
1169 riid,
1170 (void**)&pUnk);
1174 * If we couldn't find a handler... this is bad. Abort the whole thing.
1176 if (FAILED(hres))
1177 return hres;
1179 if (pClientSite)
1181 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (void **)&pOleObject);
1182 if (SUCCEEDED(hres))
1184 DWORD dwStatus;
1185 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
1190 * Initialize the object with its IPersistStorage interface.
1192 hres = IOleObject_QueryInterface(pUnk,
1193 &IID_IPersistStorage,
1194 (void**)&persistStorage);
1196 if (SUCCEEDED(hres))
1198 hres = IPersistStorage_Load(persistStorage, pStg);
1200 IPersistStorage_Release(persistStorage);
1201 persistStorage = NULL;
1204 if (SUCCEEDED(hres) && pClientSite)
1206 * Inform the new object of it's client site.
1208 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
1211 * Cleanup interfaces used internally
1213 if (pOleObject)
1214 IOleObject_Release(pOleObject);
1216 if (SUCCEEDED(hres))
1218 IOleLink *pOleLink;
1219 HRESULT hres1;
1220 hres1 = IUnknown_QueryInterface(pUnk, &IID_IOleLink, (void **)&pOleLink);
1221 if (SUCCEEDED(hres1))
1223 FIXME("handle OLE link\n");
1224 IOleLink_Release(pOleLink);
1228 if (FAILED(hres))
1230 IUnknown_Release(pUnk);
1231 pUnk = NULL;
1234 *ppvObj = pUnk;
1236 return hres;
1239 /***********************************************************************
1240 * OleSave [OLE32.@]
1242 HRESULT WINAPI OleSave(
1243 LPPERSISTSTORAGE pPS,
1244 LPSTORAGE pStg,
1245 BOOL fSameAsLoad)
1247 HRESULT hres;
1248 CLSID objectClass;
1250 TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
1253 * First, we transfer the class ID (if available)
1255 hres = IPersistStorage_GetClassID(pPS, &objectClass);
1257 if (SUCCEEDED(hres))
1259 WriteClassStg(pStg, &objectClass);
1263 * Then, we ask the object to save itself to the
1264 * storage. If it is successful, we commit the storage.
1266 hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
1268 if (SUCCEEDED(hres))
1270 IStorage_Commit(pStg,
1271 STGC_DEFAULT);
1274 return hres;
1278 /******************************************************************************
1279 * OleLockRunning [OLE32.@]
1281 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
1283 IRunnableObject* runnable = NULL;
1284 HRESULT hres;
1286 TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
1288 hres = IUnknown_QueryInterface(pUnknown,
1289 &IID_IRunnableObject,
1290 (void**)&runnable);
1292 if (SUCCEEDED(hres))
1294 hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
1296 IRunnableObject_Release(runnable);
1298 return hres;
1301 return S_OK;
1305 /**************************************************************************
1306 * Internal methods to manage the shared OLE menu in response to the
1307 * OLE***MenuDescriptor API
1310 /***
1311 * OLEMenu_Initialize()
1313 * Initializes the OLEMENU data structures.
1315 static void OLEMenu_Initialize(void)
1319 /***
1320 * OLEMenu_UnInitialize()
1322 * Releases the OLEMENU data structures.
1324 static void OLEMenu_UnInitialize(void)
1328 /*************************************************************************
1329 * OLEMenu_InstallHooks
1330 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1332 * RETURNS: TRUE if message hooks were successfully installed
1333 * FALSE on failure
1335 static BOOL OLEMenu_InstallHooks( DWORD tid )
1337 OleMenuHookItem *pHookItem;
1339 /* Create an entry for the hook table */
1340 if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
1341 sizeof(OleMenuHookItem)) ) )
1342 return FALSE;
1344 pHookItem->tid = tid;
1345 pHookItem->hHeap = GetProcessHeap();
1346 pHookItem->CallWndProc_hHook = NULL;
1348 /* Install a thread scope message hook for WH_GETMESSAGE */
1349 pHookItem->GetMsg_hHook = SetWindowsHookExW( WH_GETMESSAGE, OLEMenu_GetMsgProc,
1350 0, GetCurrentThreadId() );
1351 if ( !pHookItem->GetMsg_hHook )
1352 goto CLEANUP;
1354 /* Install a thread scope message hook for WH_CALLWNDPROC */
1355 pHookItem->CallWndProc_hHook = SetWindowsHookExW( WH_CALLWNDPROC, OLEMenu_CallWndProc,
1356 0, GetCurrentThreadId() );
1357 if ( !pHookItem->CallWndProc_hHook )
1358 goto CLEANUP;
1360 /* Insert the hook table entry */
1361 pHookItem->next = hook_list;
1362 hook_list = pHookItem;
1364 return TRUE;
1366 CLEANUP:
1367 /* Unhook any hooks */
1368 if ( pHookItem->GetMsg_hHook )
1369 UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
1370 if ( pHookItem->CallWndProc_hHook )
1371 UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
1372 /* Release the hook table entry */
1373 HeapFree(pHookItem->hHeap, 0, pHookItem );
1375 return FALSE;
1378 /*************************************************************************
1379 * OLEMenu_UnInstallHooks
1380 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1382 * RETURNS: TRUE if message hooks were successfully installed
1383 * FALSE on failure
1385 static BOOL OLEMenu_UnInstallHooks( DWORD tid )
1387 OleMenuHookItem *pHookItem = NULL;
1388 OleMenuHookItem **ppHook = &hook_list;
1390 while (*ppHook)
1392 if ((*ppHook)->tid == tid)
1394 pHookItem = *ppHook;
1395 *ppHook = pHookItem->next;
1396 break;
1398 ppHook = &(*ppHook)->next;
1400 if (!pHookItem) return FALSE;
1402 /* Uninstall the hooks installed for this thread */
1403 if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
1404 goto CLEANUP;
1405 if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
1406 goto CLEANUP;
1408 /* Release the hook table entry */
1409 HeapFree(pHookItem->hHeap, 0, pHookItem );
1411 return TRUE;
1413 CLEANUP:
1414 /* Release the hook table entry */
1415 HeapFree(pHookItem->hHeap, 0, pHookItem );
1417 return FALSE;
1420 /*************************************************************************
1421 * OLEMenu_IsHookInstalled
1422 * Tests if OLEMenu hooks have been installed for a thread
1424 * RETURNS: The pointer and index of the hook table entry for the tid
1425 * NULL and -1 for the index if no hooks were installed for this thread
1427 static OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
1429 OleMenuHookItem *pHookItem;
1431 /* Do a simple linear search for an entry whose tid matches ours.
1432 * We really need a map but efficiency is not a concern here. */
1433 for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
1435 if ( tid == pHookItem->tid )
1436 return pHookItem;
1439 return NULL;
1442 /***********************************************************************
1443 * OLEMenu_FindMainMenuIndex
1445 * Used by OLEMenu API to find the top level group a menu item belongs to.
1446 * On success pnPos contains the index of the item in the top level menu group
1448 * RETURNS: TRUE if the ID was found, FALSE on failure
1450 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1452 INT i, nItems;
1454 nItems = GetMenuItemCount( hMainMenu );
1456 for (i = 0; i < nItems; i++)
1458 HMENU hsubmenu;
1460 /* Is the current item a submenu? */
1461 if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1463 /* If the handle is the same we're done */
1464 if ( hsubmenu == hPopupMenu )
1466 if (pnPos)
1467 *pnPos = i;
1468 return TRUE;
1470 /* Recursively search without updating pnPos */
1471 else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1473 if (pnPos)
1474 *pnPos = i;
1475 return TRUE;
1480 return FALSE;
1483 /***********************************************************************
1484 * OLEMenu_SetIsServerMenu
1486 * Checks whether a popup menu belongs to a shared menu group which is
1487 * owned by the server, and sets the menu descriptor state accordingly.
1488 * All menu messages from these groups should be routed to the server.
1490 * RETURNS: TRUE if the popup menu is part of a server owned group
1491 * FALSE if the popup menu is part of a container owned group
1493 static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1495 UINT nPos = 0, nWidth, i;
1497 pOleMenuDescriptor->bIsServerItem = FALSE;
1499 /* Don't bother searching if the popup is the combined menu itself */
1500 if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1501 return FALSE;
1503 /* Find the menu item index in the shared OLE menu that this item belongs to */
1504 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu, &nPos ) )
1505 return FALSE;
1507 /* The group widths array has counts for the number of elements
1508 * in the groups File, Edit, Container, Object, Window, Help.
1509 * The Edit, Object & Help groups belong to the server object
1510 * and the other three belong to the container.
1511 * Loop through the group widths and locate the group we are a member of.
1513 for ( i = 0, nWidth = 0; i < 6; i++ )
1515 nWidth += pOleMenuDescriptor->mgw.width[i];
1516 if ( nPos < nWidth )
1518 /* Odd elements are server menu widths */
1519 pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1520 break;
1524 return pOleMenuDescriptor->bIsServerItem;
1527 /*************************************************************************
1528 * OLEMenu_CallWndProc
1529 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1530 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1532 static LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1534 LPCWPSTRUCT pMsg;
1535 HOLEMENU hOleMenu = 0;
1536 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1537 OleMenuHookItem *pHookItem = NULL;
1538 WORD fuFlags;
1540 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1542 /* Check if we're being asked to process the message */
1543 if ( HC_ACTION != code )
1544 goto NEXTHOOK;
1546 /* Retrieve the current message being dispatched from lParam */
1547 pMsg = (LPCWPSTRUCT)lParam;
1549 /* Check if the message is destined for a window we are interested in:
1550 * If the window has an OLEMenu property we may need to dispatch
1551 * the menu message to its active objects window instead. */
1553 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1554 if ( !hOleMenu )
1555 goto NEXTHOOK;
1557 /* Get the menu descriptor */
1558 pOleMenuDescriptor = GlobalLock( hOleMenu );
1559 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1560 goto NEXTHOOK;
1562 /* Process menu messages */
1563 switch( pMsg->message )
1565 case WM_INITMENU:
1567 /* Reset the menu descriptor state */
1568 pOleMenuDescriptor->bIsServerItem = FALSE;
1570 /* Send this message to the server as well */
1571 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1572 pMsg->message, pMsg->wParam, pMsg->lParam );
1573 goto NEXTHOOK;
1576 case WM_INITMENUPOPUP:
1578 /* Save the state for whether this is a server owned menu */
1579 OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1580 break;
1583 case WM_MENUSELECT:
1585 fuFlags = HIWORD(pMsg->wParam); /* Get flags */
1586 if ( fuFlags & MF_SYSMENU )
1587 goto NEXTHOOK;
1589 /* Save the state for whether this is a server owned popup menu */
1590 else if ( fuFlags & MF_POPUP )
1591 OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1593 break;
1596 case WM_DRAWITEM:
1598 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1599 if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1600 goto NEXTHOOK; /* Not a menu message */
1602 break;
1605 default:
1606 goto NEXTHOOK;
1609 /* If the message was for the server dispatch it accordingly */
1610 if ( pOleMenuDescriptor->bIsServerItem )
1612 SendMessageW( pOleMenuDescriptor->hwndActiveObject,
1613 pMsg->message, pMsg->wParam, pMsg->lParam );
1616 NEXTHOOK:
1617 if ( pOleMenuDescriptor )
1618 GlobalUnlock( hOleMenu );
1620 /* Lookup the hook item for the current thread */
1621 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1623 /* This should never fail!! */
1624 WARN("could not retrieve hHook for current thread!\n" );
1625 return 0;
1628 /* Pass on the message to the next hooker */
1629 return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1632 /*************************************************************************
1633 * OLEMenu_GetMsgProc
1634 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1635 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1637 static LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1639 LPMSG pMsg;
1640 HOLEMENU hOleMenu = 0;
1641 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1642 OleMenuHookItem *pHookItem = NULL;
1643 WORD wCode;
1645 TRACE("%i, %04lx, %08lx\n", code, wParam, lParam );
1647 /* Check if we're being asked to process a messages */
1648 if ( HC_ACTION != code )
1649 goto NEXTHOOK;
1651 /* Retrieve the current message being dispatched from lParam */
1652 pMsg = (LPMSG)lParam;
1654 /* Check if the message is destined for a window we are interested in:
1655 * If the window has an OLEMenu property we may need to dispatch
1656 * the menu message to its active objects window instead. */
1658 hOleMenu = GetPropW( pMsg->hwnd, prop_olemenuW );
1659 if ( !hOleMenu )
1660 goto NEXTHOOK;
1662 /* Process menu messages */
1663 switch( pMsg->message )
1665 case WM_COMMAND:
1667 wCode = HIWORD(pMsg->wParam); /* Get notification code */
1668 if ( wCode )
1669 goto NEXTHOOK; /* Not a menu message */
1670 break;
1672 default:
1673 goto NEXTHOOK;
1676 /* Get the menu descriptor */
1677 pOleMenuDescriptor = GlobalLock( hOleMenu );
1678 if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1679 goto NEXTHOOK;
1681 /* If the message was for the server dispatch it accordingly */
1682 if ( pOleMenuDescriptor->bIsServerItem )
1684 /* Change the hWnd in the message to the active objects hWnd.
1685 * The message loop which reads this message will automatically
1686 * dispatch it to the embedded objects window. */
1687 pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1690 NEXTHOOK:
1691 if ( pOleMenuDescriptor )
1692 GlobalUnlock( hOleMenu );
1694 /* Lookup the hook item for the current thread */
1695 if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1697 /* This should never fail!! */
1698 WARN("could not retrieve hHook for current thread!\n" );
1699 return FALSE;
1702 /* Pass on the message to the next hooker */
1703 return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1706 /***********************************************************************
1707 * OleCreateMenuDescriptor [OLE32.@]
1708 * Creates an OLE menu descriptor for OLE to use when dispatching
1709 * menu messages and commands.
1711 * PARAMS:
1712 * hmenuCombined - Handle to the objects combined menu
1713 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1716 HOLEMENU WINAPI OleCreateMenuDescriptor(
1717 HMENU hmenuCombined,
1718 LPOLEMENUGROUPWIDTHS lpMenuWidths)
1720 HOLEMENU hOleMenu;
1721 OleMenuDescriptor *pOleMenuDescriptor;
1722 int i;
1724 if ( !hmenuCombined || !lpMenuWidths )
1725 return 0;
1727 /* Create an OLE menu descriptor */
1728 if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1729 sizeof(OleMenuDescriptor) ) ) )
1730 return 0;
1732 pOleMenuDescriptor = GlobalLock( hOleMenu );
1733 if ( !pOleMenuDescriptor )
1734 return 0;
1736 /* Initialize menu group widths and hmenu */
1737 for ( i = 0; i < 6; i++ )
1738 pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1740 pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1741 pOleMenuDescriptor->bIsServerItem = FALSE;
1742 GlobalUnlock( hOleMenu );
1744 return hOleMenu;
1747 /***********************************************************************
1748 * OleDestroyMenuDescriptor [OLE32.@]
1749 * Destroy the shared menu descriptor
1751 HRESULT WINAPI OleDestroyMenuDescriptor(
1752 HOLEMENU hmenuDescriptor)
1754 if ( hmenuDescriptor )
1755 GlobalFree( hmenuDescriptor );
1756 return S_OK;
1759 /***********************************************************************
1760 * OleSetMenuDescriptor [OLE32.@]
1761 * Installs or removes OLE dispatching code for the containers frame window.
1763 * PARAMS
1764 * hOleMenu Handle to composite menu descriptor
1765 * hwndFrame Handle to containers frame window
1766 * hwndActiveObject Handle to objects in-place activation window
1767 * lpFrame Pointer to IOleInPlaceFrame on containers window
1768 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1770 * RETURNS
1771 * S_OK - menu installed correctly
1772 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1774 * FIXME
1775 * The lpFrame and lpActiveObject parameters are currently ignored
1776 * OLE should install context sensitive help F1 filtering for the app when
1777 * these are non null.
1779 HRESULT WINAPI OleSetMenuDescriptor(
1780 HOLEMENU hOleMenu,
1781 HWND hwndFrame,
1782 HWND hwndActiveObject,
1783 LPOLEINPLACEFRAME lpFrame,
1784 LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1786 OleMenuDescriptor *pOleMenuDescriptor = NULL;
1788 /* Check args */
1789 if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1790 return E_INVALIDARG;
1792 if ( lpFrame || lpActiveObject )
1794 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1795 hOleMenu,
1796 hwndFrame,
1797 hwndActiveObject,
1798 lpFrame,
1799 lpActiveObject);
1802 /* Set up a message hook to intercept the containers frame window messages.
1803 * The message filter is responsible for dispatching menu messages from the
1804 * shared menu which are intended for the object.
1807 if ( hOleMenu ) /* Want to install dispatching code */
1809 /* If OLEMenu hooks are already installed for this thread, fail
1810 * Note: This effectively means that OleSetMenuDescriptor cannot
1811 * be called twice in succession on the same frame window
1812 * without first calling it with a null hOleMenu to uninstall */
1813 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1814 return E_FAIL;
1816 /* Get the menu descriptor */
1817 pOleMenuDescriptor = GlobalLock( hOleMenu );
1818 if ( !pOleMenuDescriptor )
1819 return E_UNEXPECTED;
1821 /* Update the menu descriptor */
1822 pOleMenuDescriptor->hwndFrame = hwndFrame;
1823 pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1825 GlobalUnlock( hOleMenu );
1826 pOleMenuDescriptor = NULL;
1828 /* Add a menu descriptor windows property to the frame window */
1829 SetPropW( hwndFrame, prop_olemenuW, hOleMenu );
1831 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1832 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1833 return E_FAIL;
1835 else /* Want to uninstall dispatching code */
1837 /* Uninstall the hooks */
1838 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1839 return E_FAIL;
1841 /* Remove the menu descriptor property from the frame window */
1842 RemovePropW( hwndFrame, prop_olemenuW );
1845 return S_OK;
1848 /******************************************************************************
1849 * IsAccelerator [OLE32.@]
1850 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1852 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1854 LPACCEL lpAccelTbl;
1855 int i;
1857 if(!lpMsg) return FALSE;
1858 if (!hAccel)
1860 WARN_(accel)("NULL accel handle\n");
1861 return FALSE;
1863 if((lpMsg->message != WM_KEYDOWN &&
1864 lpMsg->message != WM_SYSKEYDOWN &&
1865 lpMsg->message != WM_SYSCHAR &&
1866 lpMsg->message != WM_CHAR)) return FALSE;
1867 lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1868 if (NULL == lpAccelTbl)
1870 return FALSE;
1872 if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1874 WARN_(accel)("CopyAcceleratorTableW failed\n");
1875 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1876 return FALSE;
1879 TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1880 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1881 hAccel, cAccelEntries,
1882 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1883 for(i = 0; i < cAccelEntries; i++)
1885 if(lpAccelTbl[i].key != lpMsg->wParam)
1886 continue;
1888 if(lpMsg->message == WM_CHAR)
1890 if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1892 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg->wParam) & 0xff);
1893 goto found;
1896 else
1898 if(lpAccelTbl[i].fVirt & FVIRTKEY)
1900 INT mask = 0;
1901 TRACE_(accel)("found accel for virt_key %04lx (scan %04x)\n",
1902 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1903 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1904 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1905 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1906 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1907 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1909 else
1911 if(!(lpMsg->lParam & 0x01000000)) /* no special_key */
1913 if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1914 { /* ^^ ALT pressed */
1915 TRACE_(accel)("found accel for Alt-%c\n", LOWORD(lpMsg->wParam) & 0xff);
1916 goto found;
1923 WARN_(accel)("couldn't translate accelerator key\n");
1924 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1925 return FALSE;
1927 found:
1928 if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1929 HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1930 return TRUE;
1933 /***********************************************************************
1934 * ReleaseStgMedium [OLE32.@]
1936 void WINAPI ReleaseStgMedium(
1937 STGMEDIUM* pmedium)
1939 switch (pmedium->tymed)
1941 case TYMED_HGLOBAL:
1943 if ( (pmedium->pUnkForRelease==0) &&
1944 (pmedium->u.hGlobal!=0) )
1945 GlobalFree(pmedium->u.hGlobal);
1946 break;
1948 case TYMED_FILE:
1950 if (pmedium->u.lpszFileName!=0)
1952 if (pmedium->pUnkForRelease==0)
1954 DeleteFileW(pmedium->u.lpszFileName);
1957 CoTaskMemFree(pmedium->u.lpszFileName);
1959 break;
1961 case TYMED_ISTREAM:
1963 if (pmedium->u.pstm!=0)
1965 IStream_Release(pmedium->u.pstm);
1967 break;
1969 case TYMED_ISTORAGE:
1971 if (pmedium->u.pstg!=0)
1973 IStorage_Release(pmedium->u.pstg);
1975 break;
1977 case TYMED_GDI:
1979 if ( (pmedium->pUnkForRelease==0) &&
1980 (pmedium->u.hBitmap!=0) )
1981 DeleteObject(pmedium->u.hBitmap);
1982 break;
1984 case TYMED_MFPICT:
1986 if ( (pmedium->pUnkForRelease==0) &&
1987 (pmedium->u.hMetaFilePict!=0) )
1989 LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1990 DeleteMetaFile(pMP->hMF);
1991 GlobalUnlock(pmedium->u.hMetaFilePict);
1992 GlobalFree(pmedium->u.hMetaFilePict);
1994 break;
1996 case TYMED_ENHMF:
1998 if ( (pmedium->pUnkForRelease==0) &&
1999 (pmedium->u.hEnhMetaFile!=0) )
2001 DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
2003 break;
2005 case TYMED_NULL:
2006 default:
2007 break;
2009 pmedium->tymed=TYMED_NULL;
2012 * After cleaning up, the unknown is released
2014 if (pmedium->pUnkForRelease!=0)
2016 IUnknown_Release(pmedium->pUnkForRelease);
2017 pmedium->pUnkForRelease = 0;
2021 /***
2022 * OLEDD_Initialize()
2024 * Initializes the OLE drag and drop data structures.
2026 static void OLEDD_Initialize(void)
2028 WNDCLASSW wndClass;
2030 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2031 wndClass.style = CS_GLOBALCLASS;
2032 wndClass.lpfnWndProc = OLEDD_DragTrackerWindowProc;
2033 wndClass.cbClsExtra = 0;
2034 wndClass.cbWndExtra = sizeof(TrackerWindowInfo*);
2035 wndClass.hCursor = 0;
2036 wndClass.hbrBackground = 0;
2037 wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
2039 RegisterClassW (&wndClass);
2042 /***
2043 * OLEDD_DragTrackerWindowProc()
2045 * This method is the WindowProcedure of the drag n drop tracking
2046 * window. During a drag n Drop operation, an invisible window is created
2047 * to receive the user input and act upon it. This procedure is in charge
2048 * of this behavior.
2051 #define DRAG_TIMER_ID 1
2053 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
2054 HWND hwnd,
2055 UINT uMsg,
2056 WPARAM wParam,
2057 LPARAM lParam)
2059 switch (uMsg)
2061 case WM_CREATE:
2063 LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
2065 SetWindowLongPtrW(hwnd, 0, (LONG_PTR)createStruct->lpCreateParams);
2066 SetTimer(hwnd, DRAG_TIMER_ID, 50, NULL);
2068 break;
2070 case WM_TIMER:
2071 case WM_MOUSEMOVE:
2073 OLEDD_TrackMouseMove((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
2074 break;
2076 case WM_LBUTTONUP:
2077 case WM_MBUTTONUP:
2078 case WM_RBUTTONUP:
2079 case WM_LBUTTONDOWN:
2080 case WM_MBUTTONDOWN:
2081 case WM_RBUTTONDOWN:
2083 OLEDD_TrackStateChange((TrackerWindowInfo*)GetWindowLongPtrA(hwnd, 0));
2084 break;
2086 case WM_DESTROY:
2088 KillTimer(hwnd, DRAG_TIMER_ID);
2089 break;
2094 * This is a window proc after all. Let's call the default.
2096 return DefWindowProcW (hwnd, uMsg, wParam, lParam);
2099 /***
2100 * OLEDD_TrackMouseMove()
2102 * This method is invoked while a drag and drop operation is in effect.
2103 * it will generate the appropriate callbacks in the drop source
2104 * and drop target. It will also provide the expected feedback to
2105 * the user.
2107 * params:
2108 * trackerInfo - Pointer to the structure identifying the
2109 * drag & drop operation that is currently
2110 * active.
2112 static void OLEDD_TrackMouseMove(TrackerWindowInfo* trackerInfo)
2114 HWND hwndNewTarget = 0;
2115 HRESULT hr = S_OK;
2116 POINT pt;
2119 * Get the handle of the window under the mouse
2121 pt.x = trackerInfo->curMousePos.x;
2122 pt.y = trackerInfo->curMousePos.y;
2123 hwndNewTarget = WindowFromPoint(pt);
2126 * Every time, we re-initialize the effects passed to the
2127 * IDropTarget to the effects allowed by the source.
2129 *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
2132 * If we are hovering over the same target as before, send the
2133 * DragOver notification
2135 if ( (trackerInfo->curDragTarget != 0) &&
2136 (trackerInfo->curTargetHWND == hwndNewTarget) )
2138 IDropTarget_DragOver(trackerInfo->curDragTarget,
2139 trackerInfo->dwKeyState,
2140 trackerInfo->curMousePos,
2141 trackerInfo->pdwEffect);
2143 else
2146 * If we changed window, we have to notify our old target and check for
2147 * the new one.
2149 if (trackerInfo->curDragTarget)
2150 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2153 * Make sure we're hovering over a window.
2155 if (hwndNewTarget)
2158 * Find-out if there is a drag target under the mouse
2160 HWND next_target_wnd = hwndNewTarget;
2162 trackerInfo->curTargetHWND = hwndNewTarget;
2164 while (next_target_wnd && !is_droptarget(next_target_wnd))
2165 next_target_wnd = GetParent(next_target_wnd);
2167 if (next_target_wnd) hwndNewTarget = next_target_wnd;
2169 trackerInfo->curDragTargetHWND = hwndNewTarget;
2170 if(trackerInfo->curDragTarget) IDropTarget_Release(trackerInfo->curDragTarget);
2171 trackerInfo->curDragTarget = get_droptarget_pointer(hwndNewTarget);
2174 * If there is, notify it that we just dragged-in
2176 if (trackerInfo->curDragTarget)
2178 hr = IDropTarget_DragEnter(trackerInfo->curDragTarget,
2179 trackerInfo->dataObject,
2180 trackerInfo->dwKeyState,
2181 trackerInfo->curMousePos,
2182 trackerInfo->pdwEffect);
2184 /* failed DragEnter() means invalid target */
2185 if (hr != S_OK)
2187 trackerInfo->curDragTargetHWND = 0;
2188 trackerInfo->curTargetHWND = 0;
2189 IDropTarget_Release(trackerInfo->curDragTarget);
2190 trackerInfo->curDragTarget = 0;
2194 else
2197 * The mouse is not over a window so we don't track anything.
2199 trackerInfo->curDragTargetHWND = 0;
2200 trackerInfo->curTargetHWND = 0;
2201 if(trackerInfo->curDragTarget) IDropTarget_Release(trackerInfo->curDragTarget);
2202 trackerInfo->curDragTarget = 0;
2207 * Now that we have done that, we have to tell the source to give
2208 * us feedback on the work being done by the target. If we don't
2209 * have a target, simulate no effect.
2211 if (trackerInfo->curDragTarget==0)
2213 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2216 hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
2217 *trackerInfo->pdwEffect);
2220 * When we ask for feedback from the drop source, sometimes it will
2221 * do all the necessary work and sometimes it will not handle it
2222 * when that's the case, we must display the standard drag and drop
2223 * cursors.
2225 if (hr == DRAGDROP_S_USEDEFAULTCURSORS)
2227 HCURSOR hCur;
2229 if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2231 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(2));
2233 else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2235 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(3));
2237 else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2239 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(4));
2241 else
2243 hCur = LoadCursorW(hProxyDll, MAKEINTRESOURCEW(1));
2246 SetCursor(hCur);
2250 /***
2251 * OLEDD_TrackStateChange()
2253 * This method is invoked while a drag and drop operation is in effect.
2254 * It is used to notify the drop target/drop source callbacks when
2255 * the state of the keyboard or mouse button change.
2257 * params:
2258 * trackerInfo - Pointer to the structure identifying the
2259 * drag & drop operation that is currently
2260 * active.
2262 static void OLEDD_TrackStateChange(TrackerWindowInfo* trackerInfo)
2265 * Ask the drop source what to do with the operation.
2267 trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2268 trackerInfo->dropSource,
2269 trackerInfo->escPressed,
2270 trackerInfo->dwKeyState);
2273 * All the return valued will stop the operation except the S_OK
2274 * return value.
2276 if (trackerInfo->returnValue!=S_OK)
2279 * Make sure the message loop in DoDragDrop stops
2281 trackerInfo->trackingDone = TRUE;
2284 * Release the mouse in case the drop target decides to show a popup
2285 * or a menu or something.
2287 ReleaseCapture();
2290 * If we end-up over a target, drop the object in the target or
2291 * inform the target that the operation was cancelled.
2293 if (trackerInfo->curDragTarget)
2295 switch (trackerInfo->returnValue)
2298 * If the source wants us to complete the operation, we tell
2299 * the drop target that we just dropped the object in it.
2301 case DRAGDROP_S_DROP:
2302 if (*trackerInfo->pdwEffect != DROPEFFECT_NONE)
2303 IDropTarget_Drop(trackerInfo->curDragTarget,
2304 trackerInfo->dataObject,
2305 trackerInfo->dwKeyState,
2306 trackerInfo->curMousePos,
2307 trackerInfo->pdwEffect);
2308 else
2309 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2310 break;
2313 * If the source told us that we should cancel, fool the drop
2314 * target by telling it that the mouse left it's window.
2315 * Also set the drop effect to "NONE" in case the application
2316 * ignores the result of DoDragDrop.
2318 case DRAGDROP_S_CANCEL:
2319 IDropTarget_DragLeave(trackerInfo->curDragTarget);
2320 *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2321 break;
2327 /***
2328 * OLEDD_GetButtonState()
2330 * This method will use the current state of the keyboard to build
2331 * a button state mask equivalent to the one passed in the
2332 * WM_MOUSEMOVE wParam.
2334 static DWORD OLEDD_GetButtonState(void)
2336 BYTE keyboardState[256];
2337 DWORD keyMask = 0;
2339 GetKeyboardState(keyboardState);
2341 if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2342 keyMask |= MK_SHIFT;
2344 if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2345 keyMask |= MK_CONTROL;
2347 if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2348 keyMask |= MK_LBUTTON;
2350 if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2351 keyMask |= MK_RBUTTON;
2353 if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2354 keyMask |= MK_MBUTTON;
2356 return keyMask;
2359 /***
2360 * OLEDD_GetButtonState()
2362 * This method will read the default value of the registry key in
2363 * parameter and extract a DWORD value from it. The registry key value
2364 * can be in a string key or a DWORD key.
2366 * params:
2367 * regKey - Key to read the default value from
2368 * pdwValue - Pointer to the location where the DWORD
2369 * value is returned. This value is not modified
2370 * if the value is not found.
2373 static void OLEUTL_ReadRegistryDWORDValue(
2374 HKEY regKey,
2375 DWORD* pdwValue)
2377 WCHAR buffer[20];
2378 DWORD cbData = sizeof(buffer);
2379 DWORD dwKeyType;
2380 LONG lres;
2382 lres = RegQueryValueExW(regKey,
2383 emptyW,
2384 NULL,
2385 &dwKeyType,
2386 (LPBYTE)buffer,
2387 &cbData);
2389 if (lres==ERROR_SUCCESS)
2391 switch (dwKeyType)
2393 case REG_DWORD:
2394 *pdwValue = *(DWORD*)buffer;
2395 break;
2396 case REG_EXPAND_SZ:
2397 case REG_MULTI_SZ:
2398 case REG_SZ:
2399 *pdwValue = (DWORD)strtoulW(buffer, NULL, 10);
2400 break;
2405 /******************************************************************************
2406 * OleDraw (OLE32.@)
2408 * The operation of this function is documented literally in the WinAPI
2409 * documentation to involve a QueryInterface for the IViewObject interface,
2410 * followed by a call to IViewObject::Draw.
2412 HRESULT WINAPI OleDraw(
2413 IUnknown *pUnk,
2414 DWORD dwAspect,
2415 HDC hdcDraw,
2416 LPCRECT lprcBounds)
2418 HRESULT hres;
2419 IViewObject *viewobject;
2421 hres = IUnknown_QueryInterface(pUnk,
2422 &IID_IViewObject,
2423 (void**)&viewobject);
2425 if (SUCCEEDED(hres))
2427 RECTL rectl;
2429 rectl.left = lprcBounds->left;
2430 rectl.right = lprcBounds->right;
2431 rectl.top = lprcBounds->top;
2432 rectl.bottom = lprcBounds->bottom;
2433 hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2435 IViewObject_Release(viewobject);
2436 return hres;
2438 else
2440 return DV_E_NOIVIEWOBJECT;
2444 /***********************************************************************
2445 * OleTranslateAccelerator [OLE32.@]
2447 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2448 LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2450 WORD wID;
2452 TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2454 if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2455 return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2457 return S_FALSE;
2460 /******************************************************************************
2461 * OleCreate [OLE32.@]
2464 HRESULT WINAPI OleCreate(
2465 REFCLSID rclsid,
2466 REFIID riid,
2467 DWORD renderopt,
2468 LPFORMATETC pFormatEtc,
2469 LPOLECLIENTSITE pClientSite,
2470 LPSTORAGE pStg,
2471 LPVOID* ppvObj)
2473 HRESULT hres;
2474 IUnknown * pUnk = NULL;
2475 IOleObject *pOleObject = NULL;
2477 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid),
2478 debugstr_guid(riid), renderopt, pFormatEtc, pClientSite, pStg, ppvObj);
2480 hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, riid, (LPVOID*)&pUnk);
2482 if (SUCCEEDED(hres))
2483 hres = IStorage_SetClass(pStg, rclsid);
2485 if (pClientSite && SUCCEEDED(hres))
2487 hres = IUnknown_QueryInterface(pUnk, &IID_IOleObject, (LPVOID*)&pOleObject);
2488 if (SUCCEEDED(hres))
2490 DWORD dwStatus;
2491 hres = IOleObject_GetMiscStatus(pOleObject, DVASPECT_CONTENT, &dwStatus);
2495 if (SUCCEEDED(hres))
2497 IPersistStorage * pPS;
2498 if (SUCCEEDED((hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2500 TRACE("trying to set stg %p\n", pStg);
2501 hres = IPersistStorage_InitNew(pPS, pStg);
2502 TRACE("-- result 0x%08x\n", hres);
2503 IPersistStorage_Release(pPS);
2507 if (pClientSite && SUCCEEDED(hres))
2509 TRACE("trying to set clientsite %p\n", pClientSite);
2510 hres = IOleObject_SetClientSite(pOleObject, pClientSite);
2511 TRACE("-- result 0x%08x\n", hres);
2514 if (pOleObject)
2515 IOleObject_Release(pOleObject);
2517 if (((renderopt == OLERENDER_DRAW) || (renderopt == OLERENDER_FORMAT)) &&
2518 SUCCEEDED(hres))
2520 IRunnableObject *pRunnable;
2521 IOleCache *pOleCache;
2522 HRESULT hres2;
2524 hres2 = IUnknown_QueryInterface(pUnk, &IID_IRunnableObject, (void **)&pRunnable);
2525 if (SUCCEEDED(hres2))
2527 hres = IRunnableObject_Run(pRunnable, NULL);
2528 IRunnableObject_Release(pRunnable);
2531 if (SUCCEEDED(hres))
2533 hres2 = IUnknown_QueryInterface(pUnk, &IID_IOleCache, (void **)&pOleCache);
2534 if (SUCCEEDED(hres2))
2536 DWORD dwConnection;
2537 if (renderopt == OLERENDER_DRAW && !pFormatEtc) {
2538 FORMATETC pfe;
2539 pfe.cfFormat = 0;
2540 pfe.ptd = NULL;
2541 pfe.dwAspect = DVASPECT_CONTENT;
2542 pfe.lindex = -1;
2543 pfe.tymed = TYMED_NULL;
2544 hres = IOleCache_Cache(pOleCache, &pfe, ADVF_PRIMEFIRST, &dwConnection);
2546 else
2547 hres = IOleCache_Cache(pOleCache, pFormatEtc, ADVF_PRIMEFIRST, &dwConnection);
2548 IOleCache_Release(pOleCache);
2553 if (FAILED(hres) && pUnk)
2555 IUnknown_Release(pUnk);
2556 pUnk = NULL;
2559 *ppvObj = pUnk;
2561 TRACE("-- %p\n", pUnk);
2562 return hres;
2565 /******************************************************************************
2566 * OleGetAutoConvert [OLE32.@]
2568 HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
2570 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2571 HKEY hkey = NULL;
2572 WCHAR buf[CHARS_IN_GUID];
2573 LONG len;
2574 HRESULT res = S_OK;
2576 res = COM_OpenKeyForCLSID(clsidOld, wszAutoConvertTo, KEY_READ, &hkey);
2577 if (FAILED(res))
2578 goto done;
2580 len = sizeof(buf);
2581 if (RegQueryValueW(hkey, NULL, buf, &len))
2583 res = REGDB_E_KEYMISSING;
2584 goto done;
2586 res = CLSIDFromString(buf, pClsidNew);
2587 done:
2588 if (hkey) RegCloseKey(hkey);
2589 return res;
2592 /******************************************************************************
2593 * OleSetAutoConvert [OLE32.@]
2595 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2597 static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2598 HKEY hkey = NULL;
2599 WCHAR szClsidNew[CHARS_IN_GUID];
2600 HRESULT res = S_OK;
2602 TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2604 res = COM_OpenKeyForCLSID(clsidOld, NULL, KEY_READ | KEY_WRITE, &hkey);
2605 if (FAILED(res))
2606 goto done;
2607 StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2608 if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2610 res = REGDB_E_WRITEREGDB;
2611 goto done;
2614 done:
2615 if (hkey) RegCloseKey(hkey);
2616 return res;
2619 /******************************************************************************
2620 * OleDoAutoConvert [OLE32.@]
2622 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2624 FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2625 return E_NOTIMPL;
2628 /******************************************************************************
2629 * OleIsRunning [OLE32.@]
2631 BOOL WINAPI OleIsRunning(LPOLEOBJECT object)
2633 IRunnableObject *pRunnable;
2634 HRESULT hr;
2635 BOOL running;
2637 TRACE("(%p)\n", object);
2639 if (!object) return FALSE;
2641 hr = IOleObject_QueryInterface(object, &IID_IRunnableObject, (void **)&pRunnable);
2642 if (FAILED(hr))
2643 return TRUE;
2644 running = IRunnableObject_IsRunning(pRunnable);
2645 IRunnableObject_Release(pRunnable);
2646 return running;
2649 /***********************************************************************
2650 * OleNoteObjectVisible [OLE32.@]
2652 HRESULT WINAPI OleNoteObjectVisible(LPUNKNOWN pUnknown, BOOL bVisible)
2654 TRACE("(%p, %s)\n", pUnknown, bVisible ? "TRUE" : "FALSE");
2655 return CoLockObjectExternal(pUnknown, bVisible, TRUE);
2659 /***********************************************************************
2660 * OLE_FreeClipDataArray [internal]
2662 * NOTES:
2663 * frees the data associated with an array of CLIPDATAs
2665 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2667 ULONG i;
2668 for (i = 0; i < count; i++)
2669 if (pClipDataArray[i].pClipData)
2670 CoTaskMemFree(pClipDataArray[i].pClipData);
2673 /***********************************************************************
2674 * PropSysAllocString [OLE32.@]
2675 * NOTES:
2676 * Basically a copy of SysAllocStringLen.
2678 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2680 DWORD bufferSize;
2681 DWORD* newBuffer;
2682 WCHAR* stringBuffer;
2683 int len;
2685 if (!str) return 0;
2687 len = lstrlenW(str);
2689 * Find the length of the buffer passed-in, in bytes.
2691 bufferSize = len * sizeof (WCHAR);
2694 * Allocate a new buffer to hold the string.
2695 * Don't forget to keep an empty spot at the beginning of the
2696 * buffer for the character count and an extra character at the
2697 * end for the NULL.
2699 newBuffer = HeapAlloc(GetProcessHeap(), 0,
2700 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2703 * If the memory allocation failed, return a null pointer.
2705 if (newBuffer==0)
2706 return 0;
2709 * Copy the length of the string in the placeholder.
2711 *newBuffer = bufferSize;
2714 * Skip the byte count.
2716 newBuffer++;
2718 memcpy(newBuffer, str, bufferSize);
2721 * Make sure that there is a nul character at the end of the
2722 * string.
2724 stringBuffer = (WCHAR*)newBuffer;
2725 stringBuffer[len] = '\0';
2727 return stringBuffer;
2730 /***********************************************************************
2731 * PropSysFreeString [OLE32.@]
2732 * NOTES
2733 * Copy of SysFreeString.
2735 void WINAPI PropSysFreeString(LPOLESTR str)
2737 DWORD* bufferPointer;
2739 /* NULL is a valid parameter */
2740 if(!str) return;
2743 * We have to be careful when we free a BSTR pointer, it points to
2744 * the beginning of the string but it skips the byte count contained
2745 * before the string.
2747 bufferPointer = (DWORD*)str;
2749 bufferPointer--;
2752 * Free the memory from its "real" origin.
2754 HeapFree(GetProcessHeap(), 0, bufferPointer);
2757 /******************************************************************************
2758 * Check if a PROPVARIANT's type is valid.
2760 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2762 switch (vt)
2764 case VT_EMPTY:
2765 case VT_NULL:
2766 case VT_I2:
2767 case VT_I4:
2768 case VT_R4:
2769 case VT_R8:
2770 case VT_CY:
2771 case VT_DATE:
2772 case VT_BSTR:
2773 case VT_ERROR:
2774 case VT_BOOL:
2775 case VT_DECIMAL:
2776 case VT_UI1:
2777 case VT_UI2:
2778 case VT_UI4:
2779 case VT_I8:
2780 case VT_UI8:
2781 case VT_LPSTR:
2782 case VT_LPWSTR:
2783 case VT_FILETIME:
2784 case VT_BLOB:
2785 case VT_STREAM:
2786 case VT_STORAGE:
2787 case VT_STREAMED_OBJECT:
2788 case VT_STORED_OBJECT:
2789 case VT_BLOB_OBJECT:
2790 case VT_CF:
2791 case VT_CLSID:
2792 case VT_I2|VT_VECTOR:
2793 case VT_I4|VT_VECTOR:
2794 case VT_R4|VT_VECTOR:
2795 case VT_R8|VT_VECTOR:
2796 case VT_CY|VT_VECTOR:
2797 case VT_DATE|VT_VECTOR:
2798 case VT_BSTR|VT_VECTOR:
2799 case VT_ERROR|VT_VECTOR:
2800 case VT_BOOL|VT_VECTOR:
2801 case VT_VARIANT|VT_VECTOR:
2802 case VT_UI1|VT_VECTOR:
2803 case VT_UI2|VT_VECTOR:
2804 case VT_UI4|VT_VECTOR:
2805 case VT_I8|VT_VECTOR:
2806 case VT_UI8|VT_VECTOR:
2807 case VT_LPSTR|VT_VECTOR:
2808 case VT_LPWSTR|VT_VECTOR:
2809 case VT_FILETIME|VT_VECTOR:
2810 case VT_CF|VT_VECTOR:
2811 case VT_CLSID|VT_VECTOR:
2812 return S_OK;
2814 WARN("Bad type %d\n", vt);
2815 return STG_E_INVALIDPARAMETER;
2818 /***********************************************************************
2819 * PropVariantClear [OLE32.@]
2821 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2823 HRESULT hr;
2825 TRACE("(%p)\n", pvar);
2827 if (!pvar)
2828 return S_OK;
2830 hr = PROPVARIANT_ValidateType(pvar->vt);
2831 if (FAILED(hr))
2832 return hr;
2834 switch(pvar->vt)
2836 case VT_EMPTY:
2837 case VT_NULL:
2838 case VT_I2:
2839 case VT_I4:
2840 case VT_R4:
2841 case VT_R8:
2842 case VT_CY:
2843 case VT_DATE:
2844 case VT_ERROR:
2845 case VT_BOOL:
2846 case VT_DECIMAL:
2847 case VT_UI1:
2848 case VT_UI2:
2849 case VT_UI4:
2850 case VT_I8:
2851 case VT_UI8:
2852 case VT_FILETIME:
2853 break;
2854 case VT_STREAM:
2855 case VT_STREAMED_OBJECT:
2856 case VT_STORAGE:
2857 case VT_STORED_OBJECT:
2858 if (pvar->u.pStream)
2859 IUnknown_Release(pvar->u.pStream);
2860 break;
2861 case VT_CLSID:
2862 case VT_LPSTR:
2863 case VT_LPWSTR:
2864 /* pick an arbitrary typed pointer - we don't care about the type
2865 * as we are just freeing it */
2866 CoTaskMemFree(pvar->u.puuid);
2867 break;
2868 case VT_BLOB:
2869 case VT_BLOB_OBJECT:
2870 CoTaskMemFree(pvar->u.blob.pBlobData);
2871 break;
2872 case VT_BSTR:
2873 if (pvar->u.bstrVal)
2874 PropSysFreeString(pvar->u.bstrVal);
2875 break;
2876 case VT_CF:
2877 if (pvar->u.pclipdata)
2879 OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2880 CoTaskMemFree(pvar->u.pclipdata);
2882 break;
2883 default:
2884 if (pvar->vt & VT_VECTOR)
2886 ULONG i;
2888 switch (pvar->vt & ~VT_VECTOR)
2890 case VT_VARIANT:
2891 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2892 break;
2893 case VT_CF:
2894 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2895 break;
2896 case VT_BSTR:
2897 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2898 PropSysFreeString(pvar->u.cabstr.pElems[i]);
2899 break;
2900 case VT_LPSTR:
2901 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2902 CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2903 break;
2904 case VT_LPWSTR:
2905 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2906 CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2907 break;
2909 if (pvar->vt & ~VT_VECTOR)
2911 /* pick an arbitrary VT_VECTOR structure - they all have the same
2912 * memory layout */
2913 CoTaskMemFree(pvar->u.capropvar.pElems);
2916 else
2917 WARN("Invalid/unsupported type %d\n", pvar->vt);
2920 ZeroMemory(pvar, sizeof(*pvar));
2922 return S_OK;
2925 /***********************************************************************
2926 * PropVariantCopy [OLE32.@]
2928 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest, /* [out] */
2929 const PROPVARIANT *pvarSrc) /* [in] */
2931 ULONG len;
2932 HRESULT hr;
2934 TRACE("(%p, %p vt %04x)\n", pvarDest, pvarSrc, pvarSrc->vt);
2936 hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2937 if (FAILED(hr))
2938 return hr;
2940 /* this will deal with most cases */
2941 *pvarDest = *pvarSrc;
2943 switch(pvarSrc->vt)
2945 case VT_EMPTY:
2946 case VT_NULL:
2947 case VT_I1:
2948 case VT_UI1:
2949 case VT_I2:
2950 case VT_UI2:
2951 case VT_BOOL:
2952 case VT_DECIMAL:
2953 case VT_I4:
2954 case VT_UI4:
2955 case VT_R4:
2956 case VT_ERROR:
2957 case VT_I8:
2958 case VT_UI8:
2959 case VT_R8:
2960 case VT_CY:
2961 case VT_DATE:
2962 case VT_FILETIME:
2963 break;
2964 case VT_STREAM:
2965 case VT_STREAMED_OBJECT:
2966 case VT_STORAGE:
2967 case VT_STORED_OBJECT:
2968 IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2969 break;
2970 case VT_CLSID:
2971 pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2972 *pvarDest->u.puuid = *pvarSrc->u.puuid;
2973 break;
2974 case VT_LPSTR:
2975 len = strlen(pvarSrc->u.pszVal);
2976 pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2977 CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2978 break;
2979 case VT_LPWSTR:
2980 len = lstrlenW(pvarSrc->u.pwszVal);
2981 pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2982 CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2983 break;
2984 case VT_BLOB:
2985 case VT_BLOB_OBJECT:
2986 if (pvarSrc->u.blob.pBlobData)
2988 len = pvarSrc->u.blob.cbSize;
2989 pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2990 CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2992 break;
2993 case VT_BSTR:
2994 pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2995 break;
2996 case VT_CF:
2997 if (pvarSrc->u.pclipdata)
2999 len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
3000 pvarDest->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
3001 pvarDest->u.pclipdata->cbSize = pvarSrc->u.pclipdata->cbSize;
3002 pvarDest->u.pclipdata->ulClipFmt = pvarSrc->u.pclipdata->ulClipFmt;
3003 pvarDest->u.pclipdata->pClipData = CoTaskMemAlloc(len);
3004 CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
3006 break;
3007 default:
3008 if (pvarSrc->vt & VT_VECTOR)
3010 int elemSize;
3011 ULONG i;
3013 switch(pvarSrc->vt & ~VT_VECTOR)
3015 case VT_I1: elemSize = sizeof(pvarSrc->u.cVal); break;
3016 case VT_UI1: elemSize = sizeof(pvarSrc->u.bVal); break;
3017 case VT_I2: elemSize = sizeof(pvarSrc->u.iVal); break;
3018 case VT_UI2: elemSize = sizeof(pvarSrc->u.uiVal); break;
3019 case VT_BOOL: elemSize = sizeof(pvarSrc->u.boolVal); break;
3020 case VT_I4: elemSize = sizeof(pvarSrc->u.lVal); break;
3021 case VT_UI4: elemSize = sizeof(pvarSrc->u.ulVal); break;
3022 case VT_R4: elemSize = sizeof(pvarSrc->u.fltVal); break;
3023 case VT_R8: elemSize = sizeof(pvarSrc->u.dblVal); break;
3024 case VT_ERROR: elemSize = sizeof(pvarSrc->u.scode); break;
3025 case VT_I8: elemSize = sizeof(pvarSrc->u.hVal); break;
3026 case VT_UI8: elemSize = sizeof(pvarSrc->u.uhVal); break;
3027 case VT_CY: elemSize = sizeof(pvarSrc->u.cyVal); break;
3028 case VT_DATE: elemSize = sizeof(pvarSrc->u.date); break;
3029 case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
3030 case VT_CLSID: elemSize = sizeof(*pvarSrc->u.puuid); break;
3031 case VT_CF: elemSize = sizeof(*pvarSrc->u.pclipdata); break;
3032 case VT_BSTR: elemSize = sizeof(pvarSrc->u.bstrVal); break;
3033 case VT_LPSTR: elemSize = sizeof(pvarSrc->u.pszVal); break;
3034 case VT_LPWSTR: elemSize = sizeof(pvarSrc->u.pwszVal); break;
3035 case VT_VARIANT: elemSize = sizeof(*pvarSrc->u.pvarVal); break;
3037 default:
3038 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
3039 return E_INVALIDARG;
3041 len = pvarSrc->u.capropvar.cElems;
3042 pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
3043 if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
3045 for (i = 0; i < len; i++)
3046 PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
3048 else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
3050 FIXME("Copy clipformats\n");
3052 else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
3054 for (i = 0; i < len; i++)
3055 pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
3057 else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
3059 size_t strLen;
3060 for (i = 0; i < len; i++)
3062 strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
3063 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
3064 memcpy(pvarDest->u.calpstr.pElems[i],
3065 pvarSrc->u.calpstr.pElems[i], strLen);
3068 else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
3070 size_t strLen;
3071 for (i = 0; i < len; i++)
3073 strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
3074 sizeof(WCHAR);
3075 pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
3076 memcpy(pvarDest->u.calpstr.pElems[i],
3077 pvarSrc->u.calpstr.pElems[i], strLen);
3080 else
3081 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
3083 else
3084 WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
3087 return S_OK;
3090 /***********************************************************************
3091 * FreePropVariantArray [OLE32.@]
3093 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
3094 PROPVARIANT *rgvars) /* [in/out] */
3096 ULONG i;
3098 TRACE("(%u, %p)\n", cVariants, rgvars);
3100 if (!rgvars)
3101 return E_INVALIDARG;
3103 for(i = 0; i < cVariants; i++)
3104 PropVariantClear(&rgvars[i]);
3106 return S_OK;
3109 /******************************************************************************
3110 * DllDebugObjectRPCHook (OLE32.@)
3111 * turns on and off internal debugging, pointer is only used on macintosh
3114 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
3116 FIXME("stub\n");
3117 return TRUE;