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 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 (!COM_CurrentInfo()->ole_inits
++ &&
207 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
210 * Initialize the libraries.
212 TRACE("() - Initializing the OLE libraries\n");
217 OLEClipbrd_Initialize();
227 OLEMenu_Initialize();
233 /******************************************************************************
234 * OleUninitialize [OLE2.3]
235 * OleUninitialize [OLE32.@]
237 void WINAPI
OleUninitialize(void)
242 * If we hit the bottom of the lock stack, free the libraries.
244 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
247 * Actually free the libraries.
249 TRACE("() - Freeing the last reference count\n");
254 OLEClipbrd_UnInitialize();
259 OLEDD_UnInitialize();
264 OLEMenu_UnInitialize();
268 * Then, uninitialize the COM libraries.
273 /******************************************************************************
274 * OleInitializeWOW [OLE32.@]
276 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
277 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
281 /***********************************************************************
282 * RegisterDragDrop (OLE32.@)
284 HRESULT WINAPI
RegisterDragDrop(
286 LPDROPTARGET pDropTarget
)
288 DropTargetNode
* dropTargetInfo
;
290 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
296 * First, check if the window is already registered.
298 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
300 if (dropTargetInfo
!=NULL
)
301 return DRAGDROP_E_ALREADYREGISTERED
;
304 * If it's not there, we can add it. We first create a node for it.
306 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
308 if (dropTargetInfo
==NULL
)
309 return E_OUTOFMEMORY
;
311 dropTargetInfo
->hwndTarget
= hwnd
;
314 * Don't forget that this is an interface pointer, need to nail it down since
315 * we keep a copy of it.
317 IDropTarget_AddRef(pDropTarget
);
318 dropTargetInfo
->dropTarget
= pDropTarget
;
320 list_add_tail(&targetListHead
, &dropTargetInfo
->entry
);
325 /***********************************************************************
326 * RevokeDragDrop (OLE32.@)
328 HRESULT WINAPI
RevokeDragDrop(
331 DropTargetNode
* dropTargetInfo
;
333 TRACE("(%p)\n", hwnd
);
336 * First, check if the window is already registered.
338 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
341 * If it ain't in there, it's an error.
343 if (dropTargetInfo
==NULL
)
344 return DRAGDROP_E_NOTREGISTERED
;
346 OLEDD_FreeDropTarget(dropTargetInfo
);
351 /***********************************************************************
352 * OleRegGetUserType (OLE32.@)
354 * This implementation of OleRegGetUserType ignores the dwFormOfType
355 * parameter and always returns the full name of the object. This is
356 * not too bad since this is the case for many objects because of the
357 * way they are registered.
359 HRESULT WINAPI
OleRegGetUserType(
362 LPOLESTR
* pszUserType
)
372 * Initialize the out parameter.
377 * Build the key name we're looking for
379 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
380 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
381 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
382 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
384 TRACE("(%s, %d, %p)\n", keyName
, dwFormOfType
, pszUserType
);
387 * Open the class id Key
389 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
393 if (hres
!= ERROR_SUCCESS
)
394 return REGDB_E_CLASSNOTREG
;
397 * Retrieve the size of the name string.
401 hres
= RegQueryValueExA(clsidKey
,
408 if (hres
!=ERROR_SUCCESS
)
410 RegCloseKey(clsidKey
);
411 return REGDB_E_READREGDB
;
415 * Allocate a buffer for the registry value.
417 *pszUserType
= CoTaskMemAlloc(cbData
*2);
419 if (*pszUserType
==NULL
)
421 RegCloseKey(clsidKey
);
422 return E_OUTOFMEMORY
;
425 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
429 RegCloseKey(clsidKey
);
430 CoTaskMemFree(*pszUserType
);
432 return E_OUTOFMEMORY
;
435 hres
= RegQueryValueExA(clsidKey
,
442 RegCloseKey(clsidKey
);
445 if (hres
!=ERROR_SUCCESS
)
447 CoTaskMemFree(*pszUserType
);
450 retVal
= REGDB_E_READREGDB
;
454 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
457 HeapFree(GetProcessHeap(), 0, buffer
);
462 /***********************************************************************
463 * DoDragDrop [OLE32.@]
465 HRESULT WINAPI
DoDragDrop (
466 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
467 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
468 DWORD dwOKEffect
, /* [in] effects allowed by the source */
469 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
471 TrackerWindowInfo trackerInfo
;
472 HWND hwndTrackWindow
;
475 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
478 * Setup the drag n drop tracking window.
480 if (!IsValidInterface((LPUNKNOWN
)pDropSource
))
483 trackerInfo
.dataObject
= pDataObject
;
484 trackerInfo
.dropSource
= pDropSource
;
485 trackerInfo
.dwOKEffect
= dwOKEffect
;
486 trackerInfo
.pdwEffect
= pdwEffect
;
487 trackerInfo
.trackingDone
= FALSE
;
488 trackerInfo
.escPressed
= FALSE
;
489 trackerInfo
.curDragTargetHWND
= 0;
490 trackerInfo
.curTargetHWND
= 0;
491 trackerInfo
.curDragTarget
= 0;
493 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
496 CW_USEDEFAULT
, CW_USEDEFAULT
,
497 CW_USEDEFAULT
, CW_USEDEFAULT
,
501 (LPVOID
)&trackerInfo
);
503 if (hwndTrackWindow
!=0)
506 * Capture the mouse input
508 SetCapture(hwndTrackWindow
);
513 * Pump messages. All mouse input should go the the capture window.
515 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
517 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
518 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
519 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
521 if ( (msg
.message
>= WM_KEYFIRST
) &&
522 (msg
.message
<= WM_KEYLAST
) )
525 * When keyboard messages are sent to windows on this thread, we
526 * want to ignore notify the drop source that the state changed.
527 * in the case of the Escape key, we also notify the drop source
528 * we give it a special meaning.
530 if ( (msg
.message
==WM_KEYDOWN
) &&
531 (msg
.wParam
==VK_ESCAPE
) )
533 trackerInfo
.escPressed
= TRUE
;
537 * Notify the drop source.
539 OLEDD_TrackStateChange(&trackerInfo
);
544 * Dispatch the messages only when it's not a keyboard message.
546 DispatchMessageA(&msg
);
550 /* re-post the quit message to outer message loop */
551 if (msg
.message
== WM_QUIT
)
552 PostQuitMessage(msg
.wParam
);
554 * Destroy the temporary window.
556 DestroyWindow(hwndTrackWindow
);
558 return trackerInfo
.returnValue
;
564 /***********************************************************************
565 * OleQueryLinkFromData [OLE32.@]
567 HRESULT WINAPI
OleQueryLinkFromData(
568 IDataObject
* pSrcDataObject
)
570 FIXME("(%p),stub!\n", pSrcDataObject
);
574 /***********************************************************************
575 * OleRegGetMiscStatus [OLE32.@]
577 HRESULT WINAPI
OleRegGetMiscStatus(
589 * Initialize the out parameter.
594 * Build the key name we're looking for
596 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
597 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
598 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
599 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
601 TRACE("(%s, %d, %p)\n", keyName
, dwAspect
, pdwStatus
);
604 * Open the class id Key
606 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
610 if (result
!= ERROR_SUCCESS
)
611 return REGDB_E_CLASSNOTREG
;
616 result
= RegOpenKeyA(clsidKey
,
621 if (result
!= ERROR_SUCCESS
)
623 RegCloseKey(clsidKey
);
624 return REGDB_E_READREGDB
;
628 * Read the default value
630 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
633 * Open the key specific to the requested aspect.
635 sprintf(keyName
, "%d", dwAspect
);
637 result
= RegOpenKeyA(miscStatusKey
,
641 if (result
== ERROR_SUCCESS
)
643 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
644 RegCloseKey(aspectKey
);
650 RegCloseKey(miscStatusKey
);
651 RegCloseKey(clsidKey
);
656 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
660 const IEnumOLEVERBVtbl
*lpvtbl
;
667 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
668 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
670 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
671 if (IsEqualIID(riid
, &IID_IUnknown
) ||
672 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
674 IUnknown_AddRef(iface
);
678 return E_NOINTERFACE
;
681 static ULONG WINAPI
EnumOLEVERB_AddRef(
684 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
686 return InterlockedIncrement(&This
->ref
);
689 static ULONG WINAPI
EnumOLEVERB_Release(
692 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
693 LONG refs
= InterlockedDecrement(&This
->ref
);
697 RegCloseKey(This
->hkeyVerb
);
698 HeapFree(GetProcessHeap(), 0, This
);
703 static HRESULT WINAPI
EnumOLEVERB_Next(
704 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
707 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
710 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
715 for (; celt
; celt
--, rgelt
++)
720 LPWSTR pwszMenuFlags
;
722 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
723 if (res
== ERROR_NO_MORE_ITEMS
)
728 else if (res
!= ERROR_SUCCESS
)
730 ERR("RegEnumKeyW failed with error %d\n", res
);
731 hr
= REGDB_E_READREGDB
;
734 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
735 if (res
!= ERROR_SUCCESS
)
737 ERR("RegQueryValueW failed with error %d\n", res
);
738 hr
= REGDB_E_READREGDB
;
741 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
747 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
748 if (res
!= ERROR_SUCCESS
)
750 ERR("RegQueryValueW failed with error %d\n", res
);
751 hr
= REGDB_E_READREGDB
;
752 CoTaskMemFree(pwszOLEVERB
);
756 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
757 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
760 hr
= OLEOBJ_E_INVALIDVERB
;
761 CoTaskMemFree(pwszOLEVERB
);
764 /* nul terminate the name string and advance to first character */
765 *pwszMenuFlags
= '\0';
767 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
770 hr
= OLEOBJ_E_INVALIDVERB
;
771 CoTaskMemFree(pwszOLEVERB
);
774 /* nul terminate the menu string and advance to first character */
778 /* fill out structure for this verb */
779 rgelt
->lVerb
= atolW(wszSubKey
);
780 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
781 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
782 rgelt
->grfAttribs
= atolW(pwszAttribs
);
791 static HRESULT WINAPI
EnumOLEVERB_Skip(
792 IEnumOLEVERB
*iface
, ULONG celt
)
794 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
796 TRACE("(%d)\n", celt
);
802 static HRESULT WINAPI
EnumOLEVERB_Reset(
805 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
813 static HRESULT WINAPI
EnumOLEVERB_Clone(
815 IEnumOLEVERB
**ppenum
)
817 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
819 TRACE("(%p)\n", ppenum
);
820 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
821 return HRESULT_FROM_WIN32(GetLastError());
822 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
825 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
827 EnumOLEVERB_QueryInterface
,
836 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
838 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
841 RegCloseKey(hkeyVerb
);
842 return E_OUTOFMEMORY
;
844 This
->lpvtbl
= &EnumOLEVERB_VTable
;
847 This
->hkeyVerb
= hkeyVerb
;
848 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
852 /***********************************************************************
853 * OleRegEnumVerbs [OLE32.@]
855 * Enumerates verbs associated with a class stored in the registry.
858 * clsid [I] Class ID to enumerate the verbs for.
859 * ppenum [O] Enumerator.
863 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
864 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
865 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
866 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
868 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
873 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
875 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
877 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
880 if (res
== REGDB_E_CLASSNOTREG
)
881 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
882 else if (res
== REGDB_E_KEYMISSING
)
883 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
885 ERR("failed to open Verbs key for CLSID %s with error %d\n",
886 debugstr_guid(clsid
), res
);
890 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
891 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
892 if (res
!= ERROR_SUCCESS
)
894 ERR("failed to get subkey count with error %d\n", GetLastError());
895 return REGDB_E_READREGDB
;
900 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
901 RegCloseKey(hkeyVerb
);
902 return OLEOBJ_E_NOVERBS
;
905 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
908 /******************************************************************************
909 * OleSetContainedObject [OLE32.@]
911 HRESULT WINAPI
OleSetContainedObject(
915 IRunnableObject
* runnable
= NULL
;
918 TRACE("(%p,%x)\n", pUnknown
, fContained
);
920 hres
= IUnknown_QueryInterface(pUnknown
,
921 &IID_IRunnableObject
,
926 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
928 IRunnableObject_Release(runnable
);
936 /******************************************************************************
939 * Set the OLE object to the running state.
942 * pUnknown [I] OLE object to run.
946 * Failure: Any HRESULT code.
948 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
950 IRunnableObject
*runable
;
953 TRACE("(%p)\n", pUnknown
);
955 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
957 return S_OK
; /* Appears to return no error. */
959 hres
= IRunnableObject_Run(runable
, NULL
);
960 IRunnableObject_Release(runable
);
964 /******************************************************************************
967 HRESULT WINAPI
OleLoad(
970 LPOLECLIENTSITE pClientSite
,
973 IPersistStorage
* persistStorage
= NULL
;
975 IOleObject
* pOleObject
= NULL
;
979 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
984 * TODO, Conversion ... OleDoAutoConvert
988 * Get the class ID for the object.
990 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
993 * Now, try and create the handler for the object
995 hres
= CoCreateInstance(&storageInfo
.clsid
,
997 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1002 * If that fails, as it will most times, load the default
1007 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1014 * If we couldn't find a handler... this is bad. Abort the whole thing.
1021 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1022 if (SUCCEEDED(hres
))
1025 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1029 if (SUCCEEDED(hres
))
1031 * Initialize the object with it's IPersistStorage interface.
1033 hres
= IOleObject_QueryInterface(pUnk
,
1034 &IID_IPersistStorage
,
1035 (void**)&persistStorage
);
1037 if (SUCCEEDED(hres
))
1039 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1041 IPersistStorage_Release(persistStorage
);
1042 persistStorage
= NULL
;
1045 if (SUCCEEDED(hres
) && pClientSite
)
1047 * Inform the new object of it's client site.
1049 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1052 * Cleanup interfaces used internally
1055 IOleObject_Release(pOleObject
);
1057 if (SUCCEEDED(hres
))
1061 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1062 if (SUCCEEDED(hres1
))
1064 FIXME("handle OLE link\n");
1065 IOleLink_Release(pOleLink
);
1071 IUnknown_Release(pUnk
);
1080 /***********************************************************************
1083 HRESULT WINAPI
OleSave(
1084 LPPERSISTSTORAGE pPS
,
1091 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1094 * First, we transfer the class ID (if available)
1096 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1098 if (SUCCEEDED(hres
))
1100 WriteClassStg(pStg
, &objectClass
);
1104 * Then, we ask the object to save itself to the
1105 * storage. If it is successful, we commit the storage.
1107 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1109 if (SUCCEEDED(hres
))
1111 IStorage_Commit(pStg
,
1119 /******************************************************************************
1120 * OleLockRunning [OLE32.@]
1122 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1124 IRunnableObject
* runnable
= NULL
;
1127 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1129 hres
= IUnknown_QueryInterface(pUnknown
,
1130 &IID_IRunnableObject
,
1133 if (SUCCEEDED(hres
))
1135 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1137 IRunnableObject_Release(runnable
);
1142 return E_INVALIDARG
;
1146 /**************************************************************************
1147 * Internal methods to manage the shared OLE menu in response to the
1148 * OLE***MenuDescriptor API
1152 * OLEMenu_Initialize()
1154 * Initializes the OLEMENU data structures.
1156 static void OLEMenu_Initialize(void)
1161 * OLEMenu_UnInitialize()
1163 * Releases the OLEMENU data structures.
1165 static void OLEMenu_UnInitialize(void)
1169 /*************************************************************************
1170 * OLEMenu_InstallHooks
1171 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1173 * RETURNS: TRUE if message hooks were successfully installed
1176 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1178 OleMenuHookItem
*pHookItem
= NULL
;
1180 /* Create an entry for the hook table */
1181 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1182 sizeof(OleMenuHookItem
)) ) )
1185 pHookItem
->tid
= tid
;
1186 pHookItem
->hHeap
= GetProcessHeap();
1188 /* Install a thread scope message hook for WH_GETMESSAGE */
1189 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1190 0, GetCurrentThreadId() );
1191 if ( !pHookItem
->GetMsg_hHook
)
1194 /* Install a thread scope message hook for WH_CALLWNDPROC */
1195 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1196 0, GetCurrentThreadId() );
1197 if ( !pHookItem
->CallWndProc_hHook
)
1200 /* Insert the hook table entry */
1201 pHookItem
->next
= hook_list
;
1202 hook_list
= pHookItem
;
1207 /* Unhook any hooks */
1208 if ( pHookItem
->GetMsg_hHook
)
1209 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1210 if ( pHookItem
->CallWndProc_hHook
)
1211 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1212 /* Release the hook table entry */
1213 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1218 /*************************************************************************
1219 * OLEMenu_UnInstallHooks
1220 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1222 * RETURNS: TRUE if message hooks were successfully installed
1225 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1227 OleMenuHookItem
*pHookItem
= NULL
;
1228 OleMenuHookItem
**ppHook
= &hook_list
;
1232 if ((*ppHook
)->tid
== tid
)
1234 pHookItem
= *ppHook
;
1235 *ppHook
= pHookItem
->next
;
1238 ppHook
= &(*ppHook
)->next
;
1240 if (!pHookItem
) return FALSE
;
1242 /* Uninstall the hooks installed for this thread */
1243 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1245 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1248 /* Release the hook table entry */
1249 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1254 /* Release the hook table entry */
1255 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1260 /*************************************************************************
1261 * OLEMenu_IsHookInstalled
1262 * Tests if OLEMenu hooks have been installed for a thread
1264 * RETURNS: The pointer and index of the hook table entry for the tid
1265 * NULL and -1 for the index if no hooks were installed for this thread
1267 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1269 OleMenuHookItem
*pHookItem
= NULL
;
1271 /* Do a simple linear search for an entry whose tid matches ours.
1272 * We really need a map but efficiency is not a concern here. */
1273 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1275 if ( tid
== pHookItem
->tid
)
1282 /***********************************************************************
1283 * OLEMenu_FindMainMenuIndex
1285 * Used by OLEMenu API to find the top level group a menu item belongs to.
1286 * On success pnPos contains the index of the item in the top level menu group
1288 * RETURNS: TRUE if the ID was found, FALSE on failure
1290 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1294 nItems
= GetMenuItemCount( hMainMenu
);
1296 for (i
= 0; i
< nItems
; i
++)
1300 /* Is the current item a submenu? */
1301 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1303 /* If the handle is the same we're done */
1304 if ( hsubmenu
== hPopupMenu
)
1310 /* Recursively search without updating pnPos */
1311 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1323 /***********************************************************************
1324 * OLEMenu_SetIsServerMenu
1326 * Checks whether a popup menu belongs to a shared menu group which is
1327 * owned by the server, and sets the menu descriptor state accordingly.
1328 * All menu messages from these groups should be routed to the server.
1330 * RETURNS: TRUE if the popup menu is part of a server owned group
1331 * FALSE if the popup menu is part of a container owned group
1333 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1335 UINT nPos
= 0, nWidth
, i
;
1337 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1339 /* Don't bother searching if the popup is the combined menu itself */
1340 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1343 /* Find the menu item index in the shared OLE menu that this item belongs to */
1344 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1347 /* The group widths array has counts for the number of elements
1348 * in the groups File, Edit, Container, Object, Window, Help.
1349 * The Edit, Object & Help groups belong to the server object
1350 * and the other three belong to the container.
1351 * Loop through the group widths and locate the group we are a member of.
1353 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1355 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1356 if ( nPos
< nWidth
)
1358 /* Odd elements are server menu widths */
1359 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1364 return pOleMenuDescriptor
->bIsServerItem
;
1367 /*************************************************************************
1368 * OLEMenu_CallWndProc
1369 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1370 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1372 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1374 LPCWPSTRUCT pMsg
= NULL
;
1375 HOLEMENU hOleMenu
= 0;
1376 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1377 OleMenuHookItem
*pHookItem
= NULL
;
1380 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1382 /* Check if we're being asked to process the message */
1383 if ( HC_ACTION
!= code
)
1386 /* Retrieve the current message being dispatched from lParam */
1387 pMsg
= (LPCWPSTRUCT
)lParam
;
1389 /* Check if the message is destined for a window we are interested in:
1390 * If the window has an OLEMenu property we may need to dispatch
1391 * the menu message to its active objects window instead. */
1393 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1397 /* Get the menu descriptor */
1398 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1399 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1402 /* Process menu messages */
1403 switch( pMsg
->message
)
1407 /* Reset the menu descriptor state */
1408 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1410 /* Send this message to the server as well */
1411 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1412 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1416 case WM_INITMENUPOPUP
:
1418 /* Save the state for whether this is a server owned menu */
1419 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1425 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1426 if ( fuFlags
& MF_SYSMENU
)
1429 /* Save the state for whether this is a server owned popup menu */
1430 else if ( fuFlags
& MF_POPUP
)
1431 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1438 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1439 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1440 goto NEXTHOOK
; /* Not a menu message */
1449 /* If the message was for the server dispatch it accordingly */
1450 if ( pOleMenuDescriptor
->bIsServerItem
)
1452 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1453 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1457 if ( pOleMenuDescriptor
)
1458 GlobalUnlock( hOleMenu
);
1460 /* Lookup the hook item for the current thread */
1461 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1463 /* This should never fail!! */
1464 WARN("could not retrieve hHook for current thread!\n" );
1468 /* Pass on the message to the next hooker */
1469 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1472 /*************************************************************************
1473 * OLEMenu_GetMsgProc
1474 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1475 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1477 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1480 HOLEMENU hOleMenu
= 0;
1481 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1482 OleMenuHookItem
*pHookItem
= NULL
;
1485 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1487 /* Check if we're being asked to process a messages */
1488 if ( HC_ACTION
!= code
)
1491 /* Retrieve the current message being dispatched from lParam */
1492 pMsg
= (LPMSG
)lParam
;
1494 /* Check if the message is destined for a window we are interested in:
1495 * If the window has an OLEMenu property we may need to dispatch
1496 * the menu message to its active objects window instead. */
1498 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1502 /* Process menu messages */
1503 switch( pMsg
->message
)
1507 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1509 goto NEXTHOOK
; /* Not a menu message */
1516 /* Get the menu descriptor */
1517 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1518 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1521 /* If the message was for the server dispatch it accordingly */
1522 if ( pOleMenuDescriptor
->bIsServerItem
)
1524 /* Change the hWnd in the message to the active objects hWnd.
1525 * The message loop which reads this message will automatically
1526 * dispatch it to the embedded objects window. */
1527 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1531 if ( pOleMenuDescriptor
)
1532 GlobalUnlock( hOleMenu
);
1534 /* Lookup the hook item for the current thread */
1535 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1537 /* This should never fail!! */
1538 WARN("could not retrieve hHook for current thread!\n" );
1542 /* Pass on the message to the next hooker */
1543 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1546 /***********************************************************************
1547 * OleCreateMenuDescriptor [OLE32.@]
1548 * Creates an OLE menu descriptor for OLE to use when dispatching
1549 * menu messages and commands.
1552 * hmenuCombined - Handle to the objects combined menu
1553 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1556 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1557 HMENU hmenuCombined
,
1558 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1561 OleMenuDescriptor
*pOleMenuDescriptor
;
1564 if ( !hmenuCombined
|| !lpMenuWidths
)
1567 /* Create an OLE menu descriptor */
1568 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1569 sizeof(OleMenuDescriptor
) ) ) )
1572 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1573 if ( !pOleMenuDescriptor
)
1576 /* Initialize menu group widths and hmenu */
1577 for ( i
= 0; i
< 6; i
++ )
1578 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1580 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1581 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1582 GlobalUnlock( hOleMenu
);
1587 /***********************************************************************
1588 * OleDestroyMenuDescriptor [OLE32.@]
1589 * Destroy the shared menu descriptor
1591 HRESULT WINAPI
OleDestroyMenuDescriptor(
1592 HOLEMENU hmenuDescriptor
)
1594 if ( hmenuDescriptor
)
1595 GlobalFree( hmenuDescriptor
);
1599 /***********************************************************************
1600 * OleSetMenuDescriptor [OLE32.@]
1601 * Installs or removes OLE dispatching code for the containers frame window.
1604 * hOleMenu Handle to composite menu descriptor
1605 * hwndFrame Handle to containers frame window
1606 * hwndActiveObject Handle to objects in-place activation window
1607 * lpFrame Pointer to IOleInPlaceFrame on containers window
1608 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1611 * S_OK - menu installed correctly
1612 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1615 * The lpFrame and lpActiveObject parameters are currently ignored
1616 * OLE should install context sensitive help F1 filtering for the app when
1617 * these are non null.
1619 HRESULT WINAPI
OleSetMenuDescriptor(
1622 HWND hwndActiveObject
,
1623 LPOLEINPLACEFRAME lpFrame
,
1624 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1626 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1629 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1630 return E_INVALIDARG
;
1632 if ( lpFrame
|| lpActiveObject
)
1634 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1642 /* Set up a message hook to intercept the containers frame window messages.
1643 * The message filter is responsible for dispatching menu messages from the
1644 * shared menu which are intended for the object.
1647 if ( hOleMenu
) /* Want to install dispatching code */
1649 /* If OLEMenu hooks are already installed for this thread, fail
1650 * Note: This effectively means that OleSetMenuDescriptor cannot
1651 * be called twice in succession on the same frame window
1652 * without first calling it with a null hOleMenu to uninstall */
1653 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1656 /* Get the menu descriptor */
1657 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1658 if ( !pOleMenuDescriptor
)
1659 return E_UNEXPECTED
;
1661 /* Update the menu descriptor */
1662 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1663 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1665 GlobalUnlock( hOleMenu
);
1666 pOleMenuDescriptor
= NULL
;
1668 /* Add a menu descriptor windows property to the frame window */
1669 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1671 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1672 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1675 else /* Want to uninstall dispatching code */
1677 /* Uninstall the hooks */
1678 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1681 /* Remove the menu descriptor property from the frame window */
1682 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1688 /******************************************************************************
1689 * IsAccelerator [OLE32.@]
1690 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1692 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1697 if(!lpMsg
) return FALSE
;
1700 WARN_(accel
)("NULL accel handle\n");
1703 if((lpMsg
->message
!= WM_KEYDOWN
&&
1704 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1705 lpMsg
->message
!= WM_SYSCHAR
&&
1706 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1707 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1708 if (NULL
== lpAccelTbl
)
1712 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1714 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1715 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1719 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1720 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1721 hAccel
, cAccelEntries
,
1722 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1723 for(i
= 0; i
< cAccelEntries
; i
++)
1725 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1728 if(lpMsg
->message
== WM_CHAR
)
1730 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1732 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1738 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1741 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1742 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1743 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1744 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1745 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1746 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1747 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1751 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1753 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1754 { /* ^^ ALT pressed */
1755 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1763 WARN_(accel
)("couldn't translate accelerator key\n");
1764 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1768 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1769 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1773 /***********************************************************************
1774 * ReleaseStgMedium [OLE32.@]
1776 void WINAPI
ReleaseStgMedium(
1779 switch (pmedium
->tymed
)
1783 if ( (pmedium
->pUnkForRelease
==0) &&
1784 (pmedium
->u
.hGlobal
!=0) )
1785 GlobalFree(pmedium
->u
.hGlobal
);
1790 if (pmedium
->u
.lpszFileName
!=0)
1792 if (pmedium
->pUnkForRelease
==0)
1794 DeleteFileW(pmedium
->u
.lpszFileName
);
1797 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1803 if (pmedium
->u
.pstm
!=0)
1805 IStream_Release(pmedium
->u
.pstm
);
1809 case TYMED_ISTORAGE
:
1811 if (pmedium
->u
.pstg
!=0)
1813 IStorage_Release(pmedium
->u
.pstg
);
1819 if ( (pmedium
->pUnkForRelease
==0) &&
1820 (pmedium
->u
.hBitmap
!=0) )
1821 DeleteObject(pmedium
->u
.hBitmap
);
1826 if ( (pmedium
->pUnkForRelease
==0) &&
1827 (pmedium
->u
.hMetaFilePict
!=0) )
1829 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1830 DeleteMetaFile(pMP
->hMF
);
1831 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1832 GlobalFree(pmedium
->u
.hMetaFilePict
);
1838 if ( (pmedium
->pUnkForRelease
==0) &&
1839 (pmedium
->u
.hEnhMetaFile
!=0) )
1841 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1849 pmedium
->tymed
=TYMED_NULL
;
1852 * After cleaning up, the unknown is released
1854 if (pmedium
->pUnkForRelease
!=0)
1856 IUnknown_Release(pmedium
->pUnkForRelease
);
1857 pmedium
->pUnkForRelease
= 0;
1862 * OLEDD_Initialize()
1864 * Initializes the OLE drag and drop data structures.
1866 static void OLEDD_Initialize(void)
1870 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1871 wndClass
.style
= CS_GLOBALCLASS
;
1872 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1873 wndClass
.cbClsExtra
= 0;
1874 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1875 wndClass
.hCursor
= 0;
1876 wndClass
.hbrBackground
= 0;
1877 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1879 RegisterClassA (&wndClass
);
1883 * OLEDD_FreeDropTarget()
1885 * Frees the drag and drop data structure
1887 static void OLEDD_FreeDropTarget(DropTargetNode
*dropTargetInfo
)
1889 list_remove(&dropTargetInfo
->entry
);
1890 IDropTarget_Release(dropTargetInfo
->dropTarget
);
1891 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
1895 * OLEDD_UnInitialize()
1897 * Releases the OLE drag and drop data structures.
1899 static void OLEDD_UnInitialize(void)
1902 * Simply empty the list.
1904 while (!list_empty(&targetListHead
))
1906 DropTargetNode
* curNode
;
1907 curNode
= LIST_ENTRY(list_head(&targetListHead
), DropTargetNode
, entry
);
1908 OLEDD_FreeDropTarget(curNode
);
1913 * OLEDD_FindDropTarget()
1915 * Finds information about the drop target.
1917 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1919 DropTargetNode
* curNode
;
1922 * Iterate the list to find the HWND value.
1924 LIST_FOR_EACH_ENTRY(curNode
, &targetListHead
, DropTargetNode
, entry
)
1925 if (hwndOfTarget
==curNode
->hwndTarget
)
1929 * If we get here, the item is not in the list
1935 * OLEDD_DragTrackerWindowProc()
1937 * This method is the WindowProcedure of the drag n drop tracking
1938 * window. During a drag n Drop operation, an invisible window is created
1939 * to receive the user input and act upon it. This procedure is in charge
1943 #define DRAG_TIMER_ID 1
1945 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1955 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1957 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1958 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
1965 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1971 case WM_LBUTTONDOWN
:
1972 case WM_MBUTTONDOWN
:
1973 case WM_RBUTTONDOWN
:
1975 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1980 KillTimer(hwnd
, DRAG_TIMER_ID
);
1986 * This is a window proc after all. Let's call the default.
1988 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
1992 * OLEDD_TrackMouseMove()
1994 * This method is invoked while a drag and drop operation is in effect.
1995 * it will generate the appropriate callbacks in the drop source
1996 * and drop target. It will also provide the expected feedback to
2000 * trackerInfo - Pointer to the structure identifying the
2001 * drag & drop operation that is currently
2004 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2006 HWND hwndNewTarget
= 0;
2011 * Get the handle of the window under the mouse
2013 pt
.x
= trackerInfo
->curMousePos
.x
;
2014 pt
.y
= trackerInfo
->curMousePos
.y
;
2015 hwndNewTarget
= WindowFromPoint(pt
);
2018 * Every time, we re-initialize the effects passed to the
2019 * IDropTarget to the effects allowed by the source.
2021 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2024 * If we are hovering over the same target as before, send the
2025 * DragOver notification
2027 if ( (trackerInfo
->curDragTarget
!= 0) &&
2028 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2030 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2031 trackerInfo
->dwKeyState
,
2032 trackerInfo
->curMousePos
,
2033 trackerInfo
->pdwEffect
);
2037 DropTargetNode
* newDropTargetNode
= 0;
2040 * If we changed window, we have to notify our old target and check for
2043 if (trackerInfo
->curDragTarget
!=0)
2045 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2049 * Make sure we're hovering over a window.
2051 if (hwndNewTarget
!=0)
2054 * Find-out if there is a drag target under the mouse
2056 HWND nexttar
= hwndNewTarget
;
2057 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2060 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2061 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2062 if(nexttar
) hwndNewTarget
= nexttar
;
2064 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2065 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2068 * If there is, notify it that we just dragged-in
2070 if (trackerInfo
->curDragTarget
!=0)
2072 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2073 trackerInfo
->dataObject
,
2074 trackerInfo
->dwKeyState
,
2075 trackerInfo
->curMousePos
,
2076 trackerInfo
->pdwEffect
);
2082 * The mouse is not over a window so we don't track anything.
2084 trackerInfo
->curDragTargetHWND
= 0;
2085 trackerInfo
->curTargetHWND
= 0;
2086 trackerInfo
->curDragTarget
= 0;
2091 * Now that we have done that, we have to tell the source to give
2092 * us feedback on the work being done by the target. If we don't
2093 * have a target, simulate no effect.
2095 if (trackerInfo
->curDragTarget
==0)
2097 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2100 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2101 *trackerInfo
->pdwEffect
);
2104 * When we ask for feedback from the drop source, sometimes it will
2105 * do all the necessary work and sometimes it will not handle it
2106 * when that's the case, we must display the standard drag and drop
2109 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2111 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2113 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2115 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2117 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2119 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2121 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2125 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2131 * OLEDD_TrackStateChange()
2133 * This method is invoked while a drag and drop operation is in effect.
2134 * It is used to notify the drop target/drop source callbacks when
2135 * the state of the keyboard or mouse button change.
2138 * trackerInfo - Pointer to the structure identifying the
2139 * drag & drop operation that is currently
2142 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2145 * Ask the drop source what to do with the operation.
2147 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2148 trackerInfo
->dropSource
,
2149 trackerInfo
->escPressed
,
2150 trackerInfo
->dwKeyState
);
2153 * All the return valued will stop the operation except the S_OK
2156 if (trackerInfo
->returnValue
!=S_OK
)
2159 * Make sure the message loop in DoDragDrop stops
2161 trackerInfo
->trackingDone
= TRUE
;
2164 * Release the mouse in case the drop target decides to show a popup
2165 * or a menu or something.
2170 * If we end-up over a target, drop the object in the target or
2171 * inform the target that the operation was cancelled.
2173 if (trackerInfo
->curDragTarget
!=0)
2175 switch (trackerInfo
->returnValue
)
2178 * If the source wants us to complete the operation, we tell
2179 * the drop target that we just dropped the object in it.
2181 case DRAGDROP_S_DROP
:
2183 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2184 trackerInfo
->dataObject
,
2185 trackerInfo
->dwKeyState
,
2186 trackerInfo
->curMousePos
,
2187 trackerInfo
->pdwEffect
);
2191 * If the source told us that we should cancel, fool the drop
2192 * target by telling it that the mouse left it's window.
2193 * Also set the drop effect to "NONE" in case the application
2194 * ignores the result of DoDragDrop.
2196 case DRAGDROP_S_CANCEL
:
2197 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2198 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2206 * OLEDD_GetButtonState()
2208 * This method will use the current state of the keyboard to build
2209 * a button state mask equivalent to the one passed in the
2210 * WM_MOUSEMOVE wParam.
2212 static DWORD
OLEDD_GetButtonState(void)
2214 BYTE keyboardState
[256];
2217 GetKeyboardState(keyboardState
);
2219 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2220 keyMask
|= MK_SHIFT
;
2222 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2223 keyMask
|= MK_CONTROL
;
2225 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2226 keyMask
|= MK_LBUTTON
;
2228 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2229 keyMask
|= MK_RBUTTON
;
2231 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2232 keyMask
|= MK_MBUTTON
;
2238 * OLEDD_GetButtonState()
2240 * This method will read the default value of the registry key in
2241 * parameter and extract a DWORD value from it. The registry key value
2242 * can be in a string key or a DWORD key.
2245 * regKey - Key to read the default value from
2246 * pdwValue - Pointer to the location where the DWORD
2247 * value is returned. This value is not modified
2248 * if the value is not found.
2251 static void OLEUTL_ReadRegistryDWORDValue(
2260 lres
= RegQueryValueExA(regKey
,
2267 if (lres
==ERROR_SUCCESS
)
2272 *pdwValue
= *(DWORD
*)buffer
;
2277 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2283 /******************************************************************************
2286 * The operation of this function is documented literally in the WinAPI
2287 * documentation to involve a QueryInterface for the IViewObject interface,
2288 * followed by a call to IViewObject::Draw.
2290 HRESULT WINAPI
OleDraw(
2297 IViewObject
*viewobject
;
2299 hres
= IUnknown_QueryInterface(pUnk
,
2301 (void**)&viewobject
);
2303 if (SUCCEEDED(hres
))
2307 rectl
.left
= lprcBounds
->left
;
2308 rectl
.right
= lprcBounds
->right
;
2309 rectl
.top
= lprcBounds
->top
;
2310 rectl
.bottom
= lprcBounds
->bottom
;
2311 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2313 IViewObject_Release(viewobject
);
2318 return DV_E_NOIVIEWOBJECT
;
2322 /***********************************************************************
2323 * OleTranslateAccelerator [OLE32.@]
2325 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2326 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2330 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2332 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2333 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2338 /******************************************************************************
2339 * OleCreate [OLE32.@]
2342 HRESULT WINAPI
OleCreate(
2346 LPFORMATETC pFormatEtc
,
2347 LPOLECLIENTSITE pClientSite
,
2352 IUnknown
* pUnk
= NULL
;
2353 IOleObject
*pOleObject
= NULL
;
2355 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2356 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2358 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2361 * If that fails, as it will most times, load the default
2366 hres
= OleCreateDefaultHandler(rclsid
,
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
)