4 * Copyright 1995 Martin von Loewis
5 * Copyright 1999 Francis Beaudet
6 * Copyright 1999 Noel Borthwick
7 * Copyright 1999, 2000 Marcus Meissner
8 * Copyright 2005 Juan Lang
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
50 #include "compobj_private.h"
51 #include "wine/list.h"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
56 WINE_DECLARE_DEBUG_CHANNEL(accel
);
58 /******************************************************************************
59 * These are static/global variables and internal data structures that the
60 * OLE module uses to maintain it's state.
62 typedef struct tagDropTargetNode
65 IDropTarget
* dropTarget
;
69 typedef struct tagTrackerWindowInfo
71 IDataObject
* dataObject
;
72 IDropSource
* dropSource
;
79 HWND curTargetHWND
; /* window the mouse is hovering over */
80 HWND curDragTargetHWND
; /* might be a ancestor of curTargetHWND */
81 IDropTarget
* curDragTarget
;
82 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
83 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
86 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
88 HWND hwndFrame
; /* The containers frame window */
89 HWND hwndActiveObject
; /* The active objects window */
90 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
91 HMENU hmenuCombined
; /* The combined menu */
92 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
95 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
97 DWORD tid
; /* Thread Id */
98 HANDLE hHeap
; /* Heap this is allocated from */
99 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
100 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
101 struct tagOleMenuHookItem
*next
;
104 static OleMenuHookItem
*hook_list
;
107 * This is the lock count on the OLE library. It is controlled by the
108 * OLEInitialize/OLEUninitialize methods.
110 static ULONG OLE_moduleLockCount
= 0;
113 * Name of our registered window class.
115 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
118 * This is the head of the Drop target container.
120 static struct list targetListHead
= LIST_INIT(targetListHead
);
122 /******************************************************************************
123 * These are the prototypes of miscelaneous utility methods
125 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
127 /******************************************************************************
128 * These are the prototypes of the utility methods used to manage a shared menu
130 static void OLEMenu_Initialize(void);
131 static void OLEMenu_UnInitialize(void);
132 BOOL
OLEMenu_InstallHooks( DWORD tid
);
133 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
134 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
135 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
136 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
137 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
138 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
140 /******************************************************************************
141 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
143 extern void OLEClipbrd_UnInitialize(void);
144 extern void OLEClipbrd_Initialize(void);
146 /******************************************************************************
147 * These are the prototypes of the utility methods used for OLE Drag n Drop
149 static void OLEDD_Initialize(void);
150 static void OLEDD_UnInitialize(void);
151 static DropTargetNode
* OLEDD_FindDropTarget(
153 static void OLEDD_FreeDropTarget(DropTargetNode
*);
154 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
159 static void OLEDD_TrackMouseMove(
160 TrackerWindowInfo
* trackerInfo
);
161 static void OLEDD_TrackStateChange(
162 TrackerWindowInfo
* trackerInfo
);
163 static DWORD
OLEDD_GetButtonState(void);
166 /******************************************************************************
167 * OleBuildVersion [OLE2.1]
168 * OleBuildVersion [OLE32.@]
170 DWORD WINAPI
OleBuildVersion(void)
172 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
173 return (rmm
<<16)+rup
;
176 /***********************************************************************
177 * OleInitialize (OLE2.2)
178 * OleInitialize (OLE32.@)
180 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
184 TRACE("(%p)\n", reserved
);
187 * The first duty of the OleInitialize is to initialize the COM libraries.
189 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
192 * If the CoInitializeEx call failed, the OLE libraries can't be
199 * Then, it has to initialize the OLE specific modules.
203 * Object linking and Embedding
204 * In-place activation
206 if (OLE_moduleLockCount
==0)
209 * Initialize the libraries.
211 TRACE("() - Initializing the OLE libraries\n");
216 OLEClipbrd_Initialize();
226 OLEMenu_Initialize();
230 * Then, we increase the lock count on the OLE module.
232 OLE_moduleLockCount
++;
237 /******************************************************************************
238 * OleUninitialize [OLE2.3]
239 * OleUninitialize [OLE32.@]
241 void WINAPI
OleUninitialize(void)
246 * Decrease the lock count on the OLE module.
248 OLE_moduleLockCount
--;
251 * If we hit the bottom of the lock stack, free the libraries.
253 if (OLE_moduleLockCount
==0)
256 * Actually free the libraries.
258 TRACE("() - Freeing the last reference count\n");
263 OLEClipbrd_UnInitialize();
268 OLEDD_UnInitialize();
273 OLEMenu_UnInitialize();
277 * Then, uninitialize the COM libraries.
282 /******************************************************************************
283 * OleInitializeWOW [OLE32.@]
285 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
286 FIXME("(0x%08lx, 0x%08lx),stub!\n",x
, y
);
290 /***********************************************************************
291 * RegisterDragDrop (OLE32.@)
293 HRESULT WINAPI
RegisterDragDrop(
295 LPDROPTARGET pDropTarget
)
297 DropTargetNode
* dropTargetInfo
;
299 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
305 * First, check if the window is already registered.
307 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
309 if (dropTargetInfo
!=NULL
)
310 return DRAGDROP_E_ALREADYREGISTERED
;
313 * If it's not there, we can add it. We first create a node for it.
315 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
317 if (dropTargetInfo
==NULL
)
318 return E_OUTOFMEMORY
;
320 dropTargetInfo
->hwndTarget
= hwnd
;
323 * Don't forget that this is an interface pointer, need to nail it down since
324 * we keep a copy of it.
326 IDropTarget_AddRef(pDropTarget
);
327 dropTargetInfo
->dropTarget
= pDropTarget
;
329 list_add_tail(&targetListHead
, &dropTargetInfo
->entry
);
334 /***********************************************************************
335 * RevokeDragDrop (OLE32.@)
337 HRESULT WINAPI
RevokeDragDrop(
340 DropTargetNode
* dropTargetInfo
;
342 TRACE("(%p)\n", hwnd
);
345 * First, check if the window is already registered.
347 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
350 * If it ain't in there, it's an error.
352 if (dropTargetInfo
==NULL
)
353 return DRAGDROP_E_NOTREGISTERED
;
355 OLEDD_FreeDropTarget(dropTargetInfo
);
360 /***********************************************************************
361 * OleRegGetUserType (OLE32.@)
363 * This implementation of OleRegGetUserType ignores the dwFormOfType
364 * parameter and always returns the full name of the object. This is
365 * not too bad since this is the case for many objects because of the
366 * way they are registered.
368 HRESULT WINAPI
OleRegGetUserType(
371 LPOLESTR
* pszUserType
)
381 * Initialize the out parameter.
386 * Build the key name we're looking for
388 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
389 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
390 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
391 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
393 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
396 * Open the class id Key
398 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
402 if (hres
!= ERROR_SUCCESS
)
403 return REGDB_E_CLASSNOTREG
;
406 * Retrieve the size of the name string.
410 hres
= RegQueryValueExA(clsidKey
,
417 if (hres
!=ERROR_SUCCESS
)
419 RegCloseKey(clsidKey
);
420 return REGDB_E_READREGDB
;
424 * Allocate a buffer for the registry value.
426 *pszUserType
= CoTaskMemAlloc(cbData
*2);
428 if (*pszUserType
==NULL
)
430 RegCloseKey(clsidKey
);
431 return E_OUTOFMEMORY
;
434 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
438 RegCloseKey(clsidKey
);
439 CoTaskMemFree(*pszUserType
);
441 return E_OUTOFMEMORY
;
444 hres
= RegQueryValueExA(clsidKey
,
451 RegCloseKey(clsidKey
);
454 if (hres
!=ERROR_SUCCESS
)
456 CoTaskMemFree(*pszUserType
);
459 retVal
= REGDB_E_READREGDB
;
463 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
466 HeapFree(GetProcessHeap(), 0, buffer
);
471 /***********************************************************************
472 * DoDragDrop [OLE32.@]
474 HRESULT WINAPI
DoDragDrop (
475 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
476 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
477 DWORD dwOKEffect
, /* [in] effects allowed by the source */
478 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
480 TrackerWindowInfo trackerInfo
;
481 HWND hwndTrackWindow
;
484 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
487 * Setup the drag n drop tracking window.
489 if (!IsValidInterface((LPUNKNOWN
)pDropSource
))
492 trackerInfo
.dataObject
= pDataObject
;
493 trackerInfo
.dropSource
= pDropSource
;
494 trackerInfo
.dwOKEffect
= dwOKEffect
;
495 trackerInfo
.pdwEffect
= pdwEffect
;
496 trackerInfo
.trackingDone
= FALSE
;
497 trackerInfo
.escPressed
= FALSE
;
498 trackerInfo
.curDragTargetHWND
= 0;
499 trackerInfo
.curTargetHWND
= 0;
500 trackerInfo
.curDragTarget
= 0;
502 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
505 CW_USEDEFAULT
, CW_USEDEFAULT
,
506 CW_USEDEFAULT
, CW_USEDEFAULT
,
510 (LPVOID
)&trackerInfo
);
512 if (hwndTrackWindow
!=0)
515 * Capture the mouse input
517 SetCapture(hwndTrackWindow
);
522 * Pump messages. All mouse input should go the the capture window.
524 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
526 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
527 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
528 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
530 if ( (msg
.message
>= WM_KEYFIRST
) &&
531 (msg
.message
<= WM_KEYLAST
) )
534 * When keyboard messages are sent to windows on this thread, we
535 * want to ignore notify the drop source that the state changed.
536 * in the case of the Escape key, we also notify the drop source
537 * we give it a special meaning.
539 if ( (msg
.message
==WM_KEYDOWN
) &&
540 (msg
.wParam
==VK_ESCAPE
) )
542 trackerInfo
.escPressed
= TRUE
;
546 * Notify the drop source.
548 OLEDD_TrackStateChange(&trackerInfo
);
553 * Dispatch the messages only when it's not a keyboard message.
555 DispatchMessageA(&msg
);
559 /* re-post the quit message to outer message loop */
560 if (msg
.message
== WM_QUIT
)
561 PostQuitMessage(msg
.wParam
);
563 * Destroy the temporary window.
565 DestroyWindow(hwndTrackWindow
);
567 return trackerInfo
.returnValue
;
573 /***********************************************************************
574 * OleQueryLinkFromData [OLE32.@]
576 HRESULT WINAPI
OleQueryLinkFromData(
577 IDataObject
* pSrcDataObject
)
579 FIXME("(%p),stub!\n", pSrcDataObject
);
583 /***********************************************************************
584 * OleRegGetMiscStatus [OLE32.@]
586 HRESULT WINAPI
OleRegGetMiscStatus(
598 * Initialize the out parameter.
603 * Build the key name we're looking for
605 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
606 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
607 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
608 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
610 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
613 * Open the class id Key
615 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
619 if (result
!= ERROR_SUCCESS
)
620 return REGDB_E_CLASSNOTREG
;
625 result
= RegOpenKeyA(clsidKey
,
630 if (result
!= ERROR_SUCCESS
)
632 RegCloseKey(clsidKey
);
633 return REGDB_E_READREGDB
;
637 * Read the default value
639 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
642 * Open the key specific to the requested aspect.
644 sprintf(keyName
, "%ld", dwAspect
);
646 result
= RegOpenKeyA(miscStatusKey
,
650 if (result
== ERROR_SUCCESS
)
652 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
653 RegCloseKey(aspectKey
);
659 RegCloseKey(miscStatusKey
);
660 RegCloseKey(clsidKey
);
665 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
669 const IEnumOLEVERBVtbl
*lpvtbl
;
676 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
677 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
679 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
680 if (IsEqualIID(riid
, &IID_IUnknown
) ||
681 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
683 IUnknown_AddRef(iface
);
687 return E_NOINTERFACE
;
690 static ULONG WINAPI
EnumOLEVERB_AddRef(
693 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
695 return InterlockedIncrement(&This
->ref
);
698 static ULONG WINAPI
EnumOLEVERB_Release(
701 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
702 LONG refs
= InterlockedDecrement(&This
->ref
);
706 RegCloseKey(This
->hkeyVerb
);
707 HeapFree(GetProcessHeap(), 0, This
);
712 static HRESULT WINAPI
EnumOLEVERB_Next(
713 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
716 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
719 TRACE("(%ld, %p, %p)\n", celt
, rgelt
, pceltFetched
);
724 for (; celt
; celt
--, rgelt
++)
729 LPWSTR pwszMenuFlags
;
731 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
732 if (res
== ERROR_NO_MORE_ITEMS
)
737 else if (res
!= ERROR_SUCCESS
)
739 ERR("RegEnumKeyW failed with error %ld\n", res
);
740 hr
= REGDB_E_READREGDB
;
743 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
744 if (res
!= ERROR_SUCCESS
)
746 ERR("RegQueryValueW failed with error %ld\n", res
);
747 hr
= REGDB_E_READREGDB
;
750 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
756 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
757 if (res
!= ERROR_SUCCESS
)
759 ERR("RegQueryValueW failed with error %ld\n", res
);
760 hr
= REGDB_E_READREGDB
;
761 CoTaskMemFree(pwszOLEVERB
);
765 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
766 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
769 hr
= OLEOBJ_E_INVALIDVERB
;
770 CoTaskMemFree(pwszOLEVERB
);
773 /* nul terminate the name string and advance to first character */
774 *pwszMenuFlags
= '\0';
776 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
779 hr
= OLEOBJ_E_INVALIDVERB
;
780 CoTaskMemFree(pwszOLEVERB
);
783 /* nul terminate the menu string and advance to first character */
787 /* fill out structure for this verb */
788 rgelt
->lVerb
= atolW(wszSubKey
);
789 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
790 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
791 rgelt
->grfAttribs
= atolW(pwszAttribs
);
800 static HRESULT WINAPI
EnumOLEVERB_Skip(
801 IEnumOLEVERB
*iface
, ULONG celt
)
803 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
805 TRACE("(%ld)\n", celt
);
811 static HRESULT WINAPI
EnumOLEVERB_Reset(
814 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
822 static HRESULT WINAPI
EnumOLEVERB_Clone(
824 IEnumOLEVERB
**ppenum
)
826 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
828 TRACE("(%p)\n", ppenum
);
829 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
830 return HRESULT_FROM_WIN32(GetLastError());
831 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
834 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
836 EnumOLEVERB_QueryInterface
,
845 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
847 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
850 RegCloseKey(hkeyVerb
);
851 return E_OUTOFMEMORY
;
853 This
->lpvtbl
= &EnumOLEVERB_VTable
;
856 This
->hkeyVerb
= hkeyVerb
;
857 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
861 /***********************************************************************
862 * OleRegEnumVerbs [OLE32.@]
864 * Enumerates verbs associated with a class stored in the registry.
867 * clsid [I] Class ID to enumerate the verbs for.
868 * ppenum [O] Enumerator.
872 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
873 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
874 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
875 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
877 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
882 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
884 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
886 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
889 if (res
== REGDB_E_CLASSNOTREG
)
890 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
891 else if (res
== REGDB_E_KEYMISSING
)
892 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
894 ERR("failed to open Verbs key for CLSID %s with error %ld\n",
895 debugstr_guid(clsid
), res
);
899 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
900 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
901 if (res
!= ERROR_SUCCESS
)
903 ERR("failed to get subkey count with error %ld\n", GetLastError());
904 return REGDB_E_READREGDB
;
909 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
910 RegCloseKey(hkeyVerb
);
911 return OLEOBJ_E_NOVERBS
;
914 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
917 /******************************************************************************
918 * OleSetContainedObject [OLE32.@]
920 HRESULT WINAPI
OleSetContainedObject(
924 IRunnableObject
* runnable
= NULL
;
927 TRACE("(%p,%x)\n", pUnknown
, fContained
);
929 hres
= IUnknown_QueryInterface(pUnknown
,
930 &IID_IRunnableObject
,
935 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
937 IRunnableObject_Release(runnable
);
945 /******************************************************************************
948 HRESULT WINAPI
OleLoad(
951 LPOLECLIENTSITE pClientSite
,
954 IPersistStorage
* persistStorage
= NULL
;
955 IOleObject
* oleObject
= NULL
;
959 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
962 * TODO, Conversion ... OleDoAutoConvert
966 * Get the class ID for the object.
968 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
971 * Now, try and create the handler for the object
973 hres
= CoCreateInstance(&storageInfo
.clsid
,
975 CLSCTX_INPROC_HANDLER
,
980 * If that fails, as it will most times, load the default
985 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
992 * If we couldn't find a handler... this is bad. Abort the whole thing.
998 * Inform the new object of it's client site.
1000 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
1003 * Initialize the object with it's IPersistStorage interface.
1005 hres
= IOleObject_QueryInterface(oleObject
,
1006 &IID_IPersistStorage
,
1007 (void**)&persistStorage
);
1009 if (SUCCEEDED(hres
))
1011 IPersistStorage_Load(persistStorage
, pStg
);
1013 IPersistStorage_Release(persistStorage
);
1014 persistStorage
= NULL
;
1018 * Return the requested interface to the caller.
1020 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
1023 * Cleanup interfaces used internally
1025 IOleObject_Release(oleObject
);
1030 /***********************************************************************
1033 HRESULT WINAPI
OleSave(
1034 LPPERSISTSTORAGE pPS
,
1041 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1044 * First, we transfer the class ID (if available)
1046 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1048 if (SUCCEEDED(hres
))
1050 WriteClassStg(pStg
, &objectClass
);
1054 * Then, we ask the object to save itself to the
1055 * storage. If it is successful, we commit the storage.
1057 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1059 if (SUCCEEDED(hres
))
1061 IStorage_Commit(pStg
,
1069 /******************************************************************************
1070 * OleLockRunning [OLE32.@]
1072 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1074 IRunnableObject
* runnable
= NULL
;
1077 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1079 hres
= IUnknown_QueryInterface(pUnknown
,
1080 &IID_IRunnableObject
,
1083 if (SUCCEEDED(hres
))
1085 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1087 IRunnableObject_Release(runnable
);
1092 return E_INVALIDARG
;
1096 /**************************************************************************
1097 * Internal methods to manage the shared OLE menu in response to the
1098 * OLE***MenuDescriptor API
1102 * OLEMenu_Initialize()
1104 * Initializes the OLEMENU data structures.
1106 static void OLEMenu_Initialize()
1111 * OLEMenu_UnInitialize()
1113 * Releases the OLEMENU data structures.
1115 static void OLEMenu_UnInitialize()
1119 /*************************************************************************
1120 * OLEMenu_InstallHooks
1121 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1123 * RETURNS: TRUE if message hooks were successfully installed
1126 BOOL
OLEMenu_InstallHooks( DWORD tid
)
1128 OleMenuHookItem
*pHookItem
= NULL
;
1130 /* Create an entry for the hook table */
1131 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1132 sizeof(OleMenuHookItem
)) ) )
1135 pHookItem
->tid
= tid
;
1136 pHookItem
->hHeap
= GetProcessHeap();
1138 /* Install a thread scope message hook for WH_GETMESSAGE */
1139 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1140 0, GetCurrentThreadId() );
1141 if ( !pHookItem
->GetMsg_hHook
)
1144 /* Install a thread scope message hook for WH_CALLWNDPROC */
1145 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1146 0, GetCurrentThreadId() );
1147 if ( !pHookItem
->CallWndProc_hHook
)
1150 /* Insert the hook table entry */
1151 pHookItem
->next
= hook_list
;
1152 hook_list
= pHookItem
;
1157 /* Unhook any hooks */
1158 if ( pHookItem
->GetMsg_hHook
)
1159 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1160 if ( pHookItem
->CallWndProc_hHook
)
1161 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1162 /* Release the hook table entry */
1163 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1168 /*************************************************************************
1169 * OLEMenu_UnInstallHooks
1170 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1172 * RETURNS: TRUE if message hooks were successfully installed
1175 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1177 OleMenuHookItem
*pHookItem
= NULL
;
1178 OleMenuHookItem
**ppHook
= &hook_list
;
1182 if ((*ppHook
)->tid
== tid
)
1184 pHookItem
= *ppHook
;
1185 *ppHook
= pHookItem
->next
;
1188 ppHook
= &(*ppHook
)->next
;
1190 if (!pHookItem
) return FALSE
;
1192 /* Uninstall the hooks installed for this thread */
1193 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1195 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1198 /* Release the hook table entry */
1199 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1204 /* Release the hook table entry */
1205 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1210 /*************************************************************************
1211 * OLEMenu_IsHookInstalled
1212 * Tests if OLEMenu hooks have been installed for a thread
1214 * RETURNS: The pointer and index of the hook table entry for the tid
1215 * NULL and -1 for the index if no hooks were installed for this thread
1217 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1219 OleMenuHookItem
*pHookItem
= NULL
;
1221 /* Do a simple linear search for an entry whose tid matches ours.
1222 * We really need a map but efficiency is not a concern here. */
1223 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1225 if ( tid
== pHookItem
->tid
)
1232 /***********************************************************************
1233 * OLEMenu_FindMainMenuIndex
1235 * Used by OLEMenu API to find the top level group a menu item belongs to.
1236 * On success pnPos contains the index of the item in the top level menu group
1238 * RETURNS: TRUE if the ID was found, FALSE on failure
1240 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1244 nItems
= GetMenuItemCount( hMainMenu
);
1246 for (i
= 0; i
< nItems
; i
++)
1250 /* Is the current item a submenu? */
1251 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1253 /* If the handle is the same we're done */
1254 if ( hsubmenu
== hPopupMenu
)
1260 /* Recursively search without updating pnPos */
1261 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1273 /***********************************************************************
1274 * OLEMenu_SetIsServerMenu
1276 * Checks whether a popup menu belongs to a shared menu group which is
1277 * owned by the server, and sets the menu descriptor state accordingly.
1278 * All menu messages from these groups should be routed to the server.
1280 * RETURNS: TRUE if the popup menu is part of a server owned group
1281 * FALSE if the popup menu is part of a container owned group
1283 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1285 UINT nPos
= 0, nWidth
, i
;
1287 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1289 /* Don't bother searching if the popup is the combined menu itself */
1290 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1293 /* Find the menu item index in the shared OLE menu that this item belongs to */
1294 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1297 /* The group widths array has counts for the number of elements
1298 * in the groups File, Edit, Container, Object, Window, Help.
1299 * The Edit, Object & Help groups belong to the server object
1300 * and the other three belong to the container.
1301 * Loop through the group widths and locate the group we are a member of.
1303 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1305 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1306 if ( nPos
< nWidth
)
1308 /* Odd elements are server menu widths */
1309 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1314 return pOleMenuDescriptor
->bIsServerItem
;
1317 /*************************************************************************
1318 * OLEMenu_CallWndProc
1319 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1320 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1322 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1324 LPCWPSTRUCT pMsg
= NULL
;
1325 HOLEMENU hOleMenu
= 0;
1326 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1327 OleMenuHookItem
*pHookItem
= NULL
;
1330 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1332 /* Check if we're being asked to process the message */
1333 if ( HC_ACTION
!= code
)
1336 /* Retrieve the current message being dispatched from lParam */
1337 pMsg
= (LPCWPSTRUCT
)lParam
;
1339 /* Check if the message is destined for a window we are interested in:
1340 * If the window has an OLEMenu property we may need to dispatch
1341 * the menu message to its active objects window instead. */
1343 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1347 /* Get the menu descriptor */
1348 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1349 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1352 /* Process menu messages */
1353 switch( pMsg
->message
)
1357 /* Reset the menu descriptor state */
1358 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1360 /* Send this message to the server as well */
1361 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1362 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1366 case WM_INITMENUPOPUP
:
1368 /* Save the state for whether this is a server owned menu */
1369 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1375 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1376 if ( fuFlags
& MF_SYSMENU
)
1379 /* Save the state for whether this is a server owned popup menu */
1380 else if ( fuFlags
& MF_POPUP
)
1381 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1388 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1389 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1390 goto NEXTHOOK
; /* Not a menu message */
1399 /* If the message was for the server dispatch it accordingly */
1400 if ( pOleMenuDescriptor
->bIsServerItem
)
1402 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1403 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1407 if ( pOleMenuDescriptor
)
1408 GlobalUnlock( hOleMenu
);
1410 /* Lookup the hook item for the current thread */
1411 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1413 /* This should never fail!! */
1414 WARN("could not retrieve hHook for current thread!\n" );
1418 /* Pass on the message to the next hooker */
1419 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1422 /*************************************************************************
1423 * OLEMenu_GetMsgProc
1424 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1425 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1427 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1430 HOLEMENU hOleMenu
= 0;
1431 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1432 OleMenuHookItem
*pHookItem
= NULL
;
1435 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1437 /* Check if we're being asked to process a messages */
1438 if ( HC_ACTION
!= code
)
1441 /* Retrieve the current message being dispatched from lParam */
1442 pMsg
= (LPMSG
)lParam
;
1444 /* Check if the message is destined for a window we are interested in:
1445 * If the window has an OLEMenu property we may need to dispatch
1446 * the menu message to its active objects window instead. */
1448 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1452 /* Process menu messages */
1453 switch( pMsg
->message
)
1457 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1459 goto NEXTHOOK
; /* Not a menu message */
1466 /* Get the menu descriptor */
1467 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1468 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1471 /* If the message was for the server dispatch it accordingly */
1472 if ( pOleMenuDescriptor
->bIsServerItem
)
1474 /* Change the hWnd in the message to the active objects hWnd.
1475 * The message loop which reads this message will automatically
1476 * dispatch it to the embedded objects window. */
1477 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1481 if ( pOleMenuDescriptor
)
1482 GlobalUnlock( hOleMenu
);
1484 /* Lookup the hook item for the current thread */
1485 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1487 /* This should never fail!! */
1488 WARN("could not retrieve hHook for current thread!\n" );
1492 /* Pass on the message to the next hooker */
1493 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1496 /***********************************************************************
1497 * OleCreateMenuDescriptor [OLE32.@]
1498 * Creates an OLE menu descriptor for OLE to use when dispatching
1499 * menu messages and commands.
1502 * hmenuCombined - Handle to the objects combined menu
1503 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1506 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1507 HMENU hmenuCombined
,
1508 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1511 OleMenuDescriptor
*pOleMenuDescriptor
;
1514 if ( !hmenuCombined
|| !lpMenuWidths
)
1517 /* Create an OLE menu descriptor */
1518 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1519 sizeof(OleMenuDescriptor
) ) ) )
1522 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1523 if ( !pOleMenuDescriptor
)
1526 /* Initialize menu group widths and hmenu */
1527 for ( i
= 0; i
< 6; i
++ )
1528 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1530 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1531 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1532 GlobalUnlock( hOleMenu
);
1537 /***********************************************************************
1538 * OleDestroyMenuDescriptor [OLE32.@]
1539 * Destroy the shared menu descriptor
1541 HRESULT WINAPI
OleDestroyMenuDescriptor(
1542 HOLEMENU hmenuDescriptor
)
1544 if ( hmenuDescriptor
)
1545 GlobalFree( hmenuDescriptor
);
1549 /***********************************************************************
1550 * OleSetMenuDescriptor [OLE32.@]
1551 * Installs or removes OLE dispatching code for the containers frame window.
1554 * hOleMenu Handle to composite menu descriptor
1555 * hwndFrame Handle to containers frame window
1556 * hwndActiveObject Handle to objects in-place activation window
1557 * lpFrame Pointer to IOleInPlaceFrame on containers window
1558 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1561 * S_OK - menu installed correctly
1562 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1565 * The lpFrame and lpActiveObject parameters are currently ignored
1566 * OLE should install context sensitive help F1 filtering for the app when
1567 * these are non null.
1569 HRESULT WINAPI
OleSetMenuDescriptor(
1572 HWND hwndActiveObject
,
1573 LPOLEINPLACEFRAME lpFrame
,
1574 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1576 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1579 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1580 return E_INVALIDARG
;
1582 if ( lpFrame
|| lpActiveObject
)
1584 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1592 /* Set up a message hook to intercept the containers frame window messages.
1593 * The message filter is responsible for dispatching menu messages from the
1594 * shared menu which are intended for the object.
1597 if ( hOleMenu
) /* Want to install dispatching code */
1599 /* If OLEMenu hooks are already installed for this thread, fail
1600 * Note: This effectively means that OleSetMenuDescriptor cannot
1601 * be called twice in succession on the same frame window
1602 * without first calling it with a null hOleMenu to uninstall */
1603 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1606 /* Get the menu descriptor */
1607 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1608 if ( !pOleMenuDescriptor
)
1609 return E_UNEXPECTED
;
1611 /* Update the menu descriptor */
1612 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1613 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1615 GlobalUnlock( hOleMenu
);
1616 pOleMenuDescriptor
= NULL
;
1618 /* Add a menu descriptor windows property to the frame window */
1619 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1621 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1622 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1625 else /* Want to uninstall dispatching code */
1627 /* Uninstall the hooks */
1628 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1631 /* Remove the menu descriptor property from the frame window */
1632 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1638 /******************************************************************************
1639 * IsAccelerator [OLE32.@]
1640 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1642 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1647 if(!lpMsg
) return FALSE
;
1650 WARN_(accel
)("NULL accel handle\n");
1653 if((lpMsg
->message
!= WM_KEYDOWN
&&
1654 lpMsg
->message
!= WM_KEYUP
&&
1655 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1656 lpMsg
->message
!= WM_SYSKEYUP
&&
1657 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1658 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1659 if (NULL
== lpAccelTbl
)
1663 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1665 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1666 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1670 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1671 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1672 hAccel
, cAccelEntries
,
1673 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1674 for(i
= 0; i
< cAccelEntries
; i
++)
1676 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1679 if(lpMsg
->message
== WM_CHAR
)
1681 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1683 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1689 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1692 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1693 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1694 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1695 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1696 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1697 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1698 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1702 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1704 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1705 { /* ^^ ALT pressed */
1706 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1714 WARN_(accel
)("couldn't translate accelerator key\n");
1715 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1719 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1720 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1724 /***********************************************************************
1725 * ReleaseStgMedium [OLE32.@]
1727 void WINAPI
ReleaseStgMedium(
1730 switch (pmedium
->tymed
)
1734 if ( (pmedium
->pUnkForRelease
==0) &&
1735 (pmedium
->u
.hGlobal
!=0) )
1736 GlobalFree(pmedium
->u
.hGlobal
);
1741 if (pmedium
->u
.lpszFileName
!=0)
1743 if (pmedium
->pUnkForRelease
==0)
1745 DeleteFileW(pmedium
->u
.lpszFileName
);
1748 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1754 if (pmedium
->u
.pstm
!=0)
1756 IStream_Release(pmedium
->u
.pstm
);
1760 case TYMED_ISTORAGE
:
1762 if (pmedium
->u
.pstg
!=0)
1764 IStorage_Release(pmedium
->u
.pstg
);
1770 if ( (pmedium
->pUnkForRelease
==0) &&
1771 (pmedium
->u
.hBitmap
!=0) )
1772 DeleteObject(pmedium
->u
.hBitmap
);
1777 if ( (pmedium
->pUnkForRelease
==0) &&
1778 (pmedium
->u
.hMetaFilePict
!=0) )
1780 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1781 DeleteMetaFile(pMP
->hMF
);
1782 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1783 GlobalFree(pmedium
->u
.hMetaFilePict
);
1789 if ( (pmedium
->pUnkForRelease
==0) &&
1790 (pmedium
->u
.hEnhMetaFile
!=0) )
1792 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1800 pmedium
->tymed
=TYMED_NULL
;
1803 * After cleaning up, the unknown is released
1805 if (pmedium
->pUnkForRelease
!=0)
1807 IUnknown_Release(pmedium
->pUnkForRelease
);
1808 pmedium
->pUnkForRelease
= 0;
1813 * OLEDD_Initialize()
1815 * Initializes the OLE drag and drop data structures.
1817 static void OLEDD_Initialize()
1821 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1822 wndClass
.style
= CS_GLOBALCLASS
;
1823 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1824 wndClass
.cbClsExtra
= 0;
1825 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1826 wndClass
.hCursor
= 0;
1827 wndClass
.hbrBackground
= 0;
1828 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1830 RegisterClassA (&wndClass
);
1834 * OLEDD_FreeDropTarget()
1836 * Frees the drag and drop data structure
1838 static void OLEDD_FreeDropTarget(DropTargetNode
*dropTargetInfo
)
1840 list_remove(&dropTargetInfo
->entry
);
1841 IDropTarget_Release(dropTargetInfo
->dropTarget
);
1842 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
1846 * OLEDD_UnInitialize()
1848 * Releases the OLE drag and drop data structures.
1850 static void OLEDD_UnInitialize(void)
1853 * Simply empty the list.
1855 while (!list_empty(&targetListHead
))
1857 DropTargetNode
* curNode
;
1858 curNode
= LIST_ENTRY(list_head(&targetListHead
), DropTargetNode
, entry
);
1859 OLEDD_FreeDropTarget(curNode
);
1864 * OLEDD_FindDropTarget()
1866 * Finds information about the drop target.
1868 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1870 DropTargetNode
* curNode
;
1873 * Iterate the list to find the HWND value.
1875 LIST_FOR_EACH_ENTRY(curNode
, &targetListHead
, DropTargetNode
, entry
)
1876 if (hwndOfTarget
==curNode
->hwndTarget
)
1880 * If we get here, the item is not in the list
1886 * OLEDD_DragTrackerWindowProc()
1888 * This method is the WindowProcedure of the drag n drop tracking
1889 * window. During a drag n Drop operation, an invisible window is created
1890 * to receive the user input and act upon it. This procedure is in charge
1894 #define DRAG_TIMER_ID 1
1896 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1906 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1908 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1909 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
1916 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1922 case WM_LBUTTONDOWN
:
1923 case WM_MBUTTONDOWN
:
1924 case WM_RBUTTONDOWN
:
1926 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1931 KillTimer(hwnd
, DRAG_TIMER_ID
);
1937 * This is a window proc after all. Let's call the default.
1939 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1943 * OLEDD_TrackMouseMove()
1945 * This method is invoked while a drag and drop operation is in effect.
1946 * it will generate the appropriate callbacks in the drop source
1947 * and drop target. It will also provide the expected feedback to
1951 * trackerInfo - Pointer to the structure identifying the
1952 * drag & drop operation that is currently
1955 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
1957 HWND hwndNewTarget
= 0;
1962 * Get the handle of the window under the mouse
1964 pt
.x
= trackerInfo
->curMousePos
.x
;
1965 pt
.y
= trackerInfo
->curMousePos
.y
;
1966 hwndNewTarget
= WindowFromPoint(pt
);
1969 * Every time, we re-initialize the effects passed to the
1970 * IDropTarget to the effects allowed by the source.
1972 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
1975 * If we are hovering over the same target as before, send the
1976 * DragOver notification
1978 if ( (trackerInfo
->curDragTarget
!= 0) &&
1979 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
1981 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
1982 trackerInfo
->dwKeyState
,
1983 trackerInfo
->curMousePos
,
1984 trackerInfo
->pdwEffect
);
1988 DropTargetNode
* newDropTargetNode
= 0;
1991 * If we changed window, we have to notify our old target and check for
1994 if (trackerInfo
->curDragTarget
!=0)
1996 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2000 * Make sure we're hovering over a window.
2002 if (hwndNewTarget
!=0)
2005 * Find-out if there is a drag target under the mouse
2007 HWND nexttar
= hwndNewTarget
;
2008 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2011 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2012 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2013 if(nexttar
) hwndNewTarget
= nexttar
;
2015 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2016 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2019 * If there is, notify it that we just dragged-in
2021 if (trackerInfo
->curDragTarget
!=0)
2023 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2024 trackerInfo
->dataObject
,
2025 trackerInfo
->dwKeyState
,
2026 trackerInfo
->curMousePos
,
2027 trackerInfo
->pdwEffect
);
2033 * The mouse is not over a window so we don't track anything.
2035 trackerInfo
->curDragTargetHWND
= 0;
2036 trackerInfo
->curTargetHWND
= 0;
2037 trackerInfo
->curDragTarget
= 0;
2042 * Now that we have done that, we have to tell the source to give
2043 * us feedback on the work being done by the target. If we don't
2044 * have a target, simulate no effect.
2046 if (trackerInfo
->curDragTarget
==0)
2048 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2051 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2052 *trackerInfo
->pdwEffect
);
2055 * When we ask for feedback from the drop source, sometimes it will
2056 * do all the necessary work and sometimes it will not handle it
2057 * when that's the case, we must display the standard drag and drop
2060 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2062 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2064 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2066 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2068 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2070 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2072 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2076 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2082 * OLEDD_TrackStateChange()
2084 * This method is invoked while a drag and drop operation is in effect.
2085 * It is used to notify the drop target/drop source callbacks when
2086 * the state of the keyboard or mouse button change.
2089 * trackerInfo - Pointer to the structure identifying the
2090 * drag & drop operation that is currently
2093 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2096 * Ask the drop source what to do with the operation.
2098 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2099 trackerInfo
->dropSource
,
2100 trackerInfo
->escPressed
,
2101 trackerInfo
->dwKeyState
);
2104 * All the return valued will stop the operation except the S_OK
2107 if (trackerInfo
->returnValue
!=S_OK
)
2110 * Make sure the message loop in DoDragDrop stops
2112 trackerInfo
->trackingDone
= TRUE
;
2115 * Release the mouse in case the drop target decides to show a popup
2116 * or a menu or something.
2121 * If we end-up over a target, drop the object in the target or
2122 * inform the target that the operation was cancelled.
2124 if (trackerInfo
->curDragTarget
!=0)
2126 switch (trackerInfo
->returnValue
)
2129 * If the source wants us to complete the operation, we tell
2130 * the drop target that we just dropped the object in it.
2132 case DRAGDROP_S_DROP
:
2134 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2135 trackerInfo
->dataObject
,
2136 trackerInfo
->dwKeyState
,
2137 trackerInfo
->curMousePos
,
2138 trackerInfo
->pdwEffect
);
2142 * If the source told us that we should cancel, fool the drop
2143 * target by telling it that the mouse left it's window.
2144 * Also set the drop effect to "NONE" in case the application
2145 * ignores the result of DoDragDrop.
2147 case DRAGDROP_S_CANCEL
:
2148 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2149 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2157 * OLEDD_GetButtonState()
2159 * This method will use the current state of the keyboard to build
2160 * a button state mask equivalent to the one passed in the
2161 * WM_MOUSEMOVE wParam.
2163 static DWORD
OLEDD_GetButtonState()
2165 BYTE keyboardState
[256];
2168 GetKeyboardState(keyboardState
);
2170 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2171 keyMask
|= MK_SHIFT
;
2173 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2174 keyMask
|= MK_CONTROL
;
2176 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2177 keyMask
|= MK_LBUTTON
;
2179 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2180 keyMask
|= MK_RBUTTON
;
2182 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2183 keyMask
|= MK_MBUTTON
;
2189 * OLEDD_GetButtonState()
2191 * This method will read the default value of the registry key in
2192 * parameter and extract a DWORD value from it. The registry key value
2193 * can be in a string key or a DWORD key.
2196 * regKey - Key to read the default value from
2197 * pdwValue - Pointer to the location where the DWORD
2198 * value is returned. This value is not modified
2199 * if the value is not found.
2202 static void OLEUTL_ReadRegistryDWORDValue(
2211 lres
= RegQueryValueExA(regKey
,
2218 if (lres
==ERROR_SUCCESS
)
2223 *pdwValue
= *(DWORD
*)buffer
;
2228 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2234 /******************************************************************************
2237 * The operation of this function is documented literally in the WinAPI
2238 * documentation to involve a QueryInterface for the IViewObject interface,
2239 * followed by a call to IViewObject::Draw.
2241 HRESULT WINAPI
OleDraw(
2248 IViewObject
*viewobject
;
2250 hres
= IUnknown_QueryInterface(pUnk
,
2252 (void**)&viewobject
);
2254 if (SUCCEEDED(hres
))
2258 rectl
.left
= lprcBounds
->left
;
2259 rectl
.right
= lprcBounds
->right
;
2260 rectl
.top
= lprcBounds
->top
;
2261 rectl
.bottom
= lprcBounds
->bottom
;
2262 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2264 IViewObject_Release(viewobject
);
2269 return DV_E_NOIVIEWOBJECT
;
2273 /***********************************************************************
2274 * OleTranslateAccelerator [OLE32.@]
2276 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2277 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2281 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2283 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2284 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2289 /******************************************************************************
2290 * OleCreate [OLE32.@]
2293 HRESULT WINAPI
OleCreate(
2297 LPFORMATETC pFormatEtc
,
2298 LPOLECLIENTSITE pClientSite
,
2302 HRESULT hres
, hres1
;
2303 IUnknown
* pUnk
= NULL
;
2305 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid
), debugstr_guid(riid
));
2307 if (SUCCEEDED((hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
|CLSCTX_LOCAL_SERVER
, riid
, (LPVOID
*)&pUnk
))))
2312 IPersistStorage
* pPS
;
2313 if (SUCCEEDED((hres
= IUnknown_QueryInterface( pUnk
, &IID_IOleObject
, (LPVOID
*)&pOE
))))
2315 TRACE("trying to set clientsite %p\n", pClientSite
);
2316 hres1
= IOleObject_SetClientSite(pOE
, pClientSite
);
2317 TRACE("-- result 0x%08lx\n", hres1
);
2318 IOleObject_Release(pOE
);
2320 if (SUCCEEDED((hres
= IUnknown_QueryInterface( pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2322 TRACE("trying to set stg %p\n", pStg
);
2323 hres1
= IPersistStorage_InitNew(pPS
, pStg
);
2324 TRACE("-- result 0x%08lx\n", hres1
);
2325 IPersistStorage_Release(pPS
);
2332 TRACE("-- %p\n", pUnk
);
2336 /******************************************************************************
2337 * OleSetAutoConvert [OLE32.@]
2339 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2341 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2343 WCHAR szClsidNew
[CHARS_IN_GUID
];
2346 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2348 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2351 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2352 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2354 res
= REGDB_E_WRITEREGDB
;
2359 if (hkey
) RegCloseKey(hkey
);
2363 /******************************************************************************
2364 * OleDoAutoConvert [OLE32.@]
2366 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2368 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2372 /******************************************************************************
2373 * OleIsRunning [OLE32.@]
2375 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2377 IRunnableObject
*pRunnable
;
2381 TRACE("(%p)\n", pObject
);
2383 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2386 running
= IRunnableObject_IsRunning(pRunnable
);
2387 IRunnableObject_Release(pRunnable
);
2391 /***********************************************************************
2392 * OLE_FreeClipDataArray [internal]
2395 * frees the data associated with an array of CLIPDATAs
2397 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2400 for (i
= 0; i
< count
; i
++)
2401 if (pClipDataArray
[i
].pClipData
)
2402 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2405 /***********************************************************************
2406 * PropSysAllocString [OLE32.@]
2408 * Basically a copy of SysAllocStringLen.
2410 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2414 WCHAR
* stringBuffer
;
2419 len
= lstrlenW(str
);
2421 * Find the length of the buffer passed-in in bytes.
2423 bufferSize
= len
* sizeof (WCHAR
);
2426 * Allocate a new buffer to hold the string.
2427 * don't forget to keep an empty spot at the beginning of the
2428 * buffer for the character count and an extra character at the
2431 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2432 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2435 * If the memory allocation failed, return a null pointer.
2441 * Copy the length of the string in the placeholder.
2443 *newBuffer
= bufferSize
;
2446 * Skip the byte count.
2451 * Copy the information in the buffer.
2452 * Since it is valid to pass a NULL pointer here, we'll initialize the
2453 * buffer to nul if it is the case.
2456 memcpy(newBuffer
, str
, bufferSize
);
2458 memset(newBuffer
, 0, bufferSize
);
2461 * Make sure that there is a nul character at the end of the
2464 stringBuffer
= (WCHAR
*)newBuffer
;
2465 stringBuffer
[len
] = L
'\0';
2467 return (LPWSTR
)stringBuffer
;
2470 /***********************************************************************
2471 * PropSysFreeString [OLE32.@]
2473 * Copy of SysFreeString.
2475 void WINAPI
PropSysFreeString(LPOLESTR str
)
2477 DWORD
* bufferPointer
;
2479 /* NULL is a valid parameter */
2483 * We have to be careful when we free a BSTR pointer, it points to
2484 * the beginning of the string but it skips the byte count contained
2485 * before the string.
2487 bufferPointer
= (DWORD
*)str
;
2492 * Free the memory from its "real" origin.
2494 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2497 /******************************************************************************
2498 * Check if a PROPVARIANT's type is valid.
2500 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2526 case VT_STREAMED_OBJECT
:
2527 case VT_STORED_OBJECT
:
2528 case VT_BLOB_OBJECT
:
2531 case VT_I2
|VT_VECTOR
:
2532 case VT_I4
|VT_VECTOR
:
2533 case VT_R4
|VT_VECTOR
:
2534 case VT_R8
|VT_VECTOR
:
2535 case VT_CY
|VT_VECTOR
:
2536 case VT_DATE
|VT_VECTOR
:
2537 case VT_BSTR
|VT_VECTOR
:
2538 case VT_ERROR
|VT_VECTOR
:
2539 case VT_BOOL
|VT_VECTOR
:
2540 case VT_VARIANT
|VT_VECTOR
:
2541 case VT_UI1
|VT_VECTOR
:
2542 case VT_UI2
|VT_VECTOR
:
2543 case VT_UI4
|VT_VECTOR
:
2544 case VT_I8
|VT_VECTOR
:
2545 case VT_UI8
|VT_VECTOR
:
2546 case VT_LPSTR
|VT_VECTOR
:
2547 case VT_LPWSTR
|VT_VECTOR
:
2548 case VT_FILETIME
|VT_VECTOR
:
2549 case VT_CF
|VT_VECTOR
:
2550 case VT_CLSID
|VT_VECTOR
:
2553 WARN("Bad type %d\n", vt
);
2554 return STG_E_INVALIDPARAMETER
;
2557 /***********************************************************************
2558 * PropVariantClear [OLE32.@]
2560 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2564 TRACE("(%p)\n", pvar
);
2569 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2576 case VT_STREAMED_OBJECT
:
2578 case VT_STORED_OBJECT
:
2579 if (pvar
->u
.pStream
)
2580 IUnknown_Release(pvar
->u
.pStream
);
2585 /* pick an arbitary typed pointer - we don't care about the type
2586 * as we are just freeing it */
2587 CoTaskMemFree(pvar
->u
.puuid
);
2590 case VT_BLOB_OBJECT
:
2591 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2594 if (pvar
->u
.bstrVal
)
2595 PropSysFreeString(pvar
->u
.bstrVal
);
2598 if (pvar
->u
.pclipdata
)
2600 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2601 CoTaskMemFree(pvar
->u
.pclipdata
);
2605 if (pvar
->vt
& VT_VECTOR
)
2609 switch (pvar
->vt
& ~VT_VECTOR
)
2612 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2615 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2618 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2619 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2622 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2623 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2626 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2627 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2630 if (pvar
->vt
& ~VT_VECTOR
)
2632 /* pick an arbitary VT_VECTOR structure - they all have the same
2634 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2638 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2641 ZeroMemory(pvar
, sizeof(*pvar
));
2646 /***********************************************************************
2647 * PropVariantCopy [OLE32.@]
2649 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2650 const PROPVARIANT
*pvarSrc
) /* [in] */
2655 TRACE("(%p, %p)\n", pvarDest
, pvarSrc
);
2657 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2661 /* this will deal with most cases */
2662 CopyMemory(pvarDest
, pvarSrc
, sizeof(*pvarDest
));
2667 case VT_STREAMED_OBJECT
:
2669 case VT_STORED_OBJECT
:
2670 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2673 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2674 CopyMemory(pvarDest
->u
.puuid
, pvarSrc
->u
.puuid
, sizeof(CLSID
));
2677 len
= strlen(pvarSrc
->u
.pszVal
);
2678 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2679 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2682 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2683 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2684 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2687 case VT_BLOB_OBJECT
:
2688 if (pvarSrc
->u
.blob
.pBlobData
)
2690 len
= pvarSrc
->u
.blob
.cbSize
;
2691 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2692 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2696 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2699 if (pvarSrc
->u
.pclipdata
)
2701 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2702 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2703 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2707 if (pvarSrc
->vt
& VT_VECTOR
)
2712 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2714 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2715 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2716 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
2717 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
2718 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
2719 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
2720 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
2721 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
2722 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
2723 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
2724 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
2725 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
2726 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
2727 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
2728 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
2729 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
2730 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
2731 case VT_BSTR
: elemSize
= sizeof(*pvarSrc
->u
.bstrVal
); break;
2732 case VT_LPSTR
: elemSize
= sizeof(*pvarSrc
->u
.pszVal
); break;
2733 case VT_LPWSTR
: elemSize
= sizeof(*pvarSrc
->u
.pwszVal
); break;
2737 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
2738 return E_INVALIDARG
;
2740 len
= pvarSrc
->u
.capropvar
.cElems
;
2741 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
2742 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
2744 for (i
= 0; i
< len
; i
++)
2745 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
2747 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
2749 FIXME("Copy clipformats\n");
2751 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
2753 for (i
= 0; i
< len
; i
++)
2754 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
2756 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
2759 for (i
= 0; i
< len
; i
++)
2761 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
2762 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2763 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2764 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2767 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
2770 for (i
= 0; i
< len
; i
++)
2772 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
2774 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2775 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2776 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2780 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
2783 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
2789 /***********************************************************************
2790 * FreePropVariantArray [OLE32.@]
2792 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
2793 PROPVARIANT
*rgvars
) /* [in/out] */
2797 TRACE("(%lu, %p)\n", cVariants
, rgvars
);
2799 for(i
= 0; i
< cVariants
; i
++)
2800 PropVariantClear(&rgvars
[i
]);
2805 /******************************************************************************
2806 * DllDebugObjectRPCHook (OLE32.@)
2807 * turns on and off internal debugging, pointer is only used on macintosh
2810 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)