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 LONG 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 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
133 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
134 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
135 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
136 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
137 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
138 static 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 DropTargetNode
* OLEDD_FindDropTarget(
152 static void OLEDD_FreeDropTarget(DropTargetNode
*);
153 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
158 static void OLEDD_TrackMouseMove(
159 TrackerWindowInfo
* trackerInfo
);
160 static void OLEDD_TrackStateChange(
161 TrackerWindowInfo
* trackerInfo
);
162 static DWORD
OLEDD_GetButtonState(void);
165 /******************************************************************************
166 * OleBuildVersion [OLE2.1]
167 * OleBuildVersion [OLE32.@]
169 DWORD WINAPI
OleBuildVersion(void)
171 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
172 return (rmm
<<16)+rup
;
175 /***********************************************************************
176 * OleInitialize (OLE2.2)
177 * OleInitialize (OLE32.@)
179 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
183 TRACE("(%p)\n", reserved
);
186 * The first duty of the OleInitialize is to initialize the COM libraries.
188 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
191 * If the CoInitializeEx call failed, the OLE libraries can't be
198 * Then, it has to initialize the OLE specific modules.
202 * Object linking and Embedding
203 * In-place activation
205 if (!COM_CurrentInfo()->ole_inits
++ &&
206 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
209 * Initialize the libraries.
211 TRACE("() - Initializing the OLE libraries\n");
216 OLEClipbrd_Initialize();
226 OLEMenu_Initialize();
232 /******************************************************************************
233 * OleUninitialize [OLE2.3]
234 * OleUninitialize [OLE32.@]
236 void WINAPI
OleUninitialize(void)
241 * If we hit the bottom of the lock stack, free the libraries.
243 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
246 * Actually free the libraries.
248 TRACE("() - Freeing the last reference count\n");
253 OLEClipbrd_UnInitialize();
258 OLEMenu_UnInitialize();
262 * Then, uninitialize the COM libraries.
267 /******************************************************************************
268 * OleInitializeWOW [OLE32.@]
270 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
271 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
275 /***********************************************************************
276 * RegisterDragDrop (OLE32.@)
278 HRESULT WINAPI
RegisterDragDrop(
280 LPDROPTARGET pDropTarget
)
282 DropTargetNode
* dropTargetInfo
;
284 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
286 if (!COM_CurrentApt())
288 ERR("COM not initialized\n");
289 return CO_E_NOTINITIALIZED
;
297 ERR("invalid hwnd %p\n", hwnd
);
298 return DRAGDROP_E_INVALIDHWND
;
302 * First, check if the window is already registered.
304 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
306 if (dropTargetInfo
!=NULL
)
307 return DRAGDROP_E_ALREADYREGISTERED
;
310 * If it's not there, we can add it. We first create a node for it.
312 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
314 if (dropTargetInfo
==NULL
)
315 return E_OUTOFMEMORY
;
317 dropTargetInfo
->hwndTarget
= hwnd
;
320 * Don't forget that this is an interface pointer, need to nail it down since
321 * we keep a copy of it.
323 IDropTarget_AddRef(pDropTarget
);
324 dropTargetInfo
->dropTarget
= pDropTarget
;
326 list_add_tail(&targetListHead
, &dropTargetInfo
->entry
);
331 /***********************************************************************
332 * RevokeDragDrop (OLE32.@)
334 HRESULT WINAPI
RevokeDragDrop(
337 DropTargetNode
* dropTargetInfo
;
339 TRACE("(%p)\n", hwnd
);
343 ERR("invalid hwnd %p\n", hwnd
);
344 return DRAGDROP_E_INVALIDHWND
;
348 * First, check if the window is already registered.
350 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
353 * If it ain't in there, it's an error.
355 if (dropTargetInfo
==NULL
)
356 return DRAGDROP_E_NOTREGISTERED
;
358 OLEDD_FreeDropTarget(dropTargetInfo
);
363 /***********************************************************************
364 * OleRegGetUserType (OLE32.@)
366 * This implementation of OleRegGetUserType ignores the dwFormOfType
367 * parameter and always returns the full name of the object. This is
368 * not too bad since this is the case for many objects because of the
369 * way they are registered.
371 HRESULT WINAPI
OleRegGetUserType(
374 LPOLESTR
* pszUserType
)
384 * Initialize the out parameter.
389 * Build the key name we're looking for
391 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
392 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
393 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
394 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
396 TRACE("(%s, %d, %p)\n", keyName
, dwFormOfType
, pszUserType
);
399 * Open the class id Key
401 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
405 if (hres
!= ERROR_SUCCESS
)
406 return REGDB_E_CLASSNOTREG
;
409 * Retrieve the size of the name string.
413 hres
= RegQueryValueExA(clsidKey
,
420 if (hres
!=ERROR_SUCCESS
)
422 RegCloseKey(clsidKey
);
423 return REGDB_E_READREGDB
;
427 * Allocate a buffer for the registry value.
429 *pszUserType
= CoTaskMemAlloc(cbData
*2);
431 if (*pszUserType
==NULL
)
433 RegCloseKey(clsidKey
);
434 return E_OUTOFMEMORY
;
437 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
441 RegCloseKey(clsidKey
);
442 CoTaskMemFree(*pszUserType
);
444 return E_OUTOFMEMORY
;
447 hres
= RegQueryValueExA(clsidKey
,
454 RegCloseKey(clsidKey
);
457 if (hres
!=ERROR_SUCCESS
)
459 CoTaskMemFree(*pszUserType
);
462 retVal
= REGDB_E_READREGDB
;
466 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
469 HeapFree(GetProcessHeap(), 0, buffer
);
474 /***********************************************************************
475 * DoDragDrop [OLE32.@]
477 HRESULT WINAPI
DoDragDrop (
478 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
479 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
480 DWORD dwOKEffect
, /* [in] effects allowed by the source */
481 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
483 TrackerWindowInfo trackerInfo
;
484 HWND hwndTrackWindow
;
487 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
490 * Setup the drag n drop tracking window.
492 if (!IsValidInterface((LPUNKNOWN
)pDropSource
))
495 trackerInfo
.dataObject
= pDataObject
;
496 trackerInfo
.dropSource
= pDropSource
;
497 trackerInfo
.dwOKEffect
= dwOKEffect
;
498 trackerInfo
.pdwEffect
= pdwEffect
;
499 trackerInfo
.trackingDone
= FALSE
;
500 trackerInfo
.escPressed
= FALSE
;
501 trackerInfo
.curDragTargetHWND
= 0;
502 trackerInfo
.curTargetHWND
= 0;
503 trackerInfo
.curDragTarget
= 0;
505 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
508 CW_USEDEFAULT
, CW_USEDEFAULT
,
509 CW_USEDEFAULT
, CW_USEDEFAULT
,
513 (LPVOID
)&trackerInfo
);
515 if (hwndTrackWindow
!=0)
518 * Capture the mouse input
520 SetCapture(hwndTrackWindow
);
525 * Pump messages. All mouse input should go the the capture window.
527 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
529 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
530 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
531 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
533 if ( (msg
.message
>= WM_KEYFIRST
) &&
534 (msg
.message
<= WM_KEYLAST
) )
537 * When keyboard messages are sent to windows on this thread, we
538 * want to ignore notify the drop source that the state changed.
539 * in the case of the Escape key, we also notify the drop source
540 * we give it a special meaning.
542 if ( (msg
.message
==WM_KEYDOWN
) &&
543 (msg
.wParam
==VK_ESCAPE
) )
545 trackerInfo
.escPressed
= TRUE
;
549 * Notify the drop source.
551 OLEDD_TrackStateChange(&trackerInfo
);
556 * Dispatch the messages only when it's not a keyboard message.
558 DispatchMessageA(&msg
);
562 /* re-post the quit message to outer message loop */
563 if (msg
.message
== WM_QUIT
)
564 PostQuitMessage(msg
.wParam
);
566 * Destroy the temporary window.
568 DestroyWindow(hwndTrackWindow
);
570 return trackerInfo
.returnValue
;
576 /***********************************************************************
577 * OleQueryLinkFromData [OLE32.@]
579 HRESULT WINAPI
OleQueryLinkFromData(
580 IDataObject
* pSrcDataObject
)
582 FIXME("(%p),stub!\n", pSrcDataObject
);
586 /***********************************************************************
587 * OleRegGetMiscStatus [OLE32.@]
589 HRESULT WINAPI
OleRegGetMiscStatus(
601 * Initialize the out parameter.
606 * Build the key name we're looking for
608 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
609 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
610 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
611 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
613 TRACE("(%s, %d, %p)\n", keyName
, dwAspect
, pdwStatus
);
616 * Open the class id Key
618 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
622 if (result
!= ERROR_SUCCESS
)
623 return REGDB_E_CLASSNOTREG
;
628 result
= RegOpenKeyA(clsidKey
,
633 if (result
!= ERROR_SUCCESS
)
635 RegCloseKey(clsidKey
);
636 return REGDB_E_READREGDB
;
640 * Read the default value
642 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
645 * Open the key specific to the requested aspect.
647 sprintf(keyName
, "%d", dwAspect
);
649 result
= RegOpenKeyA(miscStatusKey
,
653 if (result
== ERROR_SUCCESS
)
655 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
656 RegCloseKey(aspectKey
);
662 RegCloseKey(miscStatusKey
);
663 RegCloseKey(clsidKey
);
668 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
672 const IEnumOLEVERBVtbl
*lpvtbl
;
679 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
680 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
682 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
683 if (IsEqualIID(riid
, &IID_IUnknown
) ||
684 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
686 IUnknown_AddRef(iface
);
690 return E_NOINTERFACE
;
693 static ULONG WINAPI
EnumOLEVERB_AddRef(
696 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
698 return InterlockedIncrement(&This
->ref
);
701 static ULONG WINAPI
EnumOLEVERB_Release(
704 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
705 LONG refs
= InterlockedDecrement(&This
->ref
);
709 RegCloseKey(This
->hkeyVerb
);
710 HeapFree(GetProcessHeap(), 0, This
);
715 static HRESULT WINAPI
EnumOLEVERB_Next(
716 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
719 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
722 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
727 for (; celt
; celt
--, rgelt
++)
732 LPWSTR pwszMenuFlags
;
734 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
735 if (res
== ERROR_NO_MORE_ITEMS
)
740 else if (res
!= ERROR_SUCCESS
)
742 ERR("RegEnumKeyW failed with error %d\n", res
);
743 hr
= REGDB_E_READREGDB
;
746 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
747 if (res
!= ERROR_SUCCESS
)
749 ERR("RegQueryValueW failed with error %d\n", res
);
750 hr
= REGDB_E_READREGDB
;
753 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
759 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
760 if (res
!= ERROR_SUCCESS
)
762 ERR("RegQueryValueW failed with error %d\n", res
);
763 hr
= REGDB_E_READREGDB
;
764 CoTaskMemFree(pwszOLEVERB
);
768 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
769 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
772 hr
= OLEOBJ_E_INVALIDVERB
;
773 CoTaskMemFree(pwszOLEVERB
);
776 /* nul terminate the name string and advance to first character */
777 *pwszMenuFlags
= '\0';
779 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
782 hr
= OLEOBJ_E_INVALIDVERB
;
783 CoTaskMemFree(pwszOLEVERB
);
786 /* nul terminate the menu string and advance to first character */
790 /* fill out structure for this verb */
791 rgelt
->lVerb
= atolW(wszSubKey
);
792 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
793 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
794 rgelt
->grfAttribs
= atolW(pwszAttribs
);
803 static HRESULT WINAPI
EnumOLEVERB_Skip(
804 IEnumOLEVERB
*iface
, ULONG celt
)
806 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
808 TRACE("(%d)\n", celt
);
814 static HRESULT WINAPI
EnumOLEVERB_Reset(
817 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
825 static HRESULT WINAPI
EnumOLEVERB_Clone(
827 IEnumOLEVERB
**ppenum
)
829 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
831 TRACE("(%p)\n", ppenum
);
832 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
833 return HRESULT_FROM_WIN32(GetLastError());
834 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
837 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
839 EnumOLEVERB_QueryInterface
,
848 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
850 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
853 RegCloseKey(hkeyVerb
);
854 return E_OUTOFMEMORY
;
856 This
->lpvtbl
= &EnumOLEVERB_VTable
;
859 This
->hkeyVerb
= hkeyVerb
;
860 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
864 /***********************************************************************
865 * OleRegEnumVerbs [OLE32.@]
867 * Enumerates verbs associated with a class stored in the registry.
870 * clsid [I] Class ID to enumerate the verbs for.
871 * ppenum [O] Enumerator.
875 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
876 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
877 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
878 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
880 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
885 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
887 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
889 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
892 if (res
== REGDB_E_CLASSNOTREG
)
893 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
894 else if (res
== REGDB_E_KEYMISSING
)
895 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
897 ERR("failed to open Verbs key for CLSID %s with error %d\n",
898 debugstr_guid(clsid
), res
);
902 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
903 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
904 if (res
!= ERROR_SUCCESS
)
906 ERR("failed to get subkey count with error %d\n", GetLastError());
907 return REGDB_E_READREGDB
;
912 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
913 RegCloseKey(hkeyVerb
);
914 return OLEOBJ_E_NOVERBS
;
917 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
920 /******************************************************************************
921 * OleSetContainedObject [OLE32.@]
923 HRESULT WINAPI
OleSetContainedObject(
927 IRunnableObject
* runnable
= NULL
;
930 TRACE("(%p,%x)\n", pUnknown
, fContained
);
932 hres
= IUnknown_QueryInterface(pUnknown
,
933 &IID_IRunnableObject
,
938 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
940 IRunnableObject_Release(runnable
);
948 /******************************************************************************
951 * Set the OLE object to the running state.
954 * pUnknown [I] OLE object to run.
958 * Failure: Any HRESULT code.
960 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
962 IRunnableObject
*runable
;
965 TRACE("(%p)\n", pUnknown
);
967 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
969 return S_OK
; /* Appears to return no error. */
971 hres
= IRunnableObject_Run(runable
, NULL
);
972 IRunnableObject_Release(runable
);
976 /******************************************************************************
979 HRESULT WINAPI
OleLoad(
982 LPOLECLIENTSITE pClientSite
,
985 IPersistStorage
* persistStorage
= NULL
;
987 IOleObject
* pOleObject
= NULL
;
991 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
996 * TODO, Conversion ... OleDoAutoConvert
1000 * Get the class ID for the object.
1002 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1005 * Now, try and create the handler for the object
1007 hres
= CoCreateInstance(&storageInfo
.clsid
,
1009 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1014 * If that fails, as it will most times, load the default
1019 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1026 * If we couldn't find a handler... this is bad. Abort the whole thing.
1033 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1034 if (SUCCEEDED(hres
))
1037 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1041 if (SUCCEEDED(hres
))
1043 * Initialize the object with it's IPersistStorage interface.
1045 hres
= IOleObject_QueryInterface(pUnk
,
1046 &IID_IPersistStorage
,
1047 (void**)&persistStorage
);
1049 if (SUCCEEDED(hres
))
1051 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1053 IPersistStorage_Release(persistStorage
);
1054 persistStorage
= NULL
;
1057 if (SUCCEEDED(hres
) && pClientSite
)
1059 * Inform the new object of it's client site.
1061 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1064 * Cleanup interfaces used internally
1067 IOleObject_Release(pOleObject
);
1069 if (SUCCEEDED(hres
))
1073 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1074 if (SUCCEEDED(hres1
))
1076 FIXME("handle OLE link\n");
1077 IOleLink_Release(pOleLink
);
1083 IUnknown_Release(pUnk
);
1092 /***********************************************************************
1095 HRESULT WINAPI
OleSave(
1096 LPPERSISTSTORAGE pPS
,
1103 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1106 * First, we transfer the class ID (if available)
1108 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1110 if (SUCCEEDED(hres
))
1112 WriteClassStg(pStg
, &objectClass
);
1116 * Then, we ask the object to save itself to the
1117 * storage. If it is successful, we commit the storage.
1119 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1121 if (SUCCEEDED(hres
))
1123 IStorage_Commit(pStg
,
1131 /******************************************************************************
1132 * OleLockRunning [OLE32.@]
1134 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1136 IRunnableObject
* runnable
= NULL
;
1139 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1141 hres
= IUnknown_QueryInterface(pUnknown
,
1142 &IID_IRunnableObject
,
1145 if (SUCCEEDED(hres
))
1147 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1149 IRunnableObject_Release(runnable
);
1154 return E_INVALIDARG
;
1158 /**************************************************************************
1159 * Internal methods to manage the shared OLE menu in response to the
1160 * OLE***MenuDescriptor API
1164 * OLEMenu_Initialize()
1166 * Initializes the OLEMENU data structures.
1168 static void OLEMenu_Initialize(void)
1173 * OLEMenu_UnInitialize()
1175 * Releases the OLEMENU data structures.
1177 static void OLEMenu_UnInitialize(void)
1181 /*************************************************************************
1182 * OLEMenu_InstallHooks
1183 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1185 * RETURNS: TRUE if message hooks were successfully installed
1188 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1190 OleMenuHookItem
*pHookItem
= NULL
;
1192 /* Create an entry for the hook table */
1193 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1194 sizeof(OleMenuHookItem
)) ) )
1197 pHookItem
->tid
= tid
;
1198 pHookItem
->hHeap
= GetProcessHeap();
1200 /* Install a thread scope message hook for WH_GETMESSAGE */
1201 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1202 0, GetCurrentThreadId() );
1203 if ( !pHookItem
->GetMsg_hHook
)
1206 /* Install a thread scope message hook for WH_CALLWNDPROC */
1207 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1208 0, GetCurrentThreadId() );
1209 if ( !pHookItem
->CallWndProc_hHook
)
1212 /* Insert the hook table entry */
1213 pHookItem
->next
= hook_list
;
1214 hook_list
= pHookItem
;
1219 /* Unhook any hooks */
1220 if ( pHookItem
->GetMsg_hHook
)
1221 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1222 if ( pHookItem
->CallWndProc_hHook
)
1223 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1224 /* Release the hook table entry */
1225 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1230 /*************************************************************************
1231 * OLEMenu_UnInstallHooks
1232 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1234 * RETURNS: TRUE if message hooks were successfully installed
1237 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1239 OleMenuHookItem
*pHookItem
= NULL
;
1240 OleMenuHookItem
**ppHook
= &hook_list
;
1244 if ((*ppHook
)->tid
== tid
)
1246 pHookItem
= *ppHook
;
1247 *ppHook
= pHookItem
->next
;
1250 ppHook
= &(*ppHook
)->next
;
1252 if (!pHookItem
) return FALSE
;
1254 /* Uninstall the hooks installed for this thread */
1255 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1257 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1260 /* Release the hook table entry */
1261 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1266 /* Release the hook table entry */
1267 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1272 /*************************************************************************
1273 * OLEMenu_IsHookInstalled
1274 * Tests if OLEMenu hooks have been installed for a thread
1276 * RETURNS: The pointer and index of the hook table entry for the tid
1277 * NULL and -1 for the index if no hooks were installed for this thread
1279 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1281 OleMenuHookItem
*pHookItem
= NULL
;
1283 /* Do a simple linear search for an entry whose tid matches ours.
1284 * We really need a map but efficiency is not a concern here. */
1285 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1287 if ( tid
== pHookItem
->tid
)
1294 /***********************************************************************
1295 * OLEMenu_FindMainMenuIndex
1297 * Used by OLEMenu API to find the top level group a menu item belongs to.
1298 * On success pnPos contains the index of the item in the top level menu group
1300 * RETURNS: TRUE if the ID was found, FALSE on failure
1302 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1306 nItems
= GetMenuItemCount( hMainMenu
);
1308 for (i
= 0; i
< nItems
; i
++)
1312 /* Is the current item a submenu? */
1313 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1315 /* If the handle is the same we're done */
1316 if ( hsubmenu
== hPopupMenu
)
1322 /* Recursively search without updating pnPos */
1323 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1335 /***********************************************************************
1336 * OLEMenu_SetIsServerMenu
1338 * Checks whether a popup menu belongs to a shared menu group which is
1339 * owned by the server, and sets the menu descriptor state accordingly.
1340 * All menu messages from these groups should be routed to the server.
1342 * RETURNS: TRUE if the popup menu is part of a server owned group
1343 * FALSE if the popup menu is part of a container owned group
1345 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1347 UINT nPos
= 0, nWidth
, i
;
1349 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1351 /* Don't bother searching if the popup is the combined menu itself */
1352 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1355 /* Find the menu item index in the shared OLE menu that this item belongs to */
1356 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1359 /* The group widths array has counts for the number of elements
1360 * in the groups File, Edit, Container, Object, Window, Help.
1361 * The Edit, Object & Help groups belong to the server object
1362 * and the other three belong to the container.
1363 * Loop through the group widths and locate the group we are a member of.
1365 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1367 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1368 if ( nPos
< nWidth
)
1370 /* Odd elements are server menu widths */
1371 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1376 return pOleMenuDescriptor
->bIsServerItem
;
1379 /*************************************************************************
1380 * OLEMenu_CallWndProc
1381 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1382 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1384 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1386 LPCWPSTRUCT pMsg
= NULL
;
1387 HOLEMENU hOleMenu
= 0;
1388 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1389 OleMenuHookItem
*pHookItem
= NULL
;
1392 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1394 /* Check if we're being asked to process the message */
1395 if ( HC_ACTION
!= code
)
1398 /* Retrieve the current message being dispatched from lParam */
1399 pMsg
= (LPCWPSTRUCT
)lParam
;
1401 /* Check if the message is destined for a window we are interested in:
1402 * If the window has an OLEMenu property we may need to dispatch
1403 * the menu message to its active objects window instead. */
1405 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1409 /* Get the menu descriptor */
1410 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1411 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1414 /* Process menu messages */
1415 switch( pMsg
->message
)
1419 /* Reset the menu descriptor state */
1420 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1422 /* Send this message to the server as well */
1423 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1424 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1428 case WM_INITMENUPOPUP
:
1430 /* Save the state for whether this is a server owned menu */
1431 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1437 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1438 if ( fuFlags
& MF_SYSMENU
)
1441 /* Save the state for whether this is a server owned popup menu */
1442 else if ( fuFlags
& MF_POPUP
)
1443 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1450 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1451 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1452 goto NEXTHOOK
; /* Not a menu message */
1461 /* If the message was for the server dispatch it accordingly */
1462 if ( pOleMenuDescriptor
->bIsServerItem
)
1464 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1465 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1469 if ( pOleMenuDescriptor
)
1470 GlobalUnlock( hOleMenu
);
1472 /* Lookup the hook item for the current thread */
1473 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1475 /* This should never fail!! */
1476 WARN("could not retrieve hHook for current thread!\n" );
1480 /* Pass on the message to the next hooker */
1481 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1484 /*************************************************************************
1485 * OLEMenu_GetMsgProc
1486 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1487 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1489 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1492 HOLEMENU hOleMenu
= 0;
1493 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1494 OleMenuHookItem
*pHookItem
= NULL
;
1497 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1499 /* Check if we're being asked to process a messages */
1500 if ( HC_ACTION
!= code
)
1503 /* Retrieve the current message being dispatched from lParam */
1504 pMsg
= (LPMSG
)lParam
;
1506 /* Check if the message is destined for a window we are interested in:
1507 * If the window has an OLEMenu property we may need to dispatch
1508 * the menu message to its active objects window instead. */
1510 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1514 /* Process menu messages */
1515 switch( pMsg
->message
)
1519 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1521 goto NEXTHOOK
; /* Not a menu message */
1528 /* Get the menu descriptor */
1529 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1530 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1533 /* If the message was for the server dispatch it accordingly */
1534 if ( pOleMenuDescriptor
->bIsServerItem
)
1536 /* Change the hWnd in the message to the active objects hWnd.
1537 * The message loop which reads this message will automatically
1538 * dispatch it to the embedded objects window. */
1539 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1543 if ( pOleMenuDescriptor
)
1544 GlobalUnlock( hOleMenu
);
1546 /* Lookup the hook item for the current thread */
1547 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1549 /* This should never fail!! */
1550 WARN("could not retrieve hHook for current thread!\n" );
1554 /* Pass on the message to the next hooker */
1555 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1558 /***********************************************************************
1559 * OleCreateMenuDescriptor [OLE32.@]
1560 * Creates an OLE menu descriptor for OLE to use when dispatching
1561 * menu messages and commands.
1564 * hmenuCombined - Handle to the objects combined menu
1565 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1568 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1569 HMENU hmenuCombined
,
1570 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1573 OleMenuDescriptor
*pOleMenuDescriptor
;
1576 if ( !hmenuCombined
|| !lpMenuWidths
)
1579 /* Create an OLE menu descriptor */
1580 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1581 sizeof(OleMenuDescriptor
) ) ) )
1584 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1585 if ( !pOleMenuDescriptor
)
1588 /* Initialize menu group widths and hmenu */
1589 for ( i
= 0; i
< 6; i
++ )
1590 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1592 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1593 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1594 GlobalUnlock( hOleMenu
);
1599 /***********************************************************************
1600 * OleDestroyMenuDescriptor [OLE32.@]
1601 * Destroy the shared menu descriptor
1603 HRESULT WINAPI
OleDestroyMenuDescriptor(
1604 HOLEMENU hmenuDescriptor
)
1606 if ( hmenuDescriptor
)
1607 GlobalFree( hmenuDescriptor
);
1611 /***********************************************************************
1612 * OleSetMenuDescriptor [OLE32.@]
1613 * Installs or removes OLE dispatching code for the containers frame window.
1616 * hOleMenu Handle to composite menu descriptor
1617 * hwndFrame Handle to containers frame window
1618 * hwndActiveObject Handle to objects in-place activation window
1619 * lpFrame Pointer to IOleInPlaceFrame on containers window
1620 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1623 * S_OK - menu installed correctly
1624 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1627 * The lpFrame and lpActiveObject parameters are currently ignored
1628 * OLE should install context sensitive help F1 filtering for the app when
1629 * these are non null.
1631 HRESULT WINAPI
OleSetMenuDescriptor(
1634 HWND hwndActiveObject
,
1635 LPOLEINPLACEFRAME lpFrame
,
1636 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1638 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1641 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1642 return E_INVALIDARG
;
1644 if ( lpFrame
|| lpActiveObject
)
1646 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1654 /* Set up a message hook to intercept the containers frame window messages.
1655 * The message filter is responsible for dispatching menu messages from the
1656 * shared menu which are intended for the object.
1659 if ( hOleMenu
) /* Want to install dispatching code */
1661 /* If OLEMenu hooks are already installed for this thread, fail
1662 * Note: This effectively means that OleSetMenuDescriptor cannot
1663 * be called twice in succession on the same frame window
1664 * without first calling it with a null hOleMenu to uninstall */
1665 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1668 /* Get the menu descriptor */
1669 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1670 if ( !pOleMenuDescriptor
)
1671 return E_UNEXPECTED
;
1673 /* Update the menu descriptor */
1674 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1675 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1677 GlobalUnlock( hOleMenu
);
1678 pOleMenuDescriptor
= NULL
;
1680 /* Add a menu descriptor windows property to the frame window */
1681 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1683 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1684 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1687 else /* Want to uninstall dispatching code */
1689 /* Uninstall the hooks */
1690 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1693 /* Remove the menu descriptor property from the frame window */
1694 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1700 /******************************************************************************
1701 * IsAccelerator [OLE32.@]
1702 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1704 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1709 if(!lpMsg
) return FALSE
;
1712 WARN_(accel
)("NULL accel handle\n");
1715 if((lpMsg
->message
!= WM_KEYDOWN
&&
1716 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1717 lpMsg
->message
!= WM_SYSCHAR
&&
1718 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1719 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1720 if (NULL
== lpAccelTbl
)
1724 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1726 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1727 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1731 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1732 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1733 hAccel
, cAccelEntries
,
1734 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1735 for(i
= 0; i
< cAccelEntries
; i
++)
1737 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1740 if(lpMsg
->message
== WM_CHAR
)
1742 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1744 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1750 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1753 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1754 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1755 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1756 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1757 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1758 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1759 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1763 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1765 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1766 { /* ^^ ALT pressed */
1767 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1775 WARN_(accel
)("couldn't translate accelerator key\n");
1776 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1780 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1781 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1785 /***********************************************************************
1786 * ReleaseStgMedium [OLE32.@]
1788 void WINAPI
ReleaseStgMedium(
1791 switch (pmedium
->tymed
)
1795 if ( (pmedium
->pUnkForRelease
==0) &&
1796 (pmedium
->u
.hGlobal
!=0) )
1797 GlobalFree(pmedium
->u
.hGlobal
);
1802 if (pmedium
->u
.lpszFileName
!=0)
1804 if (pmedium
->pUnkForRelease
==0)
1806 DeleteFileW(pmedium
->u
.lpszFileName
);
1809 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1815 if (pmedium
->u
.pstm
!=0)
1817 IStream_Release(pmedium
->u
.pstm
);
1821 case TYMED_ISTORAGE
:
1823 if (pmedium
->u
.pstg
!=0)
1825 IStorage_Release(pmedium
->u
.pstg
);
1831 if ( (pmedium
->pUnkForRelease
==0) &&
1832 (pmedium
->u
.hBitmap
!=0) )
1833 DeleteObject(pmedium
->u
.hBitmap
);
1838 if ( (pmedium
->pUnkForRelease
==0) &&
1839 (pmedium
->u
.hMetaFilePict
!=0) )
1841 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1842 DeleteMetaFile(pMP
->hMF
);
1843 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1844 GlobalFree(pmedium
->u
.hMetaFilePict
);
1850 if ( (pmedium
->pUnkForRelease
==0) &&
1851 (pmedium
->u
.hEnhMetaFile
!=0) )
1853 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1861 pmedium
->tymed
=TYMED_NULL
;
1864 * After cleaning up, the unknown is released
1866 if (pmedium
->pUnkForRelease
!=0)
1868 IUnknown_Release(pmedium
->pUnkForRelease
);
1869 pmedium
->pUnkForRelease
= 0;
1874 * OLEDD_Initialize()
1876 * Initializes the OLE drag and drop data structures.
1878 static void OLEDD_Initialize(void)
1882 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1883 wndClass
.style
= CS_GLOBALCLASS
;
1884 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1885 wndClass
.cbClsExtra
= 0;
1886 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1887 wndClass
.hCursor
= 0;
1888 wndClass
.hbrBackground
= 0;
1889 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1891 RegisterClassA (&wndClass
);
1895 * OLEDD_FreeDropTarget()
1897 * Frees the drag and drop data structure
1899 static void OLEDD_FreeDropTarget(DropTargetNode
*dropTargetInfo
)
1901 list_remove(&dropTargetInfo
->entry
);
1902 IDropTarget_Release(dropTargetInfo
->dropTarget
);
1903 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
1907 * OLEDD_UnInitialize()
1909 * Releases the OLE drag and drop data structures.
1911 void OLEDD_UnInitialize(void)
1914 * Simply empty the list.
1916 while (!list_empty(&targetListHead
))
1918 DropTargetNode
* curNode
;
1919 curNode
= LIST_ENTRY(list_head(&targetListHead
), DropTargetNode
, entry
);
1920 OLEDD_FreeDropTarget(curNode
);
1925 * OLEDD_FindDropTarget()
1927 * Finds information about the drop target.
1929 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1931 DropTargetNode
* curNode
;
1934 * Iterate the list to find the HWND value.
1936 LIST_FOR_EACH_ENTRY(curNode
, &targetListHead
, DropTargetNode
, entry
)
1937 if (hwndOfTarget
==curNode
->hwndTarget
)
1941 * If we get here, the item is not in the list
1947 * OLEDD_DragTrackerWindowProc()
1949 * This method is the WindowProcedure of the drag n drop tracking
1950 * window. During a drag n Drop operation, an invisible window is created
1951 * to receive the user input and act upon it. This procedure is in charge
1955 #define DRAG_TIMER_ID 1
1957 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1967 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1969 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1970 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
1977 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1983 case WM_LBUTTONDOWN
:
1984 case WM_MBUTTONDOWN
:
1985 case WM_RBUTTONDOWN
:
1987 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1992 KillTimer(hwnd
, DRAG_TIMER_ID
);
1998 * This is a window proc after all. Let's call the default.
2000 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
2004 * OLEDD_TrackMouseMove()
2006 * This method is invoked while a drag and drop operation is in effect.
2007 * it will generate the appropriate callbacks in the drop source
2008 * and drop target. It will also provide the expected feedback to
2012 * trackerInfo - Pointer to the structure identifying the
2013 * drag & drop operation that is currently
2016 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2018 HWND hwndNewTarget
= 0;
2023 * Get the handle of the window under the mouse
2025 pt
.x
= trackerInfo
->curMousePos
.x
;
2026 pt
.y
= trackerInfo
->curMousePos
.y
;
2027 hwndNewTarget
= WindowFromPoint(pt
);
2030 * Every time, we re-initialize the effects passed to the
2031 * IDropTarget to the effects allowed by the source.
2033 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2036 * If we are hovering over the same target as before, send the
2037 * DragOver notification
2039 if ( (trackerInfo
->curDragTarget
!= 0) &&
2040 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2042 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2043 trackerInfo
->dwKeyState
,
2044 trackerInfo
->curMousePos
,
2045 trackerInfo
->pdwEffect
);
2049 DropTargetNode
* newDropTargetNode
= 0;
2052 * If we changed window, we have to notify our old target and check for
2055 if (trackerInfo
->curDragTarget
!=0)
2057 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2061 * Make sure we're hovering over a window.
2063 if (hwndNewTarget
!=0)
2066 * Find-out if there is a drag target under the mouse
2068 HWND nexttar
= hwndNewTarget
;
2069 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2072 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2073 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2074 if(nexttar
) hwndNewTarget
= nexttar
;
2076 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2077 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2080 * If there is, notify it that we just dragged-in
2082 if (trackerInfo
->curDragTarget
!=0)
2084 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2085 trackerInfo
->dataObject
,
2086 trackerInfo
->dwKeyState
,
2087 trackerInfo
->curMousePos
,
2088 trackerInfo
->pdwEffect
);
2094 * The mouse is not over a window so we don't track anything.
2096 trackerInfo
->curDragTargetHWND
= 0;
2097 trackerInfo
->curTargetHWND
= 0;
2098 trackerInfo
->curDragTarget
= 0;
2103 * Now that we have done that, we have to tell the source to give
2104 * us feedback on the work being done by the target. If we don't
2105 * have a target, simulate no effect.
2107 if (trackerInfo
->curDragTarget
==0)
2109 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2112 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2113 *trackerInfo
->pdwEffect
);
2116 * When we ask for feedback from the drop source, sometimes it will
2117 * do all the necessary work and sometimes it will not handle it
2118 * when that's the case, we must display the standard drag and drop
2121 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2123 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2125 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2127 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2129 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2131 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2133 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2137 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2143 * OLEDD_TrackStateChange()
2145 * This method is invoked while a drag and drop operation is in effect.
2146 * It is used to notify the drop target/drop source callbacks when
2147 * the state of the keyboard or mouse button change.
2150 * trackerInfo - Pointer to the structure identifying the
2151 * drag & drop operation that is currently
2154 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2157 * Ask the drop source what to do with the operation.
2159 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2160 trackerInfo
->dropSource
,
2161 trackerInfo
->escPressed
,
2162 trackerInfo
->dwKeyState
);
2165 * All the return valued will stop the operation except the S_OK
2168 if (trackerInfo
->returnValue
!=S_OK
)
2171 * Make sure the message loop in DoDragDrop stops
2173 trackerInfo
->trackingDone
= TRUE
;
2176 * Release the mouse in case the drop target decides to show a popup
2177 * or a menu or something.
2182 * If we end-up over a target, drop the object in the target or
2183 * inform the target that the operation was cancelled.
2185 if (trackerInfo
->curDragTarget
!=0)
2187 switch (trackerInfo
->returnValue
)
2190 * If the source wants us to complete the operation, we tell
2191 * the drop target that we just dropped the object in it.
2193 case DRAGDROP_S_DROP
:
2195 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2196 trackerInfo
->dataObject
,
2197 trackerInfo
->dwKeyState
,
2198 trackerInfo
->curMousePos
,
2199 trackerInfo
->pdwEffect
);
2203 * If the source told us that we should cancel, fool the drop
2204 * target by telling it that the mouse left it's window.
2205 * Also set the drop effect to "NONE" in case the application
2206 * ignores the result of DoDragDrop.
2208 case DRAGDROP_S_CANCEL
:
2209 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2210 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2218 * OLEDD_GetButtonState()
2220 * This method will use the current state of the keyboard to build
2221 * a button state mask equivalent to the one passed in the
2222 * WM_MOUSEMOVE wParam.
2224 static DWORD
OLEDD_GetButtonState(void)
2226 BYTE keyboardState
[256];
2229 GetKeyboardState(keyboardState
);
2231 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2232 keyMask
|= MK_SHIFT
;
2234 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2235 keyMask
|= MK_CONTROL
;
2237 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2238 keyMask
|= MK_LBUTTON
;
2240 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2241 keyMask
|= MK_RBUTTON
;
2243 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2244 keyMask
|= MK_MBUTTON
;
2250 * OLEDD_GetButtonState()
2252 * This method will read the default value of the registry key in
2253 * parameter and extract a DWORD value from it. The registry key value
2254 * can be in a string key or a DWORD key.
2257 * regKey - Key to read the default value from
2258 * pdwValue - Pointer to the location where the DWORD
2259 * value is returned. This value is not modified
2260 * if the value is not found.
2263 static void OLEUTL_ReadRegistryDWORDValue(
2272 lres
= RegQueryValueExA(regKey
,
2279 if (lres
==ERROR_SUCCESS
)
2284 *pdwValue
= *(DWORD
*)buffer
;
2289 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2295 /******************************************************************************
2298 * The operation of this function is documented literally in the WinAPI
2299 * documentation to involve a QueryInterface for the IViewObject interface,
2300 * followed by a call to IViewObject::Draw.
2302 HRESULT WINAPI
OleDraw(
2309 IViewObject
*viewobject
;
2311 hres
= IUnknown_QueryInterface(pUnk
,
2313 (void**)&viewobject
);
2315 if (SUCCEEDED(hres
))
2319 rectl
.left
= lprcBounds
->left
;
2320 rectl
.right
= lprcBounds
->right
;
2321 rectl
.top
= lprcBounds
->top
;
2322 rectl
.bottom
= lprcBounds
->bottom
;
2323 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2325 IViewObject_Release(viewobject
);
2330 return DV_E_NOIVIEWOBJECT
;
2334 /***********************************************************************
2335 * OleTranslateAccelerator [OLE32.@]
2337 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2338 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2342 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2344 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2345 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2350 /******************************************************************************
2351 * OleCreate [OLE32.@]
2354 HRESULT WINAPI
OleCreate(
2358 LPFORMATETC pFormatEtc
,
2359 LPOLECLIENTSITE pClientSite
,
2364 IUnknown
* pUnk
= NULL
;
2365 IOleObject
*pOleObject
= NULL
;
2367 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2368 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2370 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2372 if (SUCCEEDED(hres
))
2373 hres
= IStorage_SetClass(pStg
, rclsid
);
2375 if (pClientSite
&& SUCCEEDED(hres
))
2377 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2378 if (SUCCEEDED(hres
))
2381 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2385 if (SUCCEEDED(hres
))
2387 IPersistStorage
* pPS
;
2388 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2390 TRACE("trying to set stg %p\n", pStg
);
2391 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2392 TRACE("-- result 0x%08x\n", hres
);
2393 IPersistStorage_Release(pPS
);
2397 if (pClientSite
&& SUCCEEDED(hres
))
2399 TRACE("trying to set clientsite %p\n", pClientSite
);
2400 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2401 TRACE("-- result 0x%08x\n", hres
);
2405 IOleObject_Release(pOleObject
);
2407 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2410 IRunnableObject
*pRunnable
;
2411 IOleCache
*pOleCache
;
2414 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2415 if (SUCCEEDED(hres2
))
2417 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2418 IRunnableObject_Release(pRunnable
);
2421 if (SUCCEEDED(hres
))
2423 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2424 if (SUCCEEDED(hres2
))
2427 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2428 IOleCache_Release(pOleCache
);
2433 if (FAILED(hres
) && pUnk
)
2435 IUnknown_Release(pUnk
);
2441 TRACE("-- %p\n", pUnk
);
2445 /******************************************************************************
2446 * OleGetAutoConvert [OLE32.@]
2448 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2450 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2452 WCHAR buf
[CHARS_IN_GUID
];
2456 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2461 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2463 res
= REGDB_E_KEYMISSING
;
2466 res
= CLSIDFromString(buf
, pClsidNew
);
2468 if (hkey
) RegCloseKey(hkey
);
2472 /******************************************************************************
2473 * OleSetAutoConvert [OLE32.@]
2475 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2477 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2479 WCHAR szClsidNew
[CHARS_IN_GUID
];
2482 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2484 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2487 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2488 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2490 res
= REGDB_E_WRITEREGDB
;
2495 if (hkey
) RegCloseKey(hkey
);
2499 /******************************************************************************
2500 * OleDoAutoConvert [OLE32.@]
2502 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2504 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2508 /******************************************************************************
2509 * OleIsRunning [OLE32.@]
2511 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2513 IRunnableObject
*pRunnable
;
2517 TRACE("(%p)\n", pObject
);
2519 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2522 running
= IRunnableObject_IsRunning(pRunnable
);
2523 IRunnableObject_Release(pRunnable
);
2527 /***********************************************************************
2528 * OleNoteObjectVisible [OLE32.@]
2530 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2532 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2533 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2537 /***********************************************************************
2538 * OLE_FreeClipDataArray [internal]
2541 * frees the data associated with an array of CLIPDATAs
2543 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2546 for (i
= 0; i
< count
; i
++)
2547 if (pClipDataArray
[i
].pClipData
)
2548 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2551 /***********************************************************************
2552 * PropSysAllocString [OLE32.@]
2554 * Basically a copy of SysAllocStringLen.
2556 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2560 WCHAR
* stringBuffer
;
2565 len
= lstrlenW(str
);
2567 * Find the length of the buffer passed-in, in bytes.
2569 bufferSize
= len
* sizeof (WCHAR
);
2572 * Allocate a new buffer to hold the string.
2573 * Don't forget to keep an empty spot at the beginning of the
2574 * buffer for the character count and an extra character at the
2577 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2578 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2581 * If the memory allocation failed, return a null pointer.
2587 * Copy the length of the string in the placeholder.
2589 *newBuffer
= bufferSize
;
2592 * Skip the byte count.
2596 memcpy(newBuffer
, str
, bufferSize
);
2599 * Make sure that there is a nul character at the end of the
2602 stringBuffer
= (WCHAR
*)newBuffer
;
2603 stringBuffer
[len
] = L
'\0';
2605 return (LPWSTR
)stringBuffer
;
2608 /***********************************************************************
2609 * PropSysFreeString [OLE32.@]
2611 * Copy of SysFreeString.
2613 void WINAPI
PropSysFreeString(LPOLESTR str
)
2615 DWORD
* bufferPointer
;
2617 /* NULL is a valid parameter */
2621 * We have to be careful when we free a BSTR pointer, it points to
2622 * the beginning of the string but it skips the byte count contained
2623 * before the string.
2625 bufferPointer
= (DWORD
*)str
;
2630 * Free the memory from its "real" origin.
2632 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2635 /******************************************************************************
2636 * Check if a PROPVARIANT's type is valid.
2638 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2664 case VT_STREAMED_OBJECT
:
2665 case VT_STORED_OBJECT
:
2666 case VT_BLOB_OBJECT
:
2669 case VT_I2
|VT_VECTOR
:
2670 case VT_I4
|VT_VECTOR
:
2671 case VT_R4
|VT_VECTOR
:
2672 case VT_R8
|VT_VECTOR
:
2673 case VT_CY
|VT_VECTOR
:
2674 case VT_DATE
|VT_VECTOR
:
2675 case VT_BSTR
|VT_VECTOR
:
2676 case VT_ERROR
|VT_VECTOR
:
2677 case VT_BOOL
|VT_VECTOR
:
2678 case VT_VARIANT
|VT_VECTOR
:
2679 case VT_UI1
|VT_VECTOR
:
2680 case VT_UI2
|VT_VECTOR
:
2681 case VT_UI4
|VT_VECTOR
:
2682 case VT_I8
|VT_VECTOR
:
2683 case VT_UI8
|VT_VECTOR
:
2684 case VT_LPSTR
|VT_VECTOR
:
2685 case VT_LPWSTR
|VT_VECTOR
:
2686 case VT_FILETIME
|VT_VECTOR
:
2687 case VT_CF
|VT_VECTOR
:
2688 case VT_CLSID
|VT_VECTOR
:
2691 WARN("Bad type %d\n", vt
);
2692 return STG_E_INVALIDPARAMETER
;
2695 /***********************************************************************
2696 * PropVariantClear [OLE32.@]
2698 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2702 TRACE("(%p)\n", pvar
);
2707 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2731 case VT_STREAMED_OBJECT
:
2733 case VT_STORED_OBJECT
:
2734 if (pvar
->u
.pStream
)
2735 IUnknown_Release(pvar
->u
.pStream
);
2740 /* pick an arbitary typed pointer - we don't care about the type
2741 * as we are just freeing it */
2742 CoTaskMemFree(pvar
->u
.puuid
);
2745 case VT_BLOB_OBJECT
:
2746 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2749 if (pvar
->u
.bstrVal
)
2750 PropSysFreeString(pvar
->u
.bstrVal
);
2753 if (pvar
->u
.pclipdata
)
2755 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2756 CoTaskMemFree(pvar
->u
.pclipdata
);
2760 if (pvar
->vt
& VT_VECTOR
)
2764 switch (pvar
->vt
& ~VT_VECTOR
)
2767 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2770 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2773 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2774 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2777 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2778 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2781 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2782 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2785 if (pvar
->vt
& ~VT_VECTOR
)
2787 /* pick an arbitary VT_VECTOR structure - they all have the same
2789 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2793 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2796 ZeroMemory(pvar
, sizeof(*pvar
));
2801 /***********************************************************************
2802 * PropVariantCopy [OLE32.@]
2804 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2805 const PROPVARIANT
*pvarSrc
) /* [in] */
2810 TRACE("(%p, %p)\n", pvarDest
, pvarSrc
);
2812 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2816 /* this will deal with most cases */
2817 CopyMemory(pvarDest
, pvarSrc
, sizeof(*pvarDest
));
2824 case VT_STREAMED_OBJECT
:
2826 case VT_STORED_OBJECT
:
2827 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2830 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2831 CopyMemory(pvarDest
->u
.puuid
, pvarSrc
->u
.puuid
, sizeof(CLSID
));
2834 len
= strlen(pvarSrc
->u
.pszVal
);
2835 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2836 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2839 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2840 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2841 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2844 case VT_BLOB_OBJECT
:
2845 if (pvarSrc
->u
.blob
.pBlobData
)
2847 len
= pvarSrc
->u
.blob
.cbSize
;
2848 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2849 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2853 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2856 if (pvarSrc
->u
.pclipdata
)
2858 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2859 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
2860 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
2861 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
2862 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2863 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2867 if (pvarSrc
->vt
& VT_VECTOR
)
2872 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2874 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2875 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2876 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
2877 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
2878 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
2879 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
2880 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
2881 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
2882 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
2883 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
2884 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
2885 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
2886 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
2887 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
2888 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
2889 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
2890 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
2891 case VT_BSTR
: elemSize
= sizeof(*pvarSrc
->u
.bstrVal
); break;
2892 case VT_LPSTR
: elemSize
= sizeof(*pvarSrc
->u
.pszVal
); break;
2893 case VT_LPWSTR
: elemSize
= sizeof(*pvarSrc
->u
.pwszVal
); break;
2897 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
2898 return E_INVALIDARG
;
2900 len
= pvarSrc
->u
.capropvar
.cElems
;
2901 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
2902 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
2904 for (i
= 0; i
< len
; i
++)
2905 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
2907 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
2909 FIXME("Copy clipformats\n");
2911 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
2913 for (i
= 0; i
< len
; i
++)
2914 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
2916 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
2919 for (i
= 0; i
< len
; i
++)
2921 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
2922 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2923 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2924 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2927 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
2930 for (i
= 0; i
< len
; i
++)
2932 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
2934 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2935 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2936 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2940 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
2943 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
2949 /***********************************************************************
2950 * FreePropVariantArray [OLE32.@]
2952 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
2953 PROPVARIANT
*rgvars
) /* [in/out] */
2957 TRACE("(%u, %p)\n", cVariants
, rgvars
);
2960 return E_INVALIDARG
;
2962 for(i
= 0; i
< cVariants
; i
++)
2963 PropVariantClear(&rgvars
[i
]);
2968 /******************************************************************************
2969 * DllDebugObjectRPCHook (OLE32.@)
2970 * turns on and off internal debugging, pointer is only used on macintosh
2973 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)