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
47 #include "wine/unicode.h"
48 #include "compobj_private.h"
49 #include "wine/list.h"
51 #include "wine/debug.h"
53 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
54 WINE_DECLARE_DEBUG_CHANNEL(accel
);
56 /******************************************************************************
57 * These are static/global variables and internal data structures that the
58 * OLE module uses to maintain it's state.
60 typedef struct tagDropTargetNode
63 IDropTarget
* dropTarget
;
67 typedef struct tagTrackerWindowInfo
69 IDataObject
* dataObject
;
70 IDropSource
* dropSource
;
77 HWND curTargetHWND
; /* window the mouse is hovering over */
78 HWND curDragTargetHWND
; /* might be a ancestor of curTargetHWND */
79 IDropTarget
* curDragTarget
;
80 POINTL curMousePos
; /* current position of the mouse in screen coordinates */
81 DWORD dwKeyState
; /* current state of the shift and ctrl keys and the mouse buttons */
84 typedef struct tagOleMenuDescriptor
/* OleMenuDescriptor */
86 HWND hwndFrame
; /* The containers frame window */
87 HWND hwndActiveObject
; /* The active objects window */
88 OLEMENUGROUPWIDTHS mgw
; /* OLE menu group widths for the shared menu */
89 HMENU hmenuCombined
; /* The combined menu */
90 BOOL bIsServerItem
; /* True if the currently open popup belongs to the server */
93 typedef struct tagOleMenuHookItem
/* OleMenu hook item in per thread hook list */
95 DWORD tid
; /* Thread Id */
96 HANDLE hHeap
; /* Heap this is allocated from */
97 HHOOK GetMsg_hHook
; /* message hook for WH_GETMESSAGE */
98 HHOOK CallWndProc_hHook
; /* message hook for WH_CALLWNDPROC */
99 struct tagOleMenuHookItem
*next
;
102 static OleMenuHookItem
*hook_list
;
105 * This is the lock count on the OLE library. It is controlled by the
106 * OLEInitialize/OLEUninitialize methods.
108 static LONG OLE_moduleLockCount
= 0;
111 * Name of our registered window class.
113 static const char OLEDD_DRAGTRACKERCLASS
[] = "WineDragDropTracker32";
116 * This is the head of the Drop target container.
118 static struct list targetListHead
= LIST_INIT(targetListHead
);
120 /******************************************************************************
121 * These are the prototypes of miscellaneous utility methods
123 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey
, DWORD
* pdwValue
);
125 /******************************************************************************
126 * These are the prototypes of the utility methods used to manage a shared menu
128 static void OLEMenu_Initialize(void);
129 static void OLEMenu_UnInitialize(void);
130 static BOOL
OLEMenu_InstallHooks( DWORD tid
);
131 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
132 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
133 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
134 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
135 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
136 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
);
138 /******************************************************************************
139 * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
141 extern void OLEClipbrd_UnInitialize(void);
142 extern void OLEClipbrd_Initialize(void);
144 /******************************************************************************
145 * These are the prototypes of the utility methods used for OLE Drag n Drop
147 static void OLEDD_Initialize(void);
148 static DropTargetNode
* OLEDD_FindDropTarget(
150 static void OLEDD_FreeDropTarget(DropTargetNode
*, BOOL
);
151 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
156 static void OLEDD_TrackMouseMove(
157 TrackerWindowInfo
* trackerInfo
);
158 static void OLEDD_TrackStateChange(
159 TrackerWindowInfo
* trackerInfo
);
160 static DWORD
OLEDD_GetButtonState(void);
163 /******************************************************************************
164 * OleBuildVersion [OLE2.1]
165 * OleBuildVersion [OLE32.@]
167 DWORD WINAPI
OleBuildVersion(void)
169 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
170 return (rmm
<<16)+rup
;
173 /***********************************************************************
174 * OleInitialize (OLE2.2)
175 * OleInitialize (OLE32.@)
177 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
181 TRACE("(%p)\n", reserved
);
184 * The first duty of the OleInitialize is to initialize the COM libraries.
186 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
189 * If the CoInitializeEx call failed, the OLE libraries can't be
196 * Then, it has to initialize the OLE specific modules.
200 * Object linking and Embedding
201 * In-place activation
203 if (!COM_CurrentInfo()->ole_inits
++ &&
204 InterlockedIncrement(&OLE_moduleLockCount
) == 1)
207 * Initialize the libraries.
209 TRACE("() - Initializing the OLE libraries\n");
214 OLEClipbrd_Initialize();
224 OLEMenu_Initialize();
230 /******************************************************************************
231 * OleUninitialize [OLE2.3]
232 * OleUninitialize [OLE32.@]
234 void WINAPI
OleUninitialize(void)
239 * If we hit the bottom of the lock stack, free the libraries.
241 if (!--COM_CurrentInfo()->ole_inits
&& !InterlockedDecrement(&OLE_moduleLockCount
))
244 * Actually free the libraries.
246 TRACE("() - Freeing the last reference count\n");
251 OLEClipbrd_UnInitialize();
256 OLEMenu_UnInitialize();
260 * Then, uninitialize the COM libraries.
265 /******************************************************************************
266 * OleInitializeWOW [OLE32.@]
268 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
269 FIXME("(0x%08x, 0x%08x),stub!\n",x
, y
);
273 /***********************************************************************
274 * RegisterDragDrop (OLE32.@)
276 HRESULT WINAPI
RegisterDragDrop(
278 LPDROPTARGET pDropTarget
)
280 DropTargetNode
* dropTargetInfo
;
282 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
284 if (!COM_CurrentApt())
286 ERR("COM not initialized\n");
287 return E_OUTOFMEMORY
;
295 ERR("invalid hwnd %p\n", hwnd
);
296 return DRAGDROP_E_INVALIDHWND
;
300 * First, check if the window is already registered.
302 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
304 if (dropTargetInfo
!=NULL
)
305 return DRAGDROP_E_ALREADYREGISTERED
;
308 * If it's not there, we can add it. We first create a node for it.
310 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
312 if (dropTargetInfo
==NULL
)
313 return E_OUTOFMEMORY
;
315 dropTargetInfo
->hwndTarget
= hwnd
;
318 * Don't forget that this is an interface pointer, need to nail it down since
319 * we keep a copy of it.
321 IDropTarget_AddRef(pDropTarget
);
322 dropTargetInfo
->dropTarget
= pDropTarget
;
324 list_add_tail(&targetListHead
, &dropTargetInfo
->entry
);
329 /***********************************************************************
330 * RevokeDragDrop (OLE32.@)
332 HRESULT WINAPI
RevokeDragDrop(
335 DropTargetNode
* dropTargetInfo
;
337 TRACE("(%p)\n", hwnd
);
341 ERR("invalid hwnd %p\n", hwnd
);
342 return DRAGDROP_E_INVALIDHWND
;
346 * First, check if the window is already registered.
348 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
351 * If it ain't in there, it's an error.
353 if (dropTargetInfo
==NULL
)
354 return DRAGDROP_E_NOTREGISTERED
;
356 OLEDD_FreeDropTarget(dropTargetInfo
, TRUE
);
361 /***********************************************************************
362 * OleRegGetUserType (OLE32.@)
364 * This implementation of OleRegGetUserType ignores the dwFormOfType
365 * parameter and always returns the full name of the object. This is
366 * not too bad since this is the case for many objects because of the
367 * way they are registered.
369 HRESULT WINAPI
OleRegGetUserType(
372 LPOLESTR
* pszUserType
)
382 * Initialize the out parameter.
387 * Build the key name we're looking for
389 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
390 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
391 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
392 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
394 TRACE("(%s, %d, %p)\n", keyName
, dwFormOfType
, pszUserType
);
397 * Open the class id Key
399 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
403 if (hres
!= ERROR_SUCCESS
)
404 return REGDB_E_CLASSNOTREG
;
407 * Retrieve the size of the name string.
411 hres
= RegQueryValueExA(clsidKey
,
418 if (hres
!=ERROR_SUCCESS
)
420 RegCloseKey(clsidKey
);
421 return REGDB_E_READREGDB
;
425 * Allocate a buffer for the registry value.
427 *pszUserType
= CoTaskMemAlloc(cbData
*2);
429 if (*pszUserType
==NULL
)
431 RegCloseKey(clsidKey
);
432 return E_OUTOFMEMORY
;
435 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
439 RegCloseKey(clsidKey
);
440 CoTaskMemFree(*pszUserType
);
442 return E_OUTOFMEMORY
;
445 hres
= RegQueryValueExA(clsidKey
,
452 RegCloseKey(clsidKey
);
455 if (hres
!=ERROR_SUCCESS
)
457 CoTaskMemFree(*pszUserType
);
460 retVal
= REGDB_E_READREGDB
;
464 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
467 HeapFree(GetProcessHeap(), 0, buffer
);
472 /***********************************************************************
473 * DoDragDrop [OLE32.@]
475 HRESULT WINAPI
DoDragDrop (
476 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
477 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
478 DWORD dwOKEffect
, /* [in] effects allowed by the source */
479 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
481 TrackerWindowInfo trackerInfo
;
482 HWND hwndTrackWindow
;
485 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
488 * Setup the drag n drop tracking window.
490 if (!IsValidInterface((LPUNKNOWN
)pDropSource
))
493 trackerInfo
.dataObject
= pDataObject
;
494 trackerInfo
.dropSource
= pDropSource
;
495 trackerInfo
.dwOKEffect
= dwOKEffect
;
496 trackerInfo
.pdwEffect
= pdwEffect
;
497 trackerInfo
.trackingDone
= FALSE
;
498 trackerInfo
.escPressed
= FALSE
;
499 trackerInfo
.curDragTargetHWND
= 0;
500 trackerInfo
.curTargetHWND
= 0;
501 trackerInfo
.curDragTarget
= 0;
503 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
506 CW_USEDEFAULT
, CW_USEDEFAULT
,
507 CW_USEDEFAULT
, CW_USEDEFAULT
,
511 (LPVOID
)&trackerInfo
);
513 if (hwndTrackWindow
!=0)
516 * Capture the mouse input
518 SetCapture(hwndTrackWindow
);
523 * Pump messages. All mouse input should go to the capture window.
525 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
527 trackerInfo
.curMousePos
.x
= msg
.pt
.x
;
528 trackerInfo
.curMousePos
.y
= msg
.pt
.y
;
529 trackerInfo
.dwKeyState
= OLEDD_GetButtonState();
531 if ( (msg
.message
>= WM_KEYFIRST
) &&
532 (msg
.message
<= WM_KEYLAST
) )
535 * When keyboard messages are sent to windows on this thread, we
536 * want to ignore notify the drop source that the state changed.
537 * in the case of the Escape key, we also notify the drop source
538 * we give it a special meaning.
540 if ( (msg
.message
==WM_KEYDOWN
) &&
541 (msg
.wParam
==VK_ESCAPE
) )
543 trackerInfo
.escPressed
= TRUE
;
547 * Notify the drop source.
549 OLEDD_TrackStateChange(&trackerInfo
);
554 * Dispatch the messages only when it's not a keyboard message.
556 DispatchMessageA(&msg
);
560 /* re-post the quit message to outer message loop */
561 if (msg
.message
== WM_QUIT
)
562 PostQuitMessage(msg
.wParam
);
564 * Destroy the temporary window.
566 DestroyWindow(hwndTrackWindow
);
568 return trackerInfo
.returnValue
;
574 /***********************************************************************
575 * OleQueryLinkFromData [OLE32.@]
577 HRESULT WINAPI
OleQueryLinkFromData(
578 IDataObject
* pSrcDataObject
)
580 FIXME("(%p),stub!\n", pSrcDataObject
);
584 /***********************************************************************
585 * OleRegGetMiscStatus [OLE32.@]
587 HRESULT WINAPI
OleRegGetMiscStatus(
599 * Initialize the out parameter.
604 * Build the key name we're looking for
606 sprintf( keyName
, "CLSID\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
607 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
608 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
609 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
611 TRACE("(%s, %d, %p)\n", keyName
, dwAspect
, pdwStatus
);
614 * Open the class id Key
616 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
620 if (result
!= ERROR_SUCCESS
)
621 return REGDB_E_CLASSNOTREG
;
626 result
= RegOpenKeyA(clsidKey
,
631 if (result
!= ERROR_SUCCESS
)
633 RegCloseKey(clsidKey
);
634 return REGDB_E_READREGDB
;
638 * Read the default value
640 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
643 * Open the key specific to the requested aspect.
645 sprintf(keyName
, "%d", dwAspect
);
647 result
= RegOpenKeyA(miscStatusKey
,
651 if (result
== ERROR_SUCCESS
)
653 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
654 RegCloseKey(aspectKey
);
660 RegCloseKey(miscStatusKey
);
661 RegCloseKey(clsidKey
);
666 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
670 const IEnumOLEVERBVtbl
*lpvtbl
;
677 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
678 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
680 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
681 if (IsEqualIID(riid
, &IID_IUnknown
) ||
682 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
684 IUnknown_AddRef(iface
);
688 return E_NOINTERFACE
;
691 static ULONG WINAPI
EnumOLEVERB_AddRef(
694 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
696 return InterlockedIncrement(&This
->ref
);
699 static ULONG WINAPI
EnumOLEVERB_Release(
702 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
703 LONG refs
= InterlockedDecrement(&This
->ref
);
707 RegCloseKey(This
->hkeyVerb
);
708 HeapFree(GetProcessHeap(), 0, This
);
713 static HRESULT WINAPI
EnumOLEVERB_Next(
714 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
717 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
720 TRACE("(%d, %p, %p)\n", celt
, rgelt
, pceltFetched
);
725 for (; celt
; celt
--, rgelt
++)
730 LPWSTR pwszMenuFlags
;
732 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
733 if (res
== ERROR_NO_MORE_ITEMS
)
738 else if (res
!= ERROR_SUCCESS
)
740 ERR("RegEnumKeyW failed with error %d\n", res
);
741 hr
= REGDB_E_READREGDB
;
744 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
745 if (res
!= ERROR_SUCCESS
)
747 ERR("RegQueryValueW failed with error %d\n", res
);
748 hr
= REGDB_E_READREGDB
;
751 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
757 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
758 if (res
!= ERROR_SUCCESS
)
760 ERR("RegQueryValueW failed with error %d\n", res
);
761 hr
= REGDB_E_READREGDB
;
762 CoTaskMemFree(pwszOLEVERB
);
766 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
767 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
770 hr
= OLEOBJ_E_INVALIDVERB
;
771 CoTaskMemFree(pwszOLEVERB
);
774 /* nul terminate the name string and advance to first character */
775 *pwszMenuFlags
= '\0';
777 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
780 hr
= OLEOBJ_E_INVALIDVERB
;
781 CoTaskMemFree(pwszOLEVERB
);
784 /* nul terminate the menu string and advance to first character */
788 /* fill out structure for this verb */
789 rgelt
->lVerb
= atolW(wszSubKey
);
790 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
791 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
792 rgelt
->grfAttribs
= atolW(pwszAttribs
);
801 static HRESULT WINAPI
EnumOLEVERB_Skip(
802 IEnumOLEVERB
*iface
, ULONG celt
)
804 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
806 TRACE("(%d)\n", celt
);
812 static HRESULT WINAPI
EnumOLEVERB_Reset(
815 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
823 static HRESULT WINAPI
EnumOLEVERB_Clone(
825 IEnumOLEVERB
**ppenum
)
827 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
829 TRACE("(%p)\n", ppenum
);
830 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
831 return HRESULT_FROM_WIN32(GetLastError());
832 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
835 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
837 EnumOLEVERB_QueryInterface
,
846 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
848 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
851 RegCloseKey(hkeyVerb
);
852 return E_OUTOFMEMORY
;
854 This
->lpvtbl
= &EnumOLEVERB_VTable
;
857 This
->hkeyVerb
= hkeyVerb
;
858 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
862 /***********************************************************************
863 * OleRegEnumVerbs [OLE32.@]
865 * Enumerates verbs associated with a class stored in the registry.
868 * clsid [I] Class ID to enumerate the verbs for.
869 * ppenum [O] Enumerator.
873 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
874 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
875 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
876 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
878 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
883 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
885 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
887 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
890 if (res
== REGDB_E_CLASSNOTREG
)
891 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
892 else if (res
== REGDB_E_KEYMISSING
)
893 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
895 ERR("failed to open Verbs key for CLSID %s with error %d\n",
896 debugstr_guid(clsid
), res
);
900 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
901 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
902 if (res
!= ERROR_SUCCESS
)
904 ERR("failed to get subkey count with error %d\n", GetLastError());
905 return REGDB_E_READREGDB
;
910 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
911 RegCloseKey(hkeyVerb
);
912 return OLEOBJ_E_NOVERBS
;
915 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
918 /******************************************************************************
919 * OleSetContainedObject [OLE32.@]
921 HRESULT WINAPI
OleSetContainedObject(
925 IRunnableObject
* runnable
= NULL
;
928 TRACE("(%p,%x)\n", pUnknown
, fContained
);
930 hres
= IUnknown_QueryInterface(pUnknown
,
931 &IID_IRunnableObject
,
936 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
938 IRunnableObject_Release(runnable
);
946 /******************************************************************************
949 * Set the OLE object to the running state.
952 * pUnknown [I] OLE object to run.
956 * Failure: Any HRESULT code.
958 HRESULT WINAPI
OleRun(LPUNKNOWN pUnknown
)
960 IRunnableObject
*runable
;
963 TRACE("(%p)\n", pUnknown
);
965 hres
= IUnknown_QueryInterface(pUnknown
, &IID_IRunnableObject
, (void**)&runable
);
967 return S_OK
; /* Appears to return no error. */
969 hres
= IRunnableObject_Run(runable
, NULL
);
970 IRunnableObject_Release(runable
);
974 /******************************************************************************
977 HRESULT WINAPI
OleLoad(
980 LPOLECLIENTSITE pClientSite
,
983 IPersistStorage
* persistStorage
= NULL
;
985 IOleObject
* pOleObject
= NULL
;
989 TRACE("(%p, %s, %p, %p)\n", pStg
, debugstr_guid(riid
), pClientSite
, ppvObj
);
994 * TODO, Conversion ... OleDoAutoConvert
998 * Get the class ID for the object.
1000 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
1003 * Now, try and create the handler for the object
1005 hres
= CoCreateInstance(&storageInfo
.clsid
,
1007 CLSCTX_INPROC_HANDLER
|CLSCTX_INPROC_SERVER
,
1012 * If that fails, as it will most times, load the default
1017 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
1024 * If we couldn't find a handler... this is bad. Abort the whole thing.
1031 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (void **)&pOleObject
);
1032 if (SUCCEEDED(hres
))
1035 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
1039 if (SUCCEEDED(hres
))
1041 * Initialize the object with it's IPersistStorage interface.
1043 hres
= IOleObject_QueryInterface(pUnk
,
1044 &IID_IPersistStorage
,
1045 (void**)&persistStorage
);
1047 if (SUCCEEDED(hres
))
1049 hres
= IPersistStorage_Load(persistStorage
, pStg
);
1051 IPersistStorage_Release(persistStorage
);
1052 persistStorage
= NULL
;
1055 if (SUCCEEDED(hres
) && pClientSite
)
1057 * Inform the new object of it's client site.
1059 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
1062 * Cleanup interfaces used internally
1065 IOleObject_Release(pOleObject
);
1067 if (SUCCEEDED(hres
))
1071 hres1
= IUnknown_QueryInterface(pUnk
, &IID_IOleLink
, (void **)&pOleLink
);
1072 if (SUCCEEDED(hres1
))
1074 FIXME("handle OLE link\n");
1075 IOleLink_Release(pOleLink
);
1081 IUnknown_Release(pUnk
);
1090 /***********************************************************************
1093 HRESULT WINAPI
OleSave(
1094 LPPERSISTSTORAGE pPS
,
1101 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1104 * First, we transfer the class ID (if available)
1106 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1108 if (SUCCEEDED(hres
))
1110 WriteClassStg(pStg
, &objectClass
);
1114 * Then, we ask the object to save itself to the
1115 * storage. If it is successful, we commit the storage.
1117 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1119 if (SUCCEEDED(hres
))
1121 IStorage_Commit(pStg
,
1129 /******************************************************************************
1130 * OleLockRunning [OLE32.@]
1132 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1134 IRunnableObject
* runnable
= NULL
;
1137 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1139 hres
= IUnknown_QueryInterface(pUnknown
,
1140 &IID_IRunnableObject
,
1143 if (SUCCEEDED(hres
))
1145 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1147 IRunnableObject_Release(runnable
);
1152 return E_INVALIDARG
;
1156 /**************************************************************************
1157 * Internal methods to manage the shared OLE menu in response to the
1158 * OLE***MenuDescriptor API
1162 * OLEMenu_Initialize()
1164 * Initializes the OLEMENU data structures.
1166 static void OLEMenu_Initialize(void)
1171 * OLEMenu_UnInitialize()
1173 * Releases the OLEMENU data structures.
1175 static void OLEMenu_UnInitialize(void)
1179 /*************************************************************************
1180 * OLEMenu_InstallHooks
1181 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1183 * RETURNS: TRUE if message hooks were successfully installed
1186 static BOOL
OLEMenu_InstallHooks( DWORD tid
)
1188 OleMenuHookItem
*pHookItem
= NULL
;
1190 /* Create an entry for the hook table */
1191 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1192 sizeof(OleMenuHookItem
)) ) )
1195 pHookItem
->tid
= tid
;
1196 pHookItem
->hHeap
= GetProcessHeap();
1198 /* Install a thread scope message hook for WH_GETMESSAGE */
1199 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1200 0, GetCurrentThreadId() );
1201 if ( !pHookItem
->GetMsg_hHook
)
1204 /* Install a thread scope message hook for WH_CALLWNDPROC */
1205 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1206 0, GetCurrentThreadId() );
1207 if ( !pHookItem
->CallWndProc_hHook
)
1210 /* Insert the hook table entry */
1211 pHookItem
->next
= hook_list
;
1212 hook_list
= pHookItem
;
1217 /* Unhook any hooks */
1218 if ( pHookItem
->GetMsg_hHook
)
1219 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1220 if ( pHookItem
->CallWndProc_hHook
)
1221 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1222 /* Release the hook table entry */
1223 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1228 /*************************************************************************
1229 * OLEMenu_UnInstallHooks
1230 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1232 * RETURNS: TRUE if message hooks were successfully installed
1235 static BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1237 OleMenuHookItem
*pHookItem
= NULL
;
1238 OleMenuHookItem
**ppHook
= &hook_list
;
1242 if ((*ppHook
)->tid
== tid
)
1244 pHookItem
= *ppHook
;
1245 *ppHook
= pHookItem
->next
;
1248 ppHook
= &(*ppHook
)->next
;
1250 if (!pHookItem
) return FALSE
;
1252 /* Uninstall the hooks installed for this thread */
1253 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1255 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1258 /* Release the hook table entry */
1259 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1264 /* Release the hook table entry */
1265 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1270 /*************************************************************************
1271 * OLEMenu_IsHookInstalled
1272 * Tests if OLEMenu hooks have been installed for a thread
1274 * RETURNS: The pointer and index of the hook table entry for the tid
1275 * NULL and -1 for the index if no hooks were installed for this thread
1277 static OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1279 OleMenuHookItem
*pHookItem
= NULL
;
1281 /* Do a simple linear search for an entry whose tid matches ours.
1282 * We really need a map but efficiency is not a concern here. */
1283 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1285 if ( tid
== pHookItem
->tid
)
1292 /***********************************************************************
1293 * OLEMenu_FindMainMenuIndex
1295 * Used by OLEMenu API to find the top level group a menu item belongs to.
1296 * On success pnPos contains the index of the item in the top level menu group
1298 * RETURNS: TRUE if the ID was found, FALSE on failure
1300 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1304 nItems
= GetMenuItemCount( hMainMenu
);
1306 for (i
= 0; i
< nItems
; i
++)
1310 /* Is the current item a submenu? */
1311 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1313 /* If the handle is the same we're done */
1314 if ( hsubmenu
== hPopupMenu
)
1320 /* Recursively search without updating pnPos */
1321 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1333 /***********************************************************************
1334 * OLEMenu_SetIsServerMenu
1336 * Checks whether a popup menu belongs to a shared menu group which is
1337 * owned by the server, and sets the menu descriptor state accordingly.
1338 * All menu messages from these groups should be routed to the server.
1340 * RETURNS: TRUE if the popup menu is part of a server owned group
1341 * FALSE if the popup menu is part of a container owned group
1343 static BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1345 UINT nPos
= 0, nWidth
, i
;
1347 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1349 /* Don't bother searching if the popup is the combined menu itself */
1350 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1353 /* Find the menu item index in the shared OLE menu that this item belongs to */
1354 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1357 /* The group widths array has counts for the number of elements
1358 * in the groups File, Edit, Container, Object, Window, Help.
1359 * The Edit, Object & Help groups belong to the server object
1360 * and the other three belong to the container.
1361 * Loop through the group widths and locate the group we are a member of.
1363 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1365 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1366 if ( nPos
< nWidth
)
1368 /* Odd elements are server menu widths */
1369 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1374 return pOleMenuDescriptor
->bIsServerItem
;
1377 /*************************************************************************
1378 * OLEMenu_CallWndProc
1379 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1380 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1382 static LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1384 LPCWPSTRUCT pMsg
= NULL
;
1385 HOLEMENU hOleMenu
= 0;
1386 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1387 OleMenuHookItem
*pHookItem
= NULL
;
1390 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1392 /* Check if we're being asked to process the message */
1393 if ( HC_ACTION
!= code
)
1396 /* Retrieve the current message being dispatched from lParam */
1397 pMsg
= (LPCWPSTRUCT
)lParam
;
1399 /* Check if the message is destined for a window we are interested in:
1400 * If the window has an OLEMenu property we may need to dispatch
1401 * the menu message to its active objects window instead. */
1403 hOleMenu
= GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1407 /* Get the menu descriptor */
1408 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1409 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1412 /* Process menu messages */
1413 switch( pMsg
->message
)
1417 /* Reset the menu descriptor state */
1418 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1420 /* Send this message to the server as well */
1421 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1422 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1426 case WM_INITMENUPOPUP
:
1428 /* Save the state for whether this is a server owned menu */
1429 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1435 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1436 if ( fuFlags
& MF_SYSMENU
)
1439 /* Save the state for whether this is a server owned popup menu */
1440 else if ( fuFlags
& MF_POPUP
)
1441 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1448 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1449 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1450 goto NEXTHOOK
; /* Not a menu message */
1459 /* If the message was for the server dispatch it accordingly */
1460 if ( pOleMenuDescriptor
->bIsServerItem
)
1462 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1463 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1467 if ( pOleMenuDescriptor
)
1468 GlobalUnlock( hOleMenu
);
1470 /* Lookup the hook item for the current thread */
1471 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1473 /* This should never fail!! */
1474 WARN("could not retrieve hHook for current thread!\n" );
1478 /* Pass on the message to the next hooker */
1479 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1482 /*************************************************************************
1483 * OLEMenu_GetMsgProc
1484 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1485 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1487 static LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1490 HOLEMENU hOleMenu
= 0;
1491 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1492 OleMenuHookItem
*pHookItem
= NULL
;
1495 TRACE("%i, %04lx, %08lx\n", code
, wParam
, lParam
);
1497 /* Check if we're being asked to process a messages */
1498 if ( HC_ACTION
!= code
)
1501 /* Retrieve the current message being dispatched from lParam */
1502 pMsg
= (LPMSG
)lParam
;
1504 /* Check if the message is destined for a window we are interested in:
1505 * If the window has an OLEMenu property we may need to dispatch
1506 * the menu message to its active objects window instead. */
1508 hOleMenu
= GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1512 /* Process menu messages */
1513 switch( pMsg
->message
)
1517 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1519 goto NEXTHOOK
; /* Not a menu message */
1526 /* Get the menu descriptor */
1527 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1528 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1531 /* If the message was for the server dispatch it accordingly */
1532 if ( pOleMenuDescriptor
->bIsServerItem
)
1534 /* Change the hWnd in the message to the active objects hWnd.
1535 * The message loop which reads this message will automatically
1536 * dispatch it to the embedded objects window. */
1537 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1541 if ( pOleMenuDescriptor
)
1542 GlobalUnlock( hOleMenu
);
1544 /* Lookup the hook item for the current thread */
1545 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1547 /* This should never fail!! */
1548 WARN("could not retrieve hHook for current thread!\n" );
1552 /* Pass on the message to the next hooker */
1553 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1556 /***********************************************************************
1557 * OleCreateMenuDescriptor [OLE32.@]
1558 * Creates an OLE menu descriptor for OLE to use when dispatching
1559 * menu messages and commands.
1562 * hmenuCombined - Handle to the objects combined menu
1563 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1566 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1567 HMENU hmenuCombined
,
1568 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1571 OleMenuDescriptor
*pOleMenuDescriptor
;
1574 if ( !hmenuCombined
|| !lpMenuWidths
)
1577 /* Create an OLE menu descriptor */
1578 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1579 sizeof(OleMenuDescriptor
) ) ) )
1582 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1583 if ( !pOleMenuDescriptor
)
1586 /* Initialize menu group widths and hmenu */
1587 for ( i
= 0; i
< 6; i
++ )
1588 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1590 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1591 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1592 GlobalUnlock( hOleMenu
);
1597 /***********************************************************************
1598 * OleDestroyMenuDescriptor [OLE32.@]
1599 * Destroy the shared menu descriptor
1601 HRESULT WINAPI
OleDestroyMenuDescriptor(
1602 HOLEMENU hmenuDescriptor
)
1604 if ( hmenuDescriptor
)
1605 GlobalFree( hmenuDescriptor
);
1609 /***********************************************************************
1610 * OleSetMenuDescriptor [OLE32.@]
1611 * Installs or removes OLE dispatching code for the containers frame window.
1614 * hOleMenu Handle to composite menu descriptor
1615 * hwndFrame Handle to containers frame window
1616 * hwndActiveObject Handle to objects in-place activation window
1617 * lpFrame Pointer to IOleInPlaceFrame on containers window
1618 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1621 * S_OK - menu installed correctly
1622 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1625 * The lpFrame and lpActiveObject parameters are currently ignored
1626 * OLE should install context sensitive help F1 filtering for the app when
1627 * these are non null.
1629 HRESULT WINAPI
OleSetMenuDescriptor(
1632 HWND hwndActiveObject
,
1633 LPOLEINPLACEFRAME lpFrame
,
1634 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1636 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1639 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1640 return E_INVALIDARG
;
1642 if ( lpFrame
|| lpActiveObject
)
1644 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1652 /* Set up a message hook to intercept the containers frame window messages.
1653 * The message filter is responsible for dispatching menu messages from the
1654 * shared menu which are intended for the object.
1657 if ( hOleMenu
) /* Want to install dispatching code */
1659 /* If OLEMenu hooks are already installed for this thread, fail
1660 * Note: This effectively means that OleSetMenuDescriptor cannot
1661 * be called twice in succession on the same frame window
1662 * without first calling it with a null hOleMenu to uninstall */
1663 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1666 /* Get the menu descriptor */
1667 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1668 if ( !pOleMenuDescriptor
)
1669 return E_UNEXPECTED
;
1671 /* Update the menu descriptor */
1672 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1673 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1675 GlobalUnlock( hOleMenu
);
1676 pOleMenuDescriptor
= NULL
;
1678 /* Add a menu descriptor windows property to the frame window */
1679 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1681 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1682 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1685 else /* Want to uninstall dispatching code */
1687 /* Uninstall the hooks */
1688 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1691 /* Remove the menu descriptor property from the frame window */
1692 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1698 /******************************************************************************
1699 * IsAccelerator [OLE32.@]
1700 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1702 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1707 if(!lpMsg
) return FALSE
;
1710 WARN_(accel
)("NULL accel handle\n");
1713 if((lpMsg
->message
!= WM_KEYDOWN
&&
1714 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1715 lpMsg
->message
!= WM_SYSCHAR
&&
1716 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1717 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1718 if (NULL
== lpAccelTbl
)
1722 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1724 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1725 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1729 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1730 "msg->hwnd=%p, msg->message=%04x, wParam=%08lx, lParam=%08lx\n",
1731 hAccel
, cAccelEntries
,
1732 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1733 for(i
= 0; i
< cAccelEntries
; i
++)
1735 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1738 if(lpMsg
->message
== WM_CHAR
)
1740 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1742 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", LOWORD(lpMsg
->wParam
) & 0xff);
1748 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1751 TRACE_(accel
)("found accel for virt_key %04lx (scan %04x)\n",
1752 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1753 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1754 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1755 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1756 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1757 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1761 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1763 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1764 { /* ^^ ALT pressed */
1765 TRACE_(accel
)("found accel for Alt-%c\n", LOWORD(lpMsg
->wParam
) & 0xff);
1773 WARN_(accel
)("couldn't translate accelerator key\n");
1774 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1778 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1779 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1783 /***********************************************************************
1784 * ReleaseStgMedium [OLE32.@]
1786 void WINAPI
ReleaseStgMedium(
1789 switch (pmedium
->tymed
)
1793 if ( (pmedium
->pUnkForRelease
==0) &&
1794 (pmedium
->u
.hGlobal
!=0) )
1795 GlobalFree(pmedium
->u
.hGlobal
);
1800 if (pmedium
->u
.lpszFileName
!=0)
1802 if (pmedium
->pUnkForRelease
==0)
1804 DeleteFileW(pmedium
->u
.lpszFileName
);
1807 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1813 if (pmedium
->u
.pstm
!=0)
1815 IStream_Release(pmedium
->u
.pstm
);
1819 case TYMED_ISTORAGE
:
1821 if (pmedium
->u
.pstg
!=0)
1823 IStorage_Release(pmedium
->u
.pstg
);
1829 if ( (pmedium
->pUnkForRelease
==0) &&
1830 (pmedium
->u
.hBitmap
!=0) )
1831 DeleteObject(pmedium
->u
.hBitmap
);
1836 if ( (pmedium
->pUnkForRelease
==0) &&
1837 (pmedium
->u
.hMetaFilePict
!=0) )
1839 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1840 DeleteMetaFile(pMP
->hMF
);
1841 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1842 GlobalFree(pmedium
->u
.hMetaFilePict
);
1848 if ( (pmedium
->pUnkForRelease
==0) &&
1849 (pmedium
->u
.hEnhMetaFile
!=0) )
1851 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1859 pmedium
->tymed
=TYMED_NULL
;
1862 * After cleaning up, the unknown is released
1864 if (pmedium
->pUnkForRelease
!=0)
1866 IUnknown_Release(pmedium
->pUnkForRelease
);
1867 pmedium
->pUnkForRelease
= 0;
1872 * OLEDD_Initialize()
1874 * Initializes the OLE drag and drop data structures.
1876 static void OLEDD_Initialize(void)
1880 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1881 wndClass
.style
= CS_GLOBALCLASS
;
1882 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1883 wndClass
.cbClsExtra
= 0;
1884 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1885 wndClass
.hCursor
= 0;
1886 wndClass
.hbrBackground
= 0;
1887 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1889 RegisterClassA (&wndClass
);
1893 * OLEDD_FreeDropTarget()
1895 * Frees the drag and drop data structure
1897 static void OLEDD_FreeDropTarget(DropTargetNode
*dropTargetInfo
, BOOL release_drop_target
)
1899 list_remove(&dropTargetInfo
->entry
);
1900 if (release_drop_target
) IDropTarget_Release(dropTargetInfo
->dropTarget
);
1901 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
1905 * OLEDD_UnInitialize()
1907 * Releases the OLE drag and drop data structures.
1909 void OLEDD_UnInitialize(void)
1912 * Simply empty the list.
1914 while (!list_empty(&targetListHead
))
1916 DropTargetNode
* curNode
= LIST_ENTRY(list_head(&targetListHead
), DropTargetNode
, entry
);
1917 OLEDD_FreeDropTarget(curNode
, FALSE
);
1922 * OLEDD_FindDropTarget()
1924 * Finds information about the drop target.
1926 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1928 DropTargetNode
* curNode
;
1931 * Iterate the list to find the HWND value.
1933 LIST_FOR_EACH_ENTRY(curNode
, &targetListHead
, DropTargetNode
, entry
)
1934 if (hwndOfTarget
==curNode
->hwndTarget
)
1938 * If we get here, the item is not in the list
1944 * OLEDD_DragTrackerWindowProc()
1946 * This method is the WindowProcedure of the drag n drop tracking
1947 * window. During a drag n Drop operation, an invisible window is created
1948 * to receive the user input and act upon it. This procedure is in charge
1952 #define DRAG_TIMER_ID 1
1954 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
1964 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
1966 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
1967 SetTimer(hwnd
, DRAG_TIMER_ID
, 50, NULL
);
1974 OLEDD_TrackMouseMove((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1980 case WM_LBUTTONDOWN
:
1981 case WM_MBUTTONDOWN
:
1982 case WM_RBUTTONDOWN
:
1984 OLEDD_TrackStateChange((TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0));
1989 KillTimer(hwnd
, DRAG_TIMER_ID
);
1995 * This is a window proc after all. Let's call the default.
1997 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
2001 * OLEDD_TrackMouseMove()
2003 * This method is invoked while a drag and drop operation is in effect.
2004 * it will generate the appropriate callbacks in the drop source
2005 * and drop target. It will also provide the expected feedback to
2009 * trackerInfo - Pointer to the structure identifying the
2010 * drag & drop operation that is currently
2013 static void OLEDD_TrackMouseMove(TrackerWindowInfo
* trackerInfo
)
2015 HWND hwndNewTarget
= 0;
2020 * Get the handle of the window under the mouse
2022 pt
.x
= trackerInfo
->curMousePos
.x
;
2023 pt
.y
= trackerInfo
->curMousePos
.y
;
2024 hwndNewTarget
= WindowFromPoint(pt
);
2027 * Every time, we re-initialize the effects passed to the
2028 * IDropTarget to the effects allowed by the source.
2030 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2033 * If we are hovering over the same target as before, send the
2034 * DragOver notification
2036 if ( (trackerInfo
->curDragTarget
!= 0) &&
2037 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2039 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2040 trackerInfo
->dwKeyState
,
2041 trackerInfo
->curMousePos
,
2042 trackerInfo
->pdwEffect
);
2046 DropTargetNode
* newDropTargetNode
= 0;
2049 * If we changed window, we have to notify our old target and check for
2052 if (trackerInfo
->curDragTarget
!=0)
2054 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2058 * Make sure we're hovering over a window.
2060 if (hwndNewTarget
!=0)
2063 * Find-out if there is a drag target under the mouse
2065 HWND nexttar
= hwndNewTarget
;
2066 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2069 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2070 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2071 if(nexttar
) hwndNewTarget
= nexttar
;
2073 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2074 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2077 * If there is, notify it that we just dragged-in
2079 if (trackerInfo
->curDragTarget
!=0)
2081 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2082 trackerInfo
->dataObject
,
2083 trackerInfo
->dwKeyState
,
2084 trackerInfo
->curMousePos
,
2085 trackerInfo
->pdwEffect
);
2091 * The mouse is not over a window so we don't track anything.
2093 trackerInfo
->curDragTargetHWND
= 0;
2094 trackerInfo
->curTargetHWND
= 0;
2095 trackerInfo
->curDragTarget
= 0;
2100 * Now that we have done that, we have to tell the source to give
2101 * us feedback on the work being done by the target. If we don't
2102 * have a target, simulate no effect.
2104 if (trackerInfo
->curDragTarget
==0)
2106 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2109 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2110 *trackerInfo
->pdwEffect
);
2113 * When we ask for feedback from the drop source, sometimes it will
2114 * do all the necessary work and sometimes it will not handle it
2115 * when that's the case, we must display the standard drag and drop
2118 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2120 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2122 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2124 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2126 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2128 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2130 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2134 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2140 * OLEDD_TrackStateChange()
2142 * This method is invoked while a drag and drop operation is in effect.
2143 * It is used to notify the drop target/drop source callbacks when
2144 * the state of the keyboard or mouse button change.
2147 * trackerInfo - Pointer to the structure identifying the
2148 * drag & drop operation that is currently
2151 static void OLEDD_TrackStateChange(TrackerWindowInfo
* trackerInfo
)
2154 * Ask the drop source what to do with the operation.
2156 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2157 trackerInfo
->dropSource
,
2158 trackerInfo
->escPressed
,
2159 trackerInfo
->dwKeyState
);
2162 * All the return valued will stop the operation except the S_OK
2165 if (trackerInfo
->returnValue
!=S_OK
)
2168 * Make sure the message loop in DoDragDrop stops
2170 trackerInfo
->trackingDone
= TRUE
;
2173 * Release the mouse in case the drop target decides to show a popup
2174 * or a menu or something.
2179 * If we end-up over a target, drop the object in the target or
2180 * inform the target that the operation was cancelled.
2182 if (trackerInfo
->curDragTarget
!=0)
2184 switch (trackerInfo
->returnValue
)
2187 * If the source wants us to complete the operation, we tell
2188 * the drop target that we just dropped the object in it.
2190 case DRAGDROP_S_DROP
:
2192 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2193 trackerInfo
->dataObject
,
2194 trackerInfo
->dwKeyState
,
2195 trackerInfo
->curMousePos
,
2196 trackerInfo
->pdwEffect
);
2200 * If the source told us that we should cancel, fool the drop
2201 * target by telling it that the mouse left it's window.
2202 * Also set the drop effect to "NONE" in case the application
2203 * ignores the result of DoDragDrop.
2205 case DRAGDROP_S_CANCEL
:
2206 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2207 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2215 * OLEDD_GetButtonState()
2217 * This method will use the current state of the keyboard to build
2218 * a button state mask equivalent to the one passed in the
2219 * WM_MOUSEMOVE wParam.
2221 static DWORD
OLEDD_GetButtonState(void)
2223 BYTE keyboardState
[256];
2226 GetKeyboardState(keyboardState
);
2228 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2229 keyMask
|= MK_SHIFT
;
2231 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2232 keyMask
|= MK_CONTROL
;
2234 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2235 keyMask
|= MK_LBUTTON
;
2237 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2238 keyMask
|= MK_RBUTTON
;
2240 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2241 keyMask
|= MK_MBUTTON
;
2247 * OLEDD_GetButtonState()
2249 * This method will read the default value of the registry key in
2250 * parameter and extract a DWORD value from it. The registry key value
2251 * can be in a string key or a DWORD key.
2254 * regKey - Key to read the default value from
2255 * pdwValue - Pointer to the location where the DWORD
2256 * value is returned. This value is not modified
2257 * if the value is not found.
2260 static void OLEUTL_ReadRegistryDWORDValue(
2269 lres
= RegQueryValueExA(regKey
,
2276 if (lres
==ERROR_SUCCESS
)
2281 *pdwValue
= *(DWORD
*)buffer
;
2286 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2292 /******************************************************************************
2295 * The operation of this function is documented literally in the WinAPI
2296 * documentation to involve a QueryInterface for the IViewObject interface,
2297 * followed by a call to IViewObject::Draw.
2299 HRESULT WINAPI
OleDraw(
2306 IViewObject
*viewobject
;
2308 hres
= IUnknown_QueryInterface(pUnk
,
2310 (void**)&viewobject
);
2312 if (SUCCEEDED(hres
))
2316 rectl
.left
= lprcBounds
->left
;
2317 rectl
.right
= lprcBounds
->right
;
2318 rectl
.top
= lprcBounds
->top
;
2319 rectl
.bottom
= lprcBounds
->bottom
;
2320 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2322 IViewObject_Release(viewobject
);
2327 return DV_E_NOIVIEWOBJECT
;
2331 /***********************************************************************
2332 * OleTranslateAccelerator [OLE32.@]
2334 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2335 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2339 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2341 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2342 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2347 /******************************************************************************
2348 * OleCreate [OLE32.@]
2351 HRESULT WINAPI
OleCreate(
2355 LPFORMATETC pFormatEtc
,
2356 LPOLECLIENTSITE pClientSite
,
2361 IUnknown
* pUnk
= NULL
;
2362 IOleObject
*pOleObject
= NULL
;
2364 TRACE("(%s, %s, %d, %p, %p, %p, %p)\n", debugstr_guid(rclsid
),
2365 debugstr_guid(riid
), renderopt
, pFormatEtc
, pClientSite
, pStg
, ppvObj
);
2367 hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
, riid
, (LPVOID
*)&pUnk
);
2369 if (SUCCEEDED(hres
))
2370 hres
= IStorage_SetClass(pStg
, rclsid
);
2372 if (pClientSite
&& SUCCEEDED(hres
))
2374 hres
= IUnknown_QueryInterface(pUnk
, &IID_IOleObject
, (LPVOID
*)&pOleObject
);
2375 if (SUCCEEDED(hres
))
2378 hres
= IOleObject_GetMiscStatus(pOleObject
, DVASPECT_CONTENT
, &dwStatus
);
2382 if (SUCCEEDED(hres
))
2384 IPersistStorage
* pPS
;
2385 if (SUCCEEDED((hres
= IUnknown_QueryInterface(pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2387 TRACE("trying to set stg %p\n", pStg
);
2388 hres
= IPersistStorage_InitNew(pPS
, pStg
);
2389 TRACE("-- result 0x%08x\n", hres
);
2390 IPersistStorage_Release(pPS
);
2394 if (pClientSite
&& SUCCEEDED(hres
))
2396 TRACE("trying to set clientsite %p\n", pClientSite
);
2397 hres
= IOleObject_SetClientSite(pOleObject
, pClientSite
);
2398 TRACE("-- result 0x%08x\n", hres
);
2402 IOleObject_Release(pOleObject
);
2404 if (((renderopt
== OLERENDER_DRAW
) || (renderopt
== OLERENDER_FORMAT
)) &&
2407 IRunnableObject
*pRunnable
;
2408 IOleCache
*pOleCache
;
2411 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IRunnableObject
, (void **)&pRunnable
);
2412 if (SUCCEEDED(hres2
))
2414 hres
= IRunnableObject_Run(pRunnable
, NULL
);
2415 IRunnableObject_Release(pRunnable
);
2418 if (SUCCEEDED(hres
))
2420 hres2
= IUnknown_QueryInterface(pUnk
, &IID_IOleCache
, (void **)&pOleCache
);
2421 if (SUCCEEDED(hres2
))
2424 hres
= IOleCache_Cache(pOleCache
, pFormatEtc
, ADVF_PRIMEFIRST
, &dwConnection
);
2425 IOleCache_Release(pOleCache
);
2430 if (FAILED(hres
) && pUnk
)
2432 IUnknown_Release(pUnk
);
2438 TRACE("-- %p\n", pUnk
);
2442 /******************************************************************************
2443 * OleGetAutoConvert [OLE32.@]
2445 HRESULT WINAPI
OleGetAutoConvert(REFCLSID clsidOld
, LPCLSID pClsidNew
)
2447 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2449 WCHAR buf
[CHARS_IN_GUID
];
2453 res
= COM_OpenKeyForCLSID(clsidOld
, wszAutoConvertTo
, KEY_READ
, &hkey
);
2458 if (RegQueryValueW(hkey
, NULL
, buf
, &len
))
2460 res
= REGDB_E_KEYMISSING
;
2463 res
= CLSIDFromString(buf
, pClsidNew
);
2465 if (hkey
) RegCloseKey(hkey
);
2469 /******************************************************************************
2470 * OleSetAutoConvert [OLE32.@]
2472 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2474 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2476 WCHAR szClsidNew
[CHARS_IN_GUID
];
2479 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2481 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2484 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2485 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2487 res
= REGDB_E_WRITEREGDB
;
2492 if (hkey
) RegCloseKey(hkey
);
2496 /******************************************************************************
2497 * OleDoAutoConvert [OLE32.@]
2499 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2501 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2505 /******************************************************************************
2506 * OleIsRunning [OLE32.@]
2508 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2510 IRunnableObject
*pRunnable
;
2514 TRACE("(%p)\n", pObject
);
2516 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2519 running
= IRunnableObject_IsRunning(pRunnable
);
2520 IRunnableObject_Release(pRunnable
);
2524 /***********************************************************************
2525 * OleNoteObjectVisible [OLE32.@]
2527 HRESULT WINAPI
OleNoteObjectVisible(LPUNKNOWN pUnknown
, BOOL bVisible
)
2529 TRACE("(%p, %s)\n", pUnknown
, bVisible
? "TRUE" : "FALSE");
2530 return CoLockObjectExternal(pUnknown
, bVisible
, TRUE
);
2534 /***********************************************************************
2535 * OLE_FreeClipDataArray [internal]
2538 * frees the data associated with an array of CLIPDATAs
2540 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2543 for (i
= 0; i
< count
; i
++)
2544 if (pClipDataArray
[i
].pClipData
)
2545 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2548 /***********************************************************************
2549 * PropSysAllocString [OLE32.@]
2551 * Basically a copy of SysAllocStringLen.
2553 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2557 WCHAR
* stringBuffer
;
2562 len
= lstrlenW(str
);
2564 * Find the length of the buffer passed-in, in bytes.
2566 bufferSize
= len
* sizeof (WCHAR
);
2569 * Allocate a new buffer to hold the string.
2570 * Don't forget to keep an empty spot at the beginning of the
2571 * buffer for the character count and an extra character at the
2574 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2575 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2578 * If the memory allocation failed, return a null pointer.
2584 * Copy the length of the string in the placeholder.
2586 *newBuffer
= bufferSize
;
2589 * Skip the byte count.
2593 memcpy(newBuffer
, str
, bufferSize
);
2596 * Make sure that there is a nul character at the end of the
2599 stringBuffer
= (WCHAR
*)newBuffer
;
2600 stringBuffer
[len
] = '\0';
2602 return (LPWSTR
)stringBuffer
;
2605 /***********************************************************************
2606 * PropSysFreeString [OLE32.@]
2608 * Copy of SysFreeString.
2610 void WINAPI
PropSysFreeString(LPOLESTR str
)
2612 DWORD
* bufferPointer
;
2614 /* NULL is a valid parameter */
2618 * We have to be careful when we free a BSTR pointer, it points to
2619 * the beginning of the string but it skips the byte count contained
2620 * before the string.
2622 bufferPointer
= (DWORD
*)str
;
2627 * Free the memory from its "real" origin.
2629 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2632 /******************************************************************************
2633 * Check if a PROPVARIANT's type is valid.
2635 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2661 case VT_STREAMED_OBJECT
:
2662 case VT_STORED_OBJECT
:
2663 case VT_BLOB_OBJECT
:
2666 case VT_I2
|VT_VECTOR
:
2667 case VT_I4
|VT_VECTOR
:
2668 case VT_R4
|VT_VECTOR
:
2669 case VT_R8
|VT_VECTOR
:
2670 case VT_CY
|VT_VECTOR
:
2671 case VT_DATE
|VT_VECTOR
:
2672 case VT_BSTR
|VT_VECTOR
:
2673 case VT_ERROR
|VT_VECTOR
:
2674 case VT_BOOL
|VT_VECTOR
:
2675 case VT_VARIANT
|VT_VECTOR
:
2676 case VT_UI1
|VT_VECTOR
:
2677 case VT_UI2
|VT_VECTOR
:
2678 case VT_UI4
|VT_VECTOR
:
2679 case VT_I8
|VT_VECTOR
:
2680 case VT_UI8
|VT_VECTOR
:
2681 case VT_LPSTR
|VT_VECTOR
:
2682 case VT_LPWSTR
|VT_VECTOR
:
2683 case VT_FILETIME
|VT_VECTOR
:
2684 case VT_CF
|VT_VECTOR
:
2685 case VT_CLSID
|VT_VECTOR
:
2688 WARN("Bad type %d\n", vt
);
2689 return STG_E_INVALIDPARAMETER
;
2692 /***********************************************************************
2693 * PropVariantClear [OLE32.@]
2695 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2699 TRACE("(%p)\n", pvar
);
2704 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2728 case VT_STREAMED_OBJECT
:
2730 case VT_STORED_OBJECT
:
2731 if (pvar
->u
.pStream
)
2732 IUnknown_Release(pvar
->u
.pStream
);
2737 /* pick an arbitrary typed pointer - we don't care about the type
2738 * as we are just freeing it */
2739 CoTaskMemFree(pvar
->u
.puuid
);
2742 case VT_BLOB_OBJECT
:
2743 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2746 if (pvar
->u
.bstrVal
)
2747 PropSysFreeString(pvar
->u
.bstrVal
);
2750 if (pvar
->u
.pclipdata
)
2752 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2753 CoTaskMemFree(pvar
->u
.pclipdata
);
2757 if (pvar
->vt
& VT_VECTOR
)
2761 switch (pvar
->vt
& ~VT_VECTOR
)
2764 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2767 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2770 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2771 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2774 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2775 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2778 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2779 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2782 if (pvar
->vt
& ~VT_VECTOR
)
2784 /* pick an arbitrary VT_VECTOR structure - they all have the same
2786 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2790 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2793 ZeroMemory(pvar
, sizeof(*pvar
));
2798 /***********************************************************************
2799 * PropVariantCopy [OLE32.@]
2801 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2802 const PROPVARIANT
*pvarSrc
) /* [in] */
2807 TRACE("(%p, %p)\n", pvarDest
, pvarSrc
);
2809 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2813 /* this will deal with most cases */
2814 *pvarDest
= *pvarSrc
;
2821 case VT_STREAMED_OBJECT
:
2823 case VT_STORED_OBJECT
:
2824 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2827 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2828 *pvarDest
->u
.puuid
= *pvarSrc
->u
.puuid
;
2831 len
= strlen(pvarSrc
->u
.pszVal
);
2832 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2833 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2836 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2837 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2838 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2841 case VT_BLOB_OBJECT
:
2842 if (pvarSrc
->u
.blob
.pBlobData
)
2844 len
= pvarSrc
->u
.blob
.cbSize
;
2845 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2846 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2850 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2853 if (pvarSrc
->u
.pclipdata
)
2855 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2856 pvarDest
->u
.pclipdata
= CoTaskMemAlloc(sizeof (CLIPDATA
));
2857 pvarDest
->u
.pclipdata
->cbSize
= pvarSrc
->u
.pclipdata
->cbSize
;
2858 pvarDest
->u
.pclipdata
->ulClipFmt
= pvarSrc
->u
.pclipdata
->ulClipFmt
;
2859 pvarDest
->u
.pclipdata
->pClipData
= CoTaskMemAlloc(len
);
2860 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2864 if (pvarSrc
->vt
& VT_VECTOR
)
2869 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2871 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2872 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2873 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
2874 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
2875 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
2876 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
2877 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
2878 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
2879 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
2880 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
2881 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
2882 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
2883 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
2884 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
2885 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
2886 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
2887 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
2888 case VT_BSTR
: elemSize
= sizeof(*pvarSrc
->u
.bstrVal
); break;
2889 case VT_LPSTR
: elemSize
= sizeof(*pvarSrc
->u
.pszVal
); break;
2890 case VT_LPWSTR
: elemSize
= sizeof(*pvarSrc
->u
.pwszVal
); break;
2891 case VT_VARIANT
: elemSize
= sizeof(*pvarSrc
->u
.pvarVal
); break;
2894 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
2895 return E_INVALIDARG
;
2897 len
= pvarSrc
->u
.capropvar
.cElems
;
2898 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
2899 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
2901 for (i
= 0; i
< len
; i
++)
2902 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
2904 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
2906 FIXME("Copy clipformats\n");
2908 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
2910 for (i
= 0; i
< len
; i
++)
2911 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
2913 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
2916 for (i
= 0; i
< len
; i
++)
2918 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
2919 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2920 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2921 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2924 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
2927 for (i
= 0; i
< len
; i
++)
2929 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
2931 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2932 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2933 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2937 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
2940 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
2946 /***********************************************************************
2947 * FreePropVariantArray [OLE32.@]
2949 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
2950 PROPVARIANT
*rgvars
) /* [in/out] */
2954 TRACE("(%u, %p)\n", cVariants
, rgvars
);
2957 return E_INVALIDARG
;
2959 for(i
= 0; i
< cVariants
; i
++)
2960 PropVariantClear(&rgvars
[i
]);
2965 /******************************************************************************
2966 * DllDebugObjectRPCHook (OLE32.@)
2967 * turns on and off internal debugging, pointer is only used on macintosh
2970 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)