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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
49 #include "wine/unicode.h"
50 #include "compobj_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(ole
);
55 WINE_DECLARE_DEBUG_CHANNEL(accel
);
57 /******************************************************************************
58 * These are static/global variables and internal data structures that the
59 * OLE module uses to maintain it's state.
61 typedef struct tagDropTargetNode
64 IDropTarget
* dropTarget
;
65 struct tagDropTargetNode
* prevDropTarget
;
66 struct tagDropTargetNode
* nextDropTarget
;
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
;
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 ULONG 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 DropTargetNode
* targetListHead
= NULL
;
120 /******************************************************************************
121 * These are the prototypes of miscelaneous 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 BOOL
OLEMenu_InstallHooks( DWORD tid
);
131 BOOL
OLEMenu_UnInstallHooks( DWORD tid
);
132 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
);
133 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
);
134 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
);
135 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
);
136 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 void OLEDD_UnInitialize(void);
149 static void OLEDD_InsertDropTarget(
150 DropTargetNode
* nodeToAdd
);
151 static DropTargetNode
* OLEDD_ExtractDropTarget(
153 static DropTargetNode
* OLEDD_FindDropTarget(
155 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
160 static void OLEDD_TrackMouseMove(
161 TrackerWindowInfo
* trackerInfo
,
164 static void OLEDD_TrackStateChange(
165 TrackerWindowInfo
* trackerInfo
,
168 static DWORD
OLEDD_GetButtonState(void);
171 /******************************************************************************
172 * OleBuildVersion [OLE2.1]
173 * OleBuildVersion [OLE32.@]
175 DWORD WINAPI
OleBuildVersion(void)
177 TRACE("Returning version %d, build %d.\n", rmm
, rup
);
178 return (rmm
<<16)+rup
;
181 /***********************************************************************
182 * OleInitialize (OLE2.2)
183 * OleInitialize (OLE32.@)
185 HRESULT WINAPI
OleInitialize(LPVOID reserved
)
189 TRACE("(%p)\n", reserved
);
192 * The first duty of the OleInitialize is to initialize the COM libraries.
194 hr
= CoInitializeEx(NULL
, COINIT_APARTMENTTHREADED
);
197 * If the CoInitializeEx call failed, the OLE libraries can't be
204 * Then, it has to initialize the OLE specific modules.
208 * Object linking and Embedding
209 * In-place activation
211 if (OLE_moduleLockCount
==0)
214 * Initialize the libraries.
216 TRACE("() - Initializing the OLE libraries\n");
221 OLEClipbrd_Initialize();
231 OLEMenu_Initialize();
235 * Then, we increase the lock count on the OLE module.
237 OLE_moduleLockCount
++;
242 /******************************************************************************
243 * OleUninitialize [OLE2.3]
244 * OleUninitialize [OLE32.@]
246 void WINAPI
OleUninitialize(void)
251 * Decrease the lock count on the OLE module.
253 OLE_moduleLockCount
--;
256 * If we hit the bottom of the lock stack, free the libraries.
258 if (OLE_moduleLockCount
==0)
261 * Actually free the libraries.
263 TRACE("() - Freeing the last reference count\n");
268 OLEClipbrd_UnInitialize();
273 OLEDD_UnInitialize();
278 OLEMenu_UnInitialize();
282 * Then, uninitialize the COM libraries.
287 /******************************************************************************
288 * OleInitializeWOW [OLE32.@]
290 HRESULT WINAPI
OleInitializeWOW(DWORD x
, DWORD y
) {
291 FIXME("(0x%08lx, 0x%08lx),stub!\n",x
, y
);
295 /***********************************************************************
296 * RegisterDragDrop (OLE32.@)
298 HRESULT WINAPI
RegisterDragDrop(
300 LPDROPTARGET pDropTarget
)
302 DropTargetNode
* dropTargetInfo
;
304 TRACE("(%p,%p)\n", hwnd
, pDropTarget
);
310 * First, check if the window is already registered.
312 dropTargetInfo
= OLEDD_FindDropTarget(hwnd
);
314 if (dropTargetInfo
!=NULL
)
315 return DRAGDROP_E_ALREADYREGISTERED
;
318 * If it's not there, we can add it. We first create a node for it.
320 dropTargetInfo
= HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode
));
322 if (dropTargetInfo
==NULL
)
323 return E_OUTOFMEMORY
;
325 dropTargetInfo
->hwndTarget
= hwnd
;
326 dropTargetInfo
->prevDropTarget
= NULL
;
327 dropTargetInfo
->nextDropTarget
= NULL
;
330 * Don't forget that this is an interface pointer, need to nail it down since
331 * we keep a copy of it.
333 dropTargetInfo
->dropTarget
= pDropTarget
;
334 IDropTarget_AddRef(dropTargetInfo
->dropTarget
);
336 OLEDD_InsertDropTarget(dropTargetInfo
);
341 /***********************************************************************
342 * RevokeDragDrop (OLE32.@)
344 HRESULT WINAPI
RevokeDragDrop(
347 DropTargetNode
* dropTargetInfo
;
349 TRACE("(%p)\n", hwnd
);
352 * First, check if the window is already registered.
354 dropTargetInfo
= OLEDD_ExtractDropTarget(hwnd
);
357 * If it ain't in there, it's an error.
359 if (dropTargetInfo
==NULL
)
360 return DRAGDROP_E_NOTREGISTERED
;
363 * If it's in there, clean-up it's used memory and
366 IDropTarget_Release(dropTargetInfo
->dropTarget
);
367 HeapFree(GetProcessHeap(), 0, dropTargetInfo
);
372 /***********************************************************************
373 * OleRegGetUserType (OLE32.@)
375 * This implementation of OleRegGetUserType ignores the dwFormOfType
376 * parameter and always returns the full name of the object. This is
377 * not too bad since this is the case for many objects because of the
378 * way they are registered.
380 HRESULT WINAPI
OleRegGetUserType(
383 LPOLESTR
* pszUserType
)
393 * Initialize the out parameter.
398 * Build the key name we're looking for
400 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
401 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
402 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
403 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
405 TRACE("(%s, %ld, %p)\n", keyName
, dwFormOfType
, pszUserType
);
408 * Open the class id Key
410 hres
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
414 if (hres
!= ERROR_SUCCESS
)
415 return REGDB_E_CLASSNOTREG
;
418 * Retrieve the size of the name string.
422 hres
= RegQueryValueExA(clsidKey
,
429 if (hres
!=ERROR_SUCCESS
)
431 RegCloseKey(clsidKey
);
432 return REGDB_E_READREGDB
;
436 * Allocate a buffer for the registry value.
438 *pszUserType
= CoTaskMemAlloc(cbData
*2);
440 if (*pszUserType
==NULL
)
442 RegCloseKey(clsidKey
);
443 return E_OUTOFMEMORY
;
446 buffer
= HeapAlloc(GetProcessHeap(), 0, cbData
);
450 RegCloseKey(clsidKey
);
451 CoTaskMemFree(*pszUserType
);
453 return E_OUTOFMEMORY
;
456 hres
= RegQueryValueExA(clsidKey
,
463 RegCloseKey(clsidKey
);
466 if (hres
!=ERROR_SUCCESS
)
468 CoTaskMemFree(*pszUserType
);
471 retVal
= REGDB_E_READREGDB
;
475 MultiByteToWideChar( CP_ACP
, 0, buffer
, -1, *pszUserType
, cbData
/*FIXME*/ );
478 HeapFree(GetProcessHeap(), 0, buffer
);
483 /***********************************************************************
484 * DoDragDrop [OLE32.@]
486 HRESULT WINAPI
DoDragDrop (
487 IDataObject
*pDataObject
, /* [in] ptr to the data obj */
488 IDropSource
* pDropSource
, /* [in] ptr to the source obj */
489 DWORD dwOKEffect
, /* [in] effects allowed by the source */
490 DWORD
*pdwEffect
) /* [out] ptr to effects of the source */
492 TrackerWindowInfo trackerInfo
;
493 HWND hwndTrackWindow
;
496 TRACE("(DataObject %p, DropSource %p)\n", pDataObject
, pDropSource
);
499 * Setup the drag n drop tracking window.
501 if (!IsValidInterface((LPUNKNOWN
)pDropSource
))
504 trackerInfo
.dataObject
= pDataObject
;
505 trackerInfo
.dropSource
= pDropSource
;
506 trackerInfo
.dwOKEffect
= dwOKEffect
;
507 trackerInfo
.pdwEffect
= pdwEffect
;
508 trackerInfo
.trackingDone
= FALSE
;
509 trackerInfo
.escPressed
= FALSE
;
510 trackerInfo
.curDragTargetHWND
= 0;
511 trackerInfo
.curTargetHWND
= 0;
512 trackerInfo
.curDragTarget
= 0;
514 hwndTrackWindow
= CreateWindowA(OLEDD_DRAGTRACKERCLASS
,
517 CW_USEDEFAULT
, CW_USEDEFAULT
,
518 CW_USEDEFAULT
, CW_USEDEFAULT
,
522 (LPVOID
)&trackerInfo
);
524 if (hwndTrackWindow
!=0)
527 * Capture the mouse input
529 SetCapture(hwndTrackWindow
);
532 * Pump messages. All mouse input should go the the capture window.
534 while (!trackerInfo
.trackingDone
&& GetMessageA(&msg
, 0, 0, 0) )
536 if ( (msg
.message
>= WM_KEYFIRST
) &&
537 (msg
.message
<= WM_KEYLAST
) )
540 * When keyboard messages are sent to windows on this thread, we
541 * want to ignore notify the drop source that the state changed.
542 * in the case of the Escape key, we also notify the drop source
543 * we give it a special meaning.
545 if ( (msg
.message
==WM_KEYDOWN
) &&
546 (msg
.wParam
==VK_ESCAPE
) )
548 trackerInfo
.escPressed
= TRUE
;
552 * Notify the drop source.
554 OLEDD_TrackStateChange(&trackerInfo
,
556 OLEDD_GetButtonState());
561 * Dispatch the messages only when it's not a keyboard message.
563 DispatchMessageA(&msg
);
568 * Destroy the temporary window.
570 DestroyWindow(hwndTrackWindow
);
572 return trackerInfo
.returnValue
;
578 /***********************************************************************
579 * OleQueryLinkFromData [OLE32.@]
581 HRESULT WINAPI
OleQueryLinkFromData(
582 IDataObject
* pSrcDataObject
)
584 FIXME("(%p),stub!\n", pSrcDataObject
);
588 /***********************************************************************
589 * OleRegGetMiscStatus [OLE32.@]
591 HRESULT WINAPI
OleRegGetMiscStatus(
603 * Initialize the out parameter.
608 * Build the key name we're looking for
610 sprintf( keyName
, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
611 clsid
->Data1
, clsid
->Data2
, clsid
->Data3
,
612 clsid
->Data4
[0], clsid
->Data4
[1], clsid
->Data4
[2], clsid
->Data4
[3],
613 clsid
->Data4
[4], clsid
->Data4
[5], clsid
->Data4
[6], clsid
->Data4
[7] );
615 TRACE("(%s, %ld, %p)\n", keyName
, dwAspect
, pdwStatus
);
618 * Open the class id Key
620 result
= RegOpenKeyA(HKEY_CLASSES_ROOT
,
624 if (result
!= ERROR_SUCCESS
)
625 return REGDB_E_CLASSNOTREG
;
630 result
= RegOpenKeyA(clsidKey
,
635 if (result
!= ERROR_SUCCESS
)
637 RegCloseKey(clsidKey
);
638 return REGDB_E_READREGDB
;
642 * Read the default value
644 OLEUTL_ReadRegistryDWORDValue(miscStatusKey
, pdwStatus
);
647 * Open the key specific to the requested aspect.
649 sprintf(keyName
, "%ld", dwAspect
);
651 result
= RegOpenKeyA(miscStatusKey
,
655 if (result
== ERROR_SUCCESS
)
657 OLEUTL_ReadRegistryDWORDValue(aspectKey
, pdwStatus
);
658 RegCloseKey(aspectKey
);
664 RegCloseKey(miscStatusKey
);
665 RegCloseKey(clsidKey
);
670 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
);
674 const IEnumOLEVERBVtbl
*lpvtbl
;
681 static HRESULT WINAPI
EnumOLEVERB_QueryInterface(
682 IEnumOLEVERB
*iface
, REFIID riid
, void **ppv
)
684 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
685 if (IsEqualIID(riid
, &IID_IUnknown
) ||
686 IsEqualIID(riid
, &IID_IEnumOLEVERB
))
688 IUnknown_AddRef(iface
);
692 return E_NOINTERFACE
;
695 static ULONG WINAPI
EnumOLEVERB_AddRef(
698 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
700 return InterlockedIncrement(&This
->ref
);
703 static ULONG WINAPI
EnumOLEVERB_Release(
706 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
707 LONG refs
= InterlockedDecrement(&This
->ref
);
711 RegCloseKey(This
->hkeyVerb
);
712 HeapFree(GetProcessHeap(), 0, This
);
717 static HRESULT WINAPI
EnumOLEVERB_Next(
718 IEnumOLEVERB
*iface
, ULONG celt
, LPOLEVERB rgelt
,
721 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
724 TRACE("(%ld, %p, %p)\n", celt
, rgelt
, pceltFetched
);
729 for (; celt
; celt
--, rgelt
++)
734 LPWSTR pwszMenuFlags
;
736 LONG res
= RegEnumKeyW(This
->hkeyVerb
, This
->index
, wszSubKey
, sizeof(wszSubKey
)/sizeof(wszSubKey
[0]));
737 if (res
== ERROR_NO_MORE_ITEMS
)
742 else if (res
!= ERROR_SUCCESS
)
744 ERR("RegEnumKeyW failed with error %ld\n", res
);
745 hr
= REGDB_E_READREGDB
;
748 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, NULL
, &cbData
);
749 if (res
!= ERROR_SUCCESS
)
751 ERR("RegQueryValueW failed with error %ld\n", res
);
752 hr
= REGDB_E_READREGDB
;
755 pwszOLEVERB
= CoTaskMemAlloc(cbData
);
761 res
= RegQueryValueW(This
->hkeyVerb
, wszSubKey
, pwszOLEVERB
, &cbData
);
762 if (res
!= ERROR_SUCCESS
)
764 ERR("RegQueryValueW failed with error %ld\n", res
);
765 hr
= REGDB_E_READREGDB
;
766 CoTaskMemFree(pwszOLEVERB
);
770 TRACE("verb string: %s\n", debugstr_w(pwszOLEVERB
));
771 pwszMenuFlags
= strchrW(pwszOLEVERB
, ',');
774 hr
= OLEOBJ_E_INVALIDVERB
;
775 CoTaskMemFree(pwszOLEVERB
);
778 /* nul terminate the name string and advance to first character */
779 *pwszMenuFlags
= '\0';
781 pwszAttribs
= strchrW(pwszMenuFlags
, ',');
784 hr
= OLEOBJ_E_INVALIDVERB
;
785 CoTaskMemFree(pwszOLEVERB
);
788 /* nul terminate the menu string and advance to first character */
792 /* fill out structure for this verb */
793 rgelt
->lVerb
= atolW(wszSubKey
);
794 rgelt
->lpszVerbName
= pwszOLEVERB
; /* user should free */
795 rgelt
->fuFlags
= atolW(pwszMenuFlags
);
796 rgelt
->grfAttribs
= atolW(pwszAttribs
);
805 static HRESULT WINAPI
EnumOLEVERB_Skip(
806 IEnumOLEVERB
*iface
, ULONG celt
)
808 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
810 TRACE("(%ld)\n", celt
);
816 static HRESULT WINAPI
EnumOLEVERB_Reset(
819 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
827 static HRESULT WINAPI
EnumOLEVERB_Clone(
829 IEnumOLEVERB
**ppenum
)
831 EnumOLEVERB
*This
= (EnumOLEVERB
*)iface
;
833 TRACE("(%p)\n", ppenum
);
834 if (!DuplicateHandle(GetCurrentProcess(), This
->hkeyVerb
, GetCurrentProcess(), (HANDLE
*)&hkeyVerb
, 0, FALSE
, DUPLICATE_SAME_ACCESS
))
835 return HRESULT_FROM_WIN32(GetLastError());
836 return EnumOLEVERB_Construct(hkeyVerb
, This
->index
, ppenum
);
839 static const IEnumOLEVERBVtbl EnumOLEVERB_VTable
=
841 EnumOLEVERB_QueryInterface
,
850 static HRESULT
EnumOLEVERB_Construct(HKEY hkeyVerb
, ULONG index
, IEnumOLEVERB
**ppenum
)
852 EnumOLEVERB
*This
= HeapAlloc(GetProcessHeap(), 0, sizeof(*This
));
855 RegCloseKey(hkeyVerb
);
856 return E_OUTOFMEMORY
;
858 This
->lpvtbl
= &EnumOLEVERB_VTable
;
861 This
->hkeyVerb
= hkeyVerb
;
862 *ppenum
= (IEnumOLEVERB
*)&This
->lpvtbl
;
866 /***********************************************************************
867 * OleRegEnumVerbs [OLE32.@]
869 * Enumerates verbs associated with a class stored in the registry.
872 * clsid [I] Class ID to enumerate the verbs for.
873 * ppenum [O] Enumerator.
877 * REGDB_E_CLASSNOTREG: The specified class does not have a key in the registry.
878 * REGDB_E_READREGDB: The class key could not be opened for some other reason.
879 * OLE_E_REGDB_KEY: The Verb subkey for the class is not present.
880 * OLEOBJ_E_NOVERBS: The Verb subkey for the class is empty.
882 HRESULT WINAPI
OleRegEnumVerbs (REFCLSID clsid
, LPENUMOLEVERB
* ppenum
)
887 static const WCHAR wszVerb
[] = {'V','e','r','b',0};
889 TRACE("(%s, %p)\n", debugstr_guid(clsid
), ppenum
);
891 res
= COM_OpenKeyForCLSID(clsid
, wszVerb
, KEY_READ
, &hkeyVerb
);
894 if (res
== REGDB_E_CLASSNOTREG
)
895 ERR("CLSID %s not registered\n", debugstr_guid(clsid
));
896 else if (res
== REGDB_E_KEYMISSING
)
897 ERR("no Verbs key for class %s\n", debugstr_guid(clsid
));
899 ERR("failed to open Verbs key for CLSID %s with error %ld\n",
900 debugstr_guid(clsid
), res
);
904 res
= RegQueryInfoKeyW(hkeyVerb
, NULL
, NULL
, NULL
, &dwSubKeys
, NULL
,
905 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
906 if (res
!= ERROR_SUCCESS
)
908 ERR("failed to get subkey count with error %ld\n", GetLastError());
909 return REGDB_E_READREGDB
;
914 WARN("class %s has no verbs\n", debugstr_guid(clsid
));
915 RegCloseKey(hkeyVerb
);
916 return OLEOBJ_E_NOVERBS
;
919 return EnumOLEVERB_Construct(hkeyVerb
, 0, ppenum
);
922 /******************************************************************************
923 * OleSetContainedObject [OLE32.@]
925 HRESULT WINAPI
OleSetContainedObject(
929 IRunnableObject
* runnable
= NULL
;
932 TRACE("(%p,%x), stub!\n", pUnknown
, fContained
);
934 hres
= IUnknown_QueryInterface(pUnknown
,
935 &IID_IRunnableObject
,
940 hres
= IRunnableObject_SetContainedObject(runnable
, fContained
);
942 IRunnableObject_Release(runnable
);
950 /******************************************************************************
953 HRESULT WINAPI
OleLoad(
956 LPOLECLIENTSITE pClientSite
,
959 IPersistStorage
* persistStorage
= NULL
;
960 IOleObject
* oleObject
= NULL
;
964 TRACE("(%p,%p,%p,%p)\n", pStg
, riid
, pClientSite
, ppvObj
);
967 * TODO, Conversion ... OleDoAutoConvert
971 * Get the class ID for the object.
973 hres
= IStorage_Stat(pStg
, &storageInfo
, STATFLAG_NONAME
);
976 * Now, try and create the handler for the object
978 hres
= CoCreateInstance(&storageInfo
.clsid
,
980 CLSCTX_INPROC_HANDLER
,
985 * If that fails, as it will most times, load the default
990 hres
= OleCreateDefaultHandler(&storageInfo
.clsid
,
997 * If we couldn't find a handler... this is bad. Abort the whole thing.
1003 * Inform the new object of it's client site.
1005 hres
= IOleObject_SetClientSite(oleObject
, pClientSite
);
1008 * Initialize the object with it's IPersistStorage interface.
1010 hres
= IOleObject_QueryInterface(oleObject
,
1011 &IID_IPersistStorage
,
1012 (void**)&persistStorage
);
1014 if (SUCCEEDED(hres
))
1016 IPersistStorage_Load(persistStorage
, pStg
);
1018 IPersistStorage_Release(persistStorage
);
1019 persistStorage
= NULL
;
1023 * Return the requested interface to the caller.
1025 hres
= IOleObject_QueryInterface(oleObject
, riid
, ppvObj
);
1028 * Cleanup interfaces used internally
1030 IOleObject_Release(oleObject
);
1035 /***********************************************************************
1038 HRESULT WINAPI
OleSave(
1039 LPPERSISTSTORAGE pPS
,
1046 TRACE("(%p,%p,%x)\n", pPS
, pStg
, fSameAsLoad
);
1049 * First, we transfer the class ID (if available)
1051 hres
= IPersistStorage_GetClassID(pPS
, &objectClass
);
1053 if (SUCCEEDED(hres
))
1055 WriteClassStg(pStg
, &objectClass
);
1059 * Then, we ask the object to save itself to the
1060 * storage. If it is successful, we commit the storage.
1062 hres
= IPersistStorage_Save(pPS
, pStg
, fSameAsLoad
);
1064 if (SUCCEEDED(hres
))
1066 IStorage_Commit(pStg
,
1074 /******************************************************************************
1075 * OleLockRunning [OLE32.@]
1077 HRESULT WINAPI
OleLockRunning(LPUNKNOWN pUnknown
, BOOL fLock
, BOOL fLastUnlockCloses
)
1079 IRunnableObject
* runnable
= NULL
;
1082 TRACE("(%p,%x,%x)\n", pUnknown
, fLock
, fLastUnlockCloses
);
1084 hres
= IUnknown_QueryInterface(pUnknown
,
1085 &IID_IRunnableObject
,
1088 if (SUCCEEDED(hres
))
1090 hres
= IRunnableObject_LockRunning(runnable
, fLock
, fLastUnlockCloses
);
1092 IRunnableObject_Release(runnable
);
1097 return E_INVALIDARG
;
1101 /**************************************************************************
1102 * Internal methods to manage the shared OLE menu in response to the
1103 * OLE***MenuDescriptor API
1107 * OLEMenu_Initialize()
1109 * Initializes the OLEMENU data structures.
1111 static void OLEMenu_Initialize()
1116 * OLEMenu_UnInitialize()
1118 * Releases the OLEMENU data structures.
1120 static void OLEMenu_UnInitialize()
1124 /*************************************************************************
1125 * OLEMenu_InstallHooks
1126 * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1128 * RETURNS: TRUE if message hooks were successfully installed
1131 BOOL
OLEMenu_InstallHooks( DWORD tid
)
1133 OleMenuHookItem
*pHookItem
= NULL
;
1135 /* Create an entry for the hook table */
1136 if ( !(pHookItem
= HeapAlloc(GetProcessHeap(), 0,
1137 sizeof(OleMenuHookItem
)) ) )
1140 pHookItem
->tid
= tid
;
1141 pHookItem
->hHeap
= GetProcessHeap();
1143 /* Install a thread scope message hook for WH_GETMESSAGE */
1144 pHookItem
->GetMsg_hHook
= SetWindowsHookExA( WH_GETMESSAGE
, OLEMenu_GetMsgProc
,
1145 0, GetCurrentThreadId() );
1146 if ( !pHookItem
->GetMsg_hHook
)
1149 /* Install a thread scope message hook for WH_CALLWNDPROC */
1150 pHookItem
->CallWndProc_hHook
= SetWindowsHookExA( WH_CALLWNDPROC
, OLEMenu_CallWndProc
,
1151 0, GetCurrentThreadId() );
1152 if ( !pHookItem
->CallWndProc_hHook
)
1155 /* Insert the hook table entry */
1156 pHookItem
->next
= hook_list
;
1157 hook_list
= pHookItem
;
1162 /* Unhook any hooks */
1163 if ( pHookItem
->GetMsg_hHook
)
1164 UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
);
1165 if ( pHookItem
->CallWndProc_hHook
)
1166 UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
);
1167 /* Release the hook table entry */
1168 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1173 /*************************************************************************
1174 * OLEMenu_UnInstallHooks
1175 * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
1177 * RETURNS: TRUE if message hooks were successfully installed
1180 BOOL
OLEMenu_UnInstallHooks( DWORD tid
)
1182 OleMenuHookItem
*pHookItem
= NULL
;
1183 OleMenuHookItem
**ppHook
= &hook_list
;
1187 if ((*ppHook
)->tid
== tid
)
1189 pHookItem
= *ppHook
;
1190 *ppHook
= pHookItem
->next
;
1193 ppHook
= &(*ppHook
)->next
;
1195 if (!pHookItem
) return FALSE
;
1197 /* Uninstall the hooks installed for this thread */
1198 if ( !UnhookWindowsHookEx( pHookItem
->GetMsg_hHook
) )
1200 if ( !UnhookWindowsHookEx( pHookItem
->CallWndProc_hHook
) )
1203 /* Release the hook table entry */
1204 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1209 /* Release the hook table entry */
1210 HeapFree(pHookItem
->hHeap
, 0, pHookItem
);
1215 /*************************************************************************
1216 * OLEMenu_IsHookInstalled
1217 * Tests if OLEMenu hooks have been installed for a thread
1219 * RETURNS: The pointer and index of the hook table entry for the tid
1220 * NULL and -1 for the index if no hooks were installed for this thread
1222 OleMenuHookItem
* OLEMenu_IsHookInstalled( DWORD tid
)
1224 OleMenuHookItem
*pHookItem
= NULL
;
1226 /* Do a simple linear search for an entry whose tid matches ours.
1227 * We really need a map but efficiency is not a concern here. */
1228 for (pHookItem
= hook_list
; pHookItem
; pHookItem
= pHookItem
->next
)
1230 if ( tid
== pHookItem
->tid
)
1237 /***********************************************************************
1238 * OLEMenu_FindMainMenuIndex
1240 * Used by OLEMenu API to find the top level group a menu item belongs to.
1241 * On success pnPos contains the index of the item in the top level menu group
1243 * RETURNS: TRUE if the ID was found, FALSE on failure
1245 static BOOL
OLEMenu_FindMainMenuIndex( HMENU hMainMenu
, HMENU hPopupMenu
, UINT
*pnPos
)
1249 nItems
= GetMenuItemCount( hMainMenu
);
1251 for (i
= 0; i
< nItems
; i
++)
1255 /* Is the current item a submenu? */
1256 if ( (hsubmenu
= GetSubMenu(hMainMenu
, i
)) )
1258 /* If the handle is the same we're done */
1259 if ( hsubmenu
== hPopupMenu
)
1265 /* Recursively search without updating pnPos */
1266 else if ( OLEMenu_FindMainMenuIndex( hsubmenu
, hPopupMenu
, NULL
) )
1278 /***********************************************************************
1279 * OLEMenu_SetIsServerMenu
1281 * Checks whether a popup menu belongs to a shared menu group which is
1282 * owned by the server, and sets the menu descriptor state accordingly.
1283 * All menu messages from these groups should be routed to the server.
1285 * RETURNS: TRUE if the popup menu is part of a server owned group
1286 * FALSE if the popup menu is part of a container owned group
1288 BOOL
OLEMenu_SetIsServerMenu( HMENU hmenu
, OleMenuDescriptor
*pOleMenuDescriptor
)
1290 UINT nPos
= 0, nWidth
, i
;
1292 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1294 /* Don't bother searching if the popup is the combined menu itself */
1295 if ( hmenu
== pOleMenuDescriptor
->hmenuCombined
)
1298 /* Find the menu item index in the shared OLE menu that this item belongs to */
1299 if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor
->hmenuCombined
, hmenu
, &nPos
) )
1302 /* The group widths array has counts for the number of elements
1303 * in the groups File, Edit, Container, Object, Window, Help.
1304 * The Edit, Object & Help groups belong to the server object
1305 * and the other three belong to the container.
1306 * Loop through the group widths and locate the group we are a member of.
1308 for ( i
= 0, nWidth
= 0; i
< 6; i
++ )
1310 nWidth
+= pOleMenuDescriptor
->mgw
.width
[i
];
1311 if ( nPos
< nWidth
)
1313 /* Odd elements are server menu widths */
1314 pOleMenuDescriptor
->bIsServerItem
= (i
%2) ? TRUE
: FALSE
;
1319 return pOleMenuDescriptor
->bIsServerItem
;
1322 /*************************************************************************
1323 * OLEMenu_CallWndProc
1324 * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1325 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1327 LRESULT CALLBACK
OLEMenu_CallWndProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1329 LPCWPSTRUCT pMsg
= NULL
;
1330 HOLEMENU hOleMenu
= 0;
1331 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1332 OleMenuHookItem
*pHookItem
= NULL
;
1335 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1337 /* Check if we're being asked to process the message */
1338 if ( HC_ACTION
!= code
)
1341 /* Retrieve the current message being dispatched from lParam */
1342 pMsg
= (LPCWPSTRUCT
)lParam
;
1344 /* Check if the message is destined for a window we are interested in:
1345 * If the window has an OLEMenu property we may need to dispatch
1346 * the menu message to its active objects window instead. */
1348 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1352 /* Get the menu descriptor */
1353 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1354 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1357 /* Process menu messages */
1358 switch( pMsg
->message
)
1362 /* Reset the menu descriptor state */
1363 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1365 /* Send this message to the server as well */
1366 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1367 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1371 case WM_INITMENUPOPUP
:
1373 /* Save the state for whether this is a server owned menu */
1374 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->wParam
, pOleMenuDescriptor
);
1380 fuFlags
= HIWORD(pMsg
->wParam
); /* Get flags */
1381 if ( fuFlags
& MF_SYSMENU
)
1384 /* Save the state for whether this is a server owned popup menu */
1385 else if ( fuFlags
& MF_POPUP
)
1386 OLEMenu_SetIsServerMenu( (HMENU
)pMsg
->lParam
, pOleMenuDescriptor
);
1393 LPDRAWITEMSTRUCT lpdis
= (LPDRAWITEMSTRUCT
) pMsg
->lParam
;
1394 if ( pMsg
->wParam
!= 0 || lpdis
->CtlType
!= ODT_MENU
)
1395 goto NEXTHOOK
; /* Not a menu message */
1404 /* If the message was for the server dispatch it accordingly */
1405 if ( pOleMenuDescriptor
->bIsServerItem
)
1407 SendMessageA( pOleMenuDescriptor
->hwndActiveObject
,
1408 pMsg
->message
, pMsg
->wParam
, pMsg
->lParam
);
1412 if ( pOleMenuDescriptor
)
1413 GlobalUnlock( hOleMenu
);
1415 /* Lookup the hook item for the current thread */
1416 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1418 /* This should never fail!! */
1419 WARN("could not retrieve hHook for current thread!\n" );
1423 /* Pass on the message to the next hooker */
1424 return CallNextHookEx( pHookItem
->CallWndProc_hHook
, code
, wParam
, lParam
);
1427 /*************************************************************************
1428 * OLEMenu_GetMsgProc
1429 * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1430 * This is invoked from a message hook installed in OleSetMenuDescriptor.
1432 LRESULT CALLBACK
OLEMenu_GetMsgProc(INT code
, WPARAM wParam
, LPARAM lParam
)
1435 HOLEMENU hOleMenu
= 0;
1436 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1437 OleMenuHookItem
*pHookItem
= NULL
;
1440 TRACE("%i, %04x, %08x\n", code
, wParam
, (unsigned)lParam
);
1442 /* Check if we're being asked to process a messages */
1443 if ( HC_ACTION
!= code
)
1446 /* Retrieve the current message being dispatched from lParam */
1447 pMsg
= (LPMSG
)lParam
;
1449 /* Check if the message is destined for a window we are interested in:
1450 * If the window has an OLEMenu property we may need to dispatch
1451 * the menu message to its active objects window instead. */
1453 hOleMenu
= (HOLEMENU
)GetPropA( pMsg
->hwnd
, "PROP_OLEMenuDescriptor" );
1457 /* Process menu messages */
1458 switch( pMsg
->message
)
1462 wCode
= HIWORD(pMsg
->wParam
); /* Get notification code */
1464 goto NEXTHOOK
; /* Not a menu message */
1471 /* Get the menu descriptor */
1472 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1473 if ( !pOleMenuDescriptor
) /* Bad descriptor! */
1476 /* If the message was for the server dispatch it accordingly */
1477 if ( pOleMenuDescriptor
->bIsServerItem
)
1479 /* Change the hWnd in the message to the active objects hWnd.
1480 * The message loop which reads this message will automatically
1481 * dispatch it to the embedded objects window. */
1482 pMsg
->hwnd
= pOleMenuDescriptor
->hwndActiveObject
;
1486 if ( pOleMenuDescriptor
)
1487 GlobalUnlock( hOleMenu
);
1489 /* Lookup the hook item for the current thread */
1490 if ( !( pHookItem
= OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1492 /* This should never fail!! */
1493 WARN("could not retrieve hHook for current thread!\n" );
1497 /* Pass on the message to the next hooker */
1498 return CallNextHookEx( pHookItem
->GetMsg_hHook
, code
, wParam
, lParam
);
1501 /***********************************************************************
1502 * OleCreateMenuDescriptor [OLE32.@]
1503 * Creates an OLE menu descriptor for OLE to use when dispatching
1504 * menu messages and commands.
1507 * hmenuCombined - Handle to the objects combined menu
1508 * lpMenuWidths - Pointer to array of 6 LONG's indicating menus per group
1511 HOLEMENU WINAPI
OleCreateMenuDescriptor(
1512 HMENU hmenuCombined
,
1513 LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1516 OleMenuDescriptor
*pOleMenuDescriptor
;
1519 if ( !hmenuCombined
|| !lpMenuWidths
)
1522 /* Create an OLE menu descriptor */
1523 if ( !(hOleMenu
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_ZEROINIT
,
1524 sizeof(OleMenuDescriptor
) ) ) )
1527 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1528 if ( !pOleMenuDescriptor
)
1531 /* Initialize menu group widths and hmenu */
1532 for ( i
= 0; i
< 6; i
++ )
1533 pOleMenuDescriptor
->mgw
.width
[i
] = lpMenuWidths
->width
[i
];
1535 pOleMenuDescriptor
->hmenuCombined
= hmenuCombined
;
1536 pOleMenuDescriptor
->bIsServerItem
= FALSE
;
1537 GlobalUnlock( hOleMenu
);
1542 /***********************************************************************
1543 * OleDestroyMenuDescriptor [OLE32.@]
1544 * Destroy the shared menu descriptor
1546 HRESULT WINAPI
OleDestroyMenuDescriptor(
1547 HOLEMENU hmenuDescriptor
)
1549 if ( hmenuDescriptor
)
1550 GlobalFree( hmenuDescriptor
);
1554 /***********************************************************************
1555 * OleSetMenuDescriptor [OLE32.@]
1556 * Installs or removes OLE dispatching code for the containers frame window.
1559 * hOleMenu Handle to composite menu descriptor
1560 * hwndFrame Handle to containers frame window
1561 * hwndActiveObject Handle to objects in-place activation window
1562 * lpFrame Pointer to IOleInPlaceFrame on containers window
1563 * lpActiveObject Pointer to IOleInPlaceActiveObject on active in-place object
1566 * S_OK - menu installed correctly
1567 * E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1570 * The lpFrame and lpActiveObject parameters are currently ignored
1571 * OLE should install context sensitive help F1 filtering for the app when
1572 * these are non null.
1574 HRESULT WINAPI
OleSetMenuDescriptor(
1577 HWND hwndActiveObject
,
1578 LPOLEINPLACEFRAME lpFrame
,
1579 LPOLEINPLACEACTIVEOBJECT lpActiveObject
)
1581 OleMenuDescriptor
*pOleMenuDescriptor
= NULL
;
1584 if ( !hwndFrame
|| (hOleMenu
&& !hwndActiveObject
) )
1585 return E_INVALIDARG
;
1587 if ( lpFrame
|| lpActiveObject
)
1589 FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1597 /* Set up a message hook to intercept the containers frame window messages.
1598 * The message filter is responsible for dispatching menu messages from the
1599 * shared menu which are intended for the object.
1602 if ( hOleMenu
) /* Want to install dispatching code */
1604 /* If OLEMenu hooks are already installed for this thread, fail
1605 * Note: This effectively means that OleSetMenuDescriptor cannot
1606 * be called twice in succession on the same frame window
1607 * without first calling it with a null hOleMenu to uninstall */
1608 if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1611 /* Get the menu descriptor */
1612 pOleMenuDescriptor
= (OleMenuDescriptor
*) GlobalLock( hOleMenu
);
1613 if ( !pOleMenuDescriptor
)
1614 return E_UNEXPECTED
;
1616 /* Update the menu descriptor */
1617 pOleMenuDescriptor
->hwndFrame
= hwndFrame
;
1618 pOleMenuDescriptor
->hwndActiveObject
= hwndActiveObject
;
1620 GlobalUnlock( hOleMenu
);
1621 pOleMenuDescriptor
= NULL
;
1623 /* Add a menu descriptor windows property to the frame window */
1624 SetPropA( hwndFrame
, "PROP_OLEMenuDescriptor", hOleMenu
);
1626 /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1627 if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1630 else /* Want to uninstall dispatching code */
1632 /* Uninstall the hooks */
1633 if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1636 /* Remove the menu descriptor property from the frame window */
1637 RemovePropA( hwndFrame
, "PROP_OLEMenuDescriptor" );
1643 /******************************************************************************
1644 * IsAccelerator [OLE32.@]
1645 * Mostly copied from controls/menu.c TranslateAccelerator implementation
1647 BOOL WINAPI
IsAccelerator(HACCEL hAccel
, int cAccelEntries
, LPMSG lpMsg
, WORD
* lpwCmd
)
1652 if(!lpMsg
) return FALSE
;
1655 WARN_(accel
)("NULL accel handle\n");
1658 if((lpMsg
->message
!= WM_KEYDOWN
&&
1659 lpMsg
->message
!= WM_KEYUP
&&
1660 lpMsg
->message
!= WM_SYSKEYDOWN
&&
1661 lpMsg
->message
!= WM_SYSKEYUP
&&
1662 lpMsg
->message
!= WM_CHAR
)) return FALSE
;
1663 lpAccelTbl
= HeapAlloc(GetProcessHeap(), 0, cAccelEntries
* sizeof(ACCEL
));
1664 if (NULL
== lpAccelTbl
)
1668 if (CopyAcceleratorTableW(hAccel
, lpAccelTbl
, cAccelEntries
) != cAccelEntries
)
1670 WARN_(accel
)("CopyAcceleratorTableW failed\n");
1671 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1675 TRACE_(accel
)("hAccel=%p, cAccelEntries=%d,"
1676 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1677 hAccel
, cAccelEntries
,
1678 lpMsg
->hwnd
, lpMsg
->message
, lpMsg
->wParam
, lpMsg
->lParam
);
1679 for(i
= 0; i
< cAccelEntries
; i
++)
1681 if(lpAccelTbl
[i
].key
!= lpMsg
->wParam
)
1684 if(lpMsg
->message
== WM_CHAR
)
1686 if(!(lpAccelTbl
[i
].fVirt
& FALT
) && !(lpAccelTbl
[i
].fVirt
& FVIRTKEY
))
1688 TRACE_(accel
)("found accel for WM_CHAR: ('%c')\n", lpMsg
->wParam
& 0xff);
1694 if(lpAccelTbl
[i
].fVirt
& FVIRTKEY
)
1697 TRACE_(accel
)("found accel for virt_key %04x (scan %04x)\n",
1698 lpMsg
->wParam
, HIWORD(lpMsg
->lParam
) & 0xff);
1699 if(GetKeyState(VK_SHIFT
) & 0x8000) mask
|= FSHIFT
;
1700 if(GetKeyState(VK_CONTROL
) & 0x8000) mask
|= FCONTROL
;
1701 if(GetKeyState(VK_MENU
) & 0x8000) mask
|= FALT
;
1702 if(mask
== (lpAccelTbl
[i
].fVirt
& (FSHIFT
| FCONTROL
| FALT
))) goto found
;
1703 TRACE_(accel
)("incorrect SHIFT/CTRL/ALT-state\n");
1707 if(!(lpMsg
->lParam
& 0x01000000)) /* no special_key */
1709 if((lpAccelTbl
[i
].fVirt
& FALT
) && (lpMsg
->lParam
& 0x20000000))
1710 { /* ^^ ALT pressed */
1711 TRACE_(accel
)("found accel for Alt-%c\n", lpMsg
->wParam
& 0xff);
1719 WARN_(accel
)("couldn't translate accelerator key\n");
1720 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1724 if(lpwCmd
) *lpwCmd
= lpAccelTbl
[i
].cmd
;
1725 HeapFree(GetProcessHeap(), 0, lpAccelTbl
);
1729 /***********************************************************************
1730 * ReleaseStgMedium [OLE32.@]
1732 void WINAPI
ReleaseStgMedium(
1735 switch (pmedium
->tymed
)
1739 if ( (pmedium
->pUnkForRelease
==0) &&
1740 (pmedium
->u
.hGlobal
!=0) )
1741 GlobalFree(pmedium
->u
.hGlobal
);
1746 if (pmedium
->u
.lpszFileName
!=0)
1748 if (pmedium
->pUnkForRelease
==0)
1750 DeleteFileW(pmedium
->u
.lpszFileName
);
1753 CoTaskMemFree(pmedium
->u
.lpszFileName
);
1759 if (pmedium
->u
.pstm
!=0)
1761 IStream_Release(pmedium
->u
.pstm
);
1765 case TYMED_ISTORAGE
:
1767 if (pmedium
->u
.pstg
!=0)
1769 IStorage_Release(pmedium
->u
.pstg
);
1775 if ( (pmedium
->pUnkForRelease
==0) &&
1776 (pmedium
->u
.hBitmap
!=0) )
1777 DeleteObject(pmedium
->u
.hBitmap
);
1782 if ( (pmedium
->pUnkForRelease
==0) &&
1783 (pmedium
->u
.hMetaFilePict
!=0) )
1785 LPMETAFILEPICT pMP
= GlobalLock(pmedium
->u
.hMetaFilePict
);
1786 DeleteMetaFile(pMP
->hMF
);
1787 GlobalUnlock(pmedium
->u
.hMetaFilePict
);
1788 GlobalFree(pmedium
->u
.hMetaFilePict
);
1794 if ( (pmedium
->pUnkForRelease
==0) &&
1795 (pmedium
->u
.hEnhMetaFile
!=0) )
1797 DeleteEnhMetaFile(pmedium
->u
.hEnhMetaFile
);
1805 pmedium
->tymed
=TYMED_NULL
;
1808 * After cleaning up, the unknown is released
1810 if (pmedium
->pUnkForRelease
!=0)
1812 IUnknown_Release(pmedium
->pUnkForRelease
);
1813 pmedium
->pUnkForRelease
= 0;
1818 * OLEDD_Initialize()
1820 * Initializes the OLE drag and drop data structures.
1822 static void OLEDD_Initialize()
1826 ZeroMemory (&wndClass
, sizeof(WNDCLASSA
));
1827 wndClass
.style
= CS_GLOBALCLASS
;
1828 wndClass
.lpfnWndProc
= OLEDD_DragTrackerWindowProc
;
1829 wndClass
.cbClsExtra
= 0;
1830 wndClass
.cbWndExtra
= sizeof(TrackerWindowInfo
*);
1831 wndClass
.hCursor
= 0;
1832 wndClass
.hbrBackground
= 0;
1833 wndClass
.lpszClassName
= OLEDD_DRAGTRACKERCLASS
;
1835 RegisterClassA (&wndClass
);
1839 * OLEDD_UnInitialize()
1841 * Releases the OLE drag and drop data structures.
1843 static void OLEDD_UnInitialize()
1846 * Simply empty the list.
1848 while (targetListHead
!=NULL
)
1850 RevokeDragDrop(targetListHead
->hwndTarget
);
1855 * OLEDD_InsertDropTarget()
1857 * Insert the target node in the tree.
1859 static void OLEDD_InsertDropTarget(DropTargetNode
* nodeToAdd
)
1861 DropTargetNode
* curNode
;
1862 DropTargetNode
** parentNodeLink
;
1865 * Iterate the tree to find the insertion point.
1867 curNode
= targetListHead
;
1868 parentNodeLink
= &targetListHead
;
1870 while (curNode
!=NULL
)
1872 if (nodeToAdd
->hwndTarget
<curNode
->hwndTarget
)
1875 * If the node we want to add has a smaller HWND, go left
1877 parentNodeLink
= &curNode
->prevDropTarget
;
1878 curNode
= curNode
->prevDropTarget
;
1880 else if (nodeToAdd
->hwndTarget
>curNode
->hwndTarget
)
1883 * If the node we want to add has a larger HWND, go right
1885 parentNodeLink
= &curNode
->nextDropTarget
;
1886 curNode
= curNode
->nextDropTarget
;
1891 * The item was found in the list. It shouldn't have been there
1899 * If we get here, we have found a spot for our item. The parentNodeLink
1900 * pointer points to the pointer that we have to modify.
1901 * The curNode should be NULL. We just have to establish the link and Voila!
1903 assert(curNode
==NULL
);
1904 assert(parentNodeLink
!=NULL
);
1905 assert(*parentNodeLink
==NULL
);
1907 *parentNodeLink
=nodeToAdd
;
1911 * OLEDD_ExtractDropTarget()
1913 * Removes the target node from the tree.
1915 static DropTargetNode
* OLEDD_ExtractDropTarget(HWND hwndOfTarget
)
1917 DropTargetNode
* curNode
;
1918 DropTargetNode
** parentNodeLink
;
1921 * Iterate the tree to find the insertion point.
1923 curNode
= targetListHead
;
1924 parentNodeLink
= &targetListHead
;
1926 while (curNode
!=NULL
)
1928 if (hwndOfTarget
<curNode
->hwndTarget
)
1931 * If the node we want to add has a smaller HWND, go left
1933 parentNodeLink
= &curNode
->prevDropTarget
;
1934 curNode
= curNode
->prevDropTarget
;
1936 else if (hwndOfTarget
>curNode
->hwndTarget
)
1939 * If the node we want to add has a larger HWND, go right
1941 parentNodeLink
= &curNode
->nextDropTarget
;
1942 curNode
= curNode
->nextDropTarget
;
1947 * The item was found in the list. Detach it from it's parent and
1948 * re-insert it's kids in the tree.
1950 assert(parentNodeLink
!=NULL
);
1951 assert(*parentNodeLink
==curNode
);
1954 * We arbitrately re-attach the left sub-tree to the parent.
1956 *parentNodeLink
= curNode
->prevDropTarget
;
1959 * And we re-insert the right subtree
1961 if (curNode
->nextDropTarget
!=NULL
)
1963 OLEDD_InsertDropTarget(curNode
->nextDropTarget
);
1967 * The node we found is still a valid node once we complete
1968 * the unlinking of the kids.
1970 curNode
->nextDropTarget
=NULL
;
1971 curNode
->prevDropTarget
=NULL
;
1978 * If we get here, the node is not in the tree
1984 * OLEDD_FindDropTarget()
1986 * Finds information about the drop target.
1988 static DropTargetNode
* OLEDD_FindDropTarget(HWND hwndOfTarget
)
1990 DropTargetNode
* curNode
;
1993 * Iterate the tree to find the HWND value.
1995 curNode
= targetListHead
;
1997 while (curNode
!=NULL
)
1999 if (hwndOfTarget
<curNode
->hwndTarget
)
2002 * If the node we want to add has a smaller HWND, go left
2004 curNode
= curNode
->prevDropTarget
;
2006 else if (hwndOfTarget
>curNode
->hwndTarget
)
2009 * If the node we want to add has a larger HWND, go right
2011 curNode
= curNode
->nextDropTarget
;
2016 * The item was found in the list.
2023 * If we get here, the item is not in the list
2029 * OLEDD_DragTrackerWindowProc()
2031 * This method is the WindowProcedure of the drag n drop tracking
2032 * window. During a drag n Drop operation, an invisible window is created
2033 * to receive the user input and act upon it. This procedure is in charge
2036 static LRESULT WINAPI
OLEDD_DragTrackerWindowProc(
2046 LPCREATESTRUCTA createStruct
= (LPCREATESTRUCTA
)lParam
;
2048 SetWindowLongA(hwnd
, 0, (LONG
)createStruct
->lpCreateParams
);
2055 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
2059 * Get the current mouse position in screen coordinates.
2061 mousePos
.x
= LOWORD(lParam
);
2062 mousePos
.y
= HIWORD(lParam
);
2063 ClientToScreen(hwnd
, &mousePos
);
2066 * Track the movement of the mouse.
2068 OLEDD_TrackMouseMove(trackerInfo
, mousePos
, wParam
);
2075 case WM_LBUTTONDOWN
:
2076 case WM_MBUTTONDOWN
:
2077 case WM_RBUTTONDOWN
:
2079 TrackerWindowInfo
* trackerInfo
= (TrackerWindowInfo
*)GetWindowLongA(hwnd
, 0);
2083 * Get the current mouse position in screen coordinates.
2085 mousePos
.x
= LOWORD(lParam
);
2086 mousePos
.y
= HIWORD(lParam
);
2087 ClientToScreen(hwnd
, &mousePos
);
2090 * Notify everyone that the button state changed
2091 * TODO: Check if the "escape" key was pressed.
2093 OLEDD_TrackStateChange(trackerInfo
, mousePos
, wParam
);
2100 * This is a window proc after all. Let's call the default.
2102 return DefWindowProcA (hwnd
, uMsg
, wParam
, lParam
);
2106 * OLEDD_TrackMouseMove()
2108 * This method is invoked while a drag and drop operation is in effect.
2109 * it will generate the appropriate callbacks in the drop source
2110 * and drop target. It will also provide the expected feedback to
2114 * trackerInfo - Pointer to the structure identifying the
2115 * drag & drop operation that is currently
2117 * mousePos - Current position of the mouse in screen
2119 * keyState - Contains the state of the shift keys and the
2120 * mouse buttons (MK_LBUTTON and the like)
2122 static void OLEDD_TrackMouseMove(
2123 TrackerWindowInfo
* trackerInfo
,
2127 HWND hwndNewTarget
= 0;
2131 * Get the handle of the window under the mouse
2133 hwndNewTarget
= WindowFromPoint(mousePos
);
2136 * Every time, we re-initialize the effects passed to the
2137 * IDropTarget to the effects allowed by the source.
2139 *trackerInfo
->pdwEffect
= trackerInfo
->dwOKEffect
;
2142 * If we are hovering over the same target as before, send the
2143 * DragOver notification
2145 if ( (trackerInfo
->curDragTarget
!= 0) &&
2146 (trackerInfo
->curTargetHWND
== hwndNewTarget
) )
2148 POINTL mousePosParam
;
2151 * The documentation tells me that the coordinate should be in the target
2152 * window's coordinate space. However, the tests I made tell me the
2153 * coordinates should be in screen coordinates.
2155 mousePosParam
.x
= mousePos
.x
;
2156 mousePosParam
.y
= mousePos
.y
;
2158 IDropTarget_DragOver(trackerInfo
->curDragTarget
,
2161 trackerInfo
->pdwEffect
);
2165 DropTargetNode
* newDropTargetNode
= 0;
2168 * If we changed window, we have to notify our old target and check for
2171 if (trackerInfo
->curDragTarget
!=0)
2173 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2177 * Make sure we're hovering over a window.
2179 if (hwndNewTarget
!=0)
2182 * Find-out if there is a drag target under the mouse
2184 HWND nexttar
= hwndNewTarget
;
2185 trackerInfo
->curTargetHWND
= hwndNewTarget
;
2188 newDropTargetNode
= OLEDD_FindDropTarget(nexttar
);
2189 } while (!newDropTargetNode
&& (nexttar
= GetParent(nexttar
)) != 0);
2190 if(nexttar
) hwndNewTarget
= nexttar
;
2192 trackerInfo
->curDragTargetHWND
= hwndNewTarget
;
2193 trackerInfo
->curDragTarget
= newDropTargetNode
? newDropTargetNode
->dropTarget
: 0;
2196 * If there is, notify it that we just dragged-in
2198 if (trackerInfo
->curDragTarget
!=0)
2200 POINTL mousePosParam
;
2203 * The documentation tells me that the coordinate should be in the target
2204 * window's coordinate space. However, the tests I made tell me the
2205 * coordinates should be in screen coordinates.
2207 mousePosParam
.x
= mousePos
.x
;
2208 mousePosParam
.y
= mousePos
.y
;
2210 IDropTarget_DragEnter(trackerInfo
->curDragTarget
,
2211 trackerInfo
->dataObject
,
2214 trackerInfo
->pdwEffect
);
2220 * The mouse is not over a window so we don't track anything.
2222 trackerInfo
->curDragTargetHWND
= 0;
2223 trackerInfo
->curTargetHWND
= 0;
2224 trackerInfo
->curDragTarget
= 0;
2229 * Now that we have done that, we have to tell the source to give
2230 * us feedback on the work being done by the target. If we don't
2231 * have a target, simulate no effect.
2233 if (trackerInfo
->curDragTarget
==0)
2235 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2238 hr
= IDropSource_GiveFeedback(trackerInfo
->dropSource
,
2239 *trackerInfo
->pdwEffect
);
2242 * When we ask for feedback from the drop source, sometimes it will
2243 * do all the necessary work and sometimes it will not handle it
2244 * when that's the case, we must display the standard drag and drop
2247 if (hr
==DRAGDROP_S_USEDEFAULTCURSORS
)
2249 if (*trackerInfo
->pdwEffect
& DROPEFFECT_MOVE
)
2251 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(1)));
2253 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_COPY
)
2255 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(2)));
2257 else if (*trackerInfo
->pdwEffect
& DROPEFFECT_LINK
)
2259 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(3)));
2263 SetCursor(LoadCursorA(OLE32_hInstance
, MAKEINTRESOURCEA(0)));
2269 * OLEDD_TrackStateChange()
2271 * This method is invoked while a drag and drop operation is in effect.
2272 * It is used to notify the drop target/drop source callbacks when
2273 * the state of the keyboard or mouse button change.
2276 * trackerInfo - Pointer to the structure identifying the
2277 * drag & drop operation that is currently
2279 * mousePos - Current position of the mouse in screen
2281 * keyState - Contains the state of the shift keys and the
2282 * mouse buttons (MK_LBUTTON and the like)
2284 static void OLEDD_TrackStateChange(
2285 TrackerWindowInfo
* trackerInfo
,
2290 * Ask the drop source what to do with the operation.
2292 trackerInfo
->returnValue
= IDropSource_QueryContinueDrag(
2293 trackerInfo
->dropSource
,
2294 trackerInfo
->escPressed
,
2298 * All the return valued will stop the operation except the S_OK
2301 if (trackerInfo
->returnValue
!=S_OK
)
2304 * Make sure the message loop in DoDragDrop stops
2306 trackerInfo
->trackingDone
= TRUE
;
2309 * Release the mouse in case the drop target decides to show a popup
2310 * or a menu or something.
2315 * If we end-up over a target, drop the object in the target or
2316 * inform the target that the operation was cancelled.
2318 if (trackerInfo
->curDragTarget
!=0)
2320 switch (trackerInfo
->returnValue
)
2323 * If the source wants us to complete the operation, we tell
2324 * the drop target that we just dropped the object in it.
2326 case DRAGDROP_S_DROP
:
2328 POINTL mousePosParam
;
2331 * The documentation tells me that the coordinate should be
2332 * in the target window's coordinate space. However, the tests
2333 * I made tell me the coordinates should be in screen coordinates.
2335 mousePosParam
.x
= mousePos
.x
;
2336 mousePosParam
.y
= mousePos
.y
;
2338 IDropTarget_Drop(trackerInfo
->curDragTarget
,
2339 trackerInfo
->dataObject
,
2342 trackerInfo
->pdwEffect
);
2346 * If the source told us that we should cancel, fool the drop
2347 * target by telling it that the mouse left it's window.
2348 * Also set the drop effect to "NONE" in case the application
2349 * ignores the result of DoDragDrop.
2351 case DRAGDROP_S_CANCEL
:
2352 IDropTarget_DragLeave(trackerInfo
->curDragTarget
);
2353 *trackerInfo
->pdwEffect
= DROPEFFECT_NONE
;
2361 * OLEDD_GetButtonState()
2363 * This method will use the current state of the keyboard to build
2364 * a button state mask equivalent to the one passed in the
2365 * WM_MOUSEMOVE wParam.
2367 static DWORD
OLEDD_GetButtonState()
2369 BYTE keyboardState
[256];
2372 GetKeyboardState(keyboardState
);
2374 if ( (keyboardState
[VK_SHIFT
] & 0x80) !=0)
2375 keyMask
|= MK_SHIFT
;
2377 if ( (keyboardState
[VK_CONTROL
] & 0x80) !=0)
2378 keyMask
|= MK_CONTROL
;
2380 if ( (keyboardState
[VK_LBUTTON
] & 0x80) !=0)
2381 keyMask
|= MK_LBUTTON
;
2383 if ( (keyboardState
[VK_RBUTTON
] & 0x80) !=0)
2384 keyMask
|= MK_RBUTTON
;
2386 if ( (keyboardState
[VK_MBUTTON
] & 0x80) !=0)
2387 keyMask
|= MK_MBUTTON
;
2393 * OLEDD_GetButtonState()
2395 * This method will read the default value of the registry key in
2396 * parameter and extract a DWORD value from it. The registry key value
2397 * can be in a string key or a DWORD key.
2400 * regKey - Key to read the default value from
2401 * pdwValue - Pointer to the location where the DWORD
2402 * value is returned. This value is not modified
2403 * if the value is not found.
2406 static void OLEUTL_ReadRegistryDWORDValue(
2415 lres
= RegQueryValueExA(regKey
,
2422 if (lres
==ERROR_SUCCESS
)
2427 *pdwValue
= *(DWORD
*)buffer
;
2432 *pdwValue
= (DWORD
)strtoul(buffer
, NULL
, 10);
2438 /******************************************************************************
2441 * The operation of this function is documented literally in the WinAPI
2442 * documentation to involve a QueryInterface for the IViewObject interface,
2443 * followed by a call to IViewObject::Draw.
2445 HRESULT WINAPI
OleDraw(
2452 IViewObject
*viewobject
;
2454 hres
= IUnknown_QueryInterface(pUnk
,
2456 (void**)&viewobject
);
2458 if (SUCCEEDED(hres
))
2462 rectl
.left
= lprcBounds
->left
;
2463 rectl
.right
= lprcBounds
->right
;
2464 rectl
.top
= lprcBounds
->top
;
2465 rectl
.bottom
= lprcBounds
->bottom
;
2466 hres
= IViewObject_Draw(viewobject
, dwAspect
, -1, 0, 0, 0, hdcDraw
, &rectl
, 0, 0, 0);
2468 IViewObject_Release(viewobject
);
2473 return DV_E_NOIVIEWOBJECT
;
2477 /***********************************************************************
2478 * OleTranslateAccelerator [OLE32.@]
2480 HRESULT WINAPI
OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame
,
2481 LPOLEINPLACEFRAMEINFO lpFrameInfo
, LPMSG lpmsg
)
2485 TRACE("(%p,%p,%p)\n", lpFrame
, lpFrameInfo
, lpmsg
);
2487 if (IsAccelerator(lpFrameInfo
->haccel
,lpFrameInfo
->cAccelEntries
,lpmsg
,&wID
))
2488 return IOleInPlaceFrame_TranslateAccelerator(lpFrame
,lpmsg
,wID
);
2493 /******************************************************************************
2494 * OleCreate [OLE32.@]
2497 HRESULT WINAPI
OleCreate(
2501 LPFORMATETC pFormatEtc
,
2502 LPOLECLIENTSITE pClientSite
,
2506 HRESULT hres
, hres1
;
2507 IUnknown
* pUnk
= NULL
;
2509 FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid
), debugstr_guid(riid
));
2511 if (SUCCEEDED((hres
= CoCreateInstance(rclsid
, 0, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
|CLSCTX_LOCAL_SERVER
, riid
, (LPVOID
*)&pUnk
))))
2516 IPersistStorage
* pPS
;
2517 if (SUCCEEDED((hres
= IUnknown_QueryInterface( pUnk
, &IID_IOleObject
, (LPVOID
*)&pOE
))))
2519 TRACE("trying to set clientsite %p\n", pClientSite
);
2520 hres1
= IOleObject_SetClientSite(pOE
, pClientSite
);
2521 TRACE("-- result 0x%08lx\n", hres1
);
2522 IOleObject_Release(pOE
);
2524 if (SUCCEEDED((hres
= IUnknown_QueryInterface( pUnk
, &IID_IPersistStorage
, (LPVOID
*)&pPS
))))
2526 TRACE("trying to set stg %p\n", pStg
);
2527 hres1
= IPersistStorage_InitNew(pPS
, pStg
);
2528 TRACE("-- result 0x%08lx\n", hres1
);
2529 IPersistStorage_Release(pPS
);
2536 TRACE("-- %p\n", pUnk
);
2540 /******************************************************************************
2541 * OleSetAutoConvert [OLE32.@]
2543 HRESULT WINAPI
OleSetAutoConvert(REFCLSID clsidOld
, REFCLSID clsidNew
)
2545 static const WCHAR wszAutoConvertTo
[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2547 WCHAR szClsidNew
[CHARS_IN_GUID
];
2550 TRACE("(%s,%s)\n", debugstr_guid(clsidOld
), debugstr_guid(clsidNew
));
2552 res
= COM_OpenKeyForCLSID(clsidOld
, NULL
, KEY_READ
| KEY_WRITE
, &hkey
);
2555 StringFromGUID2(clsidNew
, szClsidNew
, CHARS_IN_GUID
);
2556 if (RegSetValueW(hkey
, wszAutoConvertTo
, REG_SZ
, szClsidNew
, (strlenW(szClsidNew
)+1) * sizeof(WCHAR
)))
2558 res
= REGDB_E_WRITEREGDB
;
2563 if (hkey
) RegCloseKey(hkey
);
2567 /******************************************************************************
2568 * OleDoAutoConvert [OLE32.@]
2570 HRESULT WINAPI
OleDoAutoConvert(LPSTORAGE pStg
, LPCLSID pClsidNew
)
2572 FIXME("(%p,%p) : stub\n",pStg
,pClsidNew
);
2576 /******************************************************************************
2577 * OleIsRunning [OLE32.@]
2579 BOOL WINAPI
OleIsRunning(LPOLEOBJECT pObject
)
2581 IRunnableObject
*pRunnable
;
2585 TRACE("(%p)\n", pObject
);
2587 hr
= IOleObject_QueryInterface(pObject
, &IID_IRunnableObject
, (void **)&pRunnable
);
2590 running
= IRunnableObject_IsRunning(pRunnable
);
2591 IRunnableObject_Release(pRunnable
);
2595 /***********************************************************************
2596 * OLE_FreeClipDataArray [internal]
2599 * frees the data associated with an array of CLIPDATAs
2601 static void OLE_FreeClipDataArray(ULONG count
, CLIPDATA
* pClipDataArray
)
2604 for (i
= 0; i
< count
; i
++)
2605 if (pClipDataArray
[i
].pClipData
)
2606 CoTaskMemFree(pClipDataArray
[i
].pClipData
);
2609 /***********************************************************************
2610 * PropSysAllocString [OLE32.@]
2612 * Basically a copy of SysAllocStringLen.
2614 BSTR WINAPI
PropSysAllocString(LPCOLESTR str
)
2618 WCHAR
* stringBuffer
;
2623 len
= lstrlenW(str
);
2625 * Find the length of the buffer passed-in in bytes.
2627 bufferSize
= len
* sizeof (WCHAR
);
2630 * Allocate a new buffer to hold the string.
2631 * don't forget to keep an empty spot at the beginning of the
2632 * buffer for the character count and an extra character at the
2635 newBuffer
= HeapAlloc(GetProcessHeap(), 0,
2636 bufferSize
+ sizeof(WCHAR
) + sizeof(DWORD
));
2639 * If the memory allocation failed, return a null pointer.
2645 * Copy the length of the string in the placeholder.
2647 *newBuffer
= bufferSize
;
2650 * Skip the byte count.
2655 * Copy the information in the buffer.
2656 * Since it is valid to pass a NULL pointer here, we'll initialize the
2657 * buffer to nul if it is the case.
2660 memcpy(newBuffer
, str
, bufferSize
);
2662 memset(newBuffer
, 0, bufferSize
);
2665 * Make sure that there is a nul character at the end of the
2668 stringBuffer
= (WCHAR
*)newBuffer
;
2669 stringBuffer
[len
] = L
'\0';
2671 return (LPWSTR
)stringBuffer
;
2674 /***********************************************************************
2675 * PropSysFreeString [OLE32.@]
2677 * Copy of SysFreeString.
2679 void WINAPI
PropSysFreeString(LPOLESTR str
)
2681 DWORD
* bufferPointer
;
2683 /* NULL is a valid parameter */
2687 * We have to be careful when we free a BSTR pointer, it points to
2688 * the beginning of the string but it skips the byte count contained
2689 * before the string.
2691 bufferPointer
= (DWORD
*)str
;
2696 * Free the memory from its "real" origin.
2698 HeapFree(GetProcessHeap(), 0, bufferPointer
);
2701 /******************************************************************************
2702 * Check if a PROPVARIANT's type is valid.
2704 static inline HRESULT
PROPVARIANT_ValidateType(VARTYPE vt
)
2730 case VT_STREAMED_OBJECT
:
2731 case VT_STORED_OBJECT
:
2732 case VT_BLOB_OBJECT
:
2735 case VT_I2
|VT_VECTOR
:
2736 case VT_I4
|VT_VECTOR
:
2737 case VT_R4
|VT_VECTOR
:
2738 case VT_R8
|VT_VECTOR
:
2739 case VT_CY
|VT_VECTOR
:
2740 case VT_DATE
|VT_VECTOR
:
2741 case VT_BSTR
|VT_VECTOR
:
2742 case VT_ERROR
|VT_VECTOR
:
2743 case VT_BOOL
|VT_VECTOR
:
2744 case VT_VARIANT
|VT_VECTOR
:
2745 case VT_UI1
|VT_VECTOR
:
2746 case VT_UI2
|VT_VECTOR
:
2747 case VT_UI4
|VT_VECTOR
:
2748 case VT_I8
|VT_VECTOR
:
2749 case VT_UI8
|VT_VECTOR
:
2750 case VT_LPSTR
|VT_VECTOR
:
2751 case VT_LPWSTR
|VT_VECTOR
:
2752 case VT_FILETIME
|VT_VECTOR
:
2753 case VT_CF
|VT_VECTOR
:
2754 case VT_CLSID
|VT_VECTOR
:
2757 WARN("Bad type %d\n", vt
);
2758 return STG_E_INVALIDPARAMETER
;
2761 /***********************************************************************
2762 * PropVariantClear [OLE32.@]
2764 HRESULT WINAPI
PropVariantClear(PROPVARIANT
* pvar
) /* [in/out] */
2768 TRACE("(%p)\n", pvar
);
2773 hr
= PROPVARIANT_ValidateType(pvar
->vt
);
2780 case VT_STREAMED_OBJECT
:
2782 case VT_STORED_OBJECT
:
2783 if (pvar
->u
.pStream
)
2784 IUnknown_Release(pvar
->u
.pStream
);
2789 /* pick an arbitary typed pointer - we don't care about the type
2790 * as we are just freeing it */
2791 CoTaskMemFree(pvar
->u
.puuid
);
2794 case VT_BLOB_OBJECT
:
2795 CoTaskMemFree(pvar
->u
.blob
.pBlobData
);
2798 if (pvar
->u
.bstrVal
)
2799 PropSysFreeString(pvar
->u
.bstrVal
);
2802 if (pvar
->u
.pclipdata
)
2804 OLE_FreeClipDataArray(1, pvar
->u
.pclipdata
);
2805 CoTaskMemFree(pvar
->u
.pclipdata
);
2809 if (pvar
->vt
& VT_VECTOR
)
2813 switch (pvar
->vt
& ~VT_VECTOR
)
2816 FreePropVariantArray(pvar
->u
.capropvar
.cElems
, pvar
->u
.capropvar
.pElems
);
2819 OLE_FreeClipDataArray(pvar
->u
.caclipdata
.cElems
, pvar
->u
.caclipdata
.pElems
);
2822 for (i
= 0; i
< pvar
->u
.cabstr
.cElems
; i
++)
2823 PropSysFreeString(pvar
->u
.cabstr
.pElems
[i
]);
2826 for (i
= 0; i
< pvar
->u
.calpstr
.cElems
; i
++)
2827 CoTaskMemFree(pvar
->u
.calpstr
.pElems
[i
]);
2830 for (i
= 0; i
< pvar
->u
.calpwstr
.cElems
; i
++)
2831 CoTaskMemFree(pvar
->u
.calpwstr
.pElems
[i
]);
2834 if (pvar
->vt
& ~VT_VECTOR
)
2836 /* pick an arbitary VT_VECTOR structure - they all have the same
2838 CoTaskMemFree(pvar
->u
.capropvar
.pElems
);
2842 WARN("Invalid/unsupported type %d\n", pvar
->vt
);
2845 ZeroMemory(pvar
, sizeof(*pvar
));
2850 /***********************************************************************
2851 * PropVariantCopy [OLE32.@]
2853 HRESULT WINAPI
PropVariantCopy(PROPVARIANT
*pvarDest
, /* [out] */
2854 const PROPVARIANT
*pvarSrc
) /* [in] */
2859 TRACE("(%p, %p)\n", pvarDest
, pvarSrc
);
2861 hr
= PROPVARIANT_ValidateType(pvarSrc
->vt
);
2865 /* this will deal with most cases */
2866 CopyMemory(pvarDest
, pvarSrc
, sizeof(*pvarDest
));
2871 case VT_STREAMED_OBJECT
:
2873 case VT_STORED_OBJECT
:
2874 IUnknown_AddRef((LPUNKNOWN
)pvarDest
->u
.pStream
);
2877 pvarDest
->u
.puuid
= CoTaskMemAlloc(sizeof(CLSID
));
2878 CopyMemory(pvarDest
->u
.puuid
, pvarSrc
->u
.puuid
, sizeof(CLSID
));
2881 len
= strlen(pvarSrc
->u
.pszVal
);
2882 pvarDest
->u
.pszVal
= CoTaskMemAlloc((len
+1)*sizeof(CHAR
));
2883 CopyMemory(pvarDest
->u
.pszVal
, pvarSrc
->u
.pszVal
, (len
+1)*sizeof(CHAR
));
2886 len
= lstrlenW(pvarSrc
->u
.pwszVal
);
2887 pvarDest
->u
.pwszVal
= CoTaskMemAlloc((len
+1)*sizeof(WCHAR
));
2888 CopyMemory(pvarDest
->u
.pwszVal
, pvarSrc
->u
.pwszVal
, (len
+1)*sizeof(WCHAR
));
2891 case VT_BLOB_OBJECT
:
2892 if (pvarSrc
->u
.blob
.pBlobData
)
2894 len
= pvarSrc
->u
.blob
.cbSize
;
2895 pvarDest
->u
.blob
.pBlobData
= CoTaskMemAlloc(len
);
2896 CopyMemory(pvarDest
->u
.blob
.pBlobData
, pvarSrc
->u
.blob
.pBlobData
, len
);
2900 pvarDest
->u
.bstrVal
= PropSysAllocString(pvarSrc
->u
.bstrVal
);
2903 if (pvarSrc
->u
.pclipdata
)
2905 len
= pvarSrc
->u
.pclipdata
->cbSize
- sizeof(pvarSrc
->u
.pclipdata
->ulClipFmt
);
2906 CoTaskMemAlloc(len
);
2907 CopyMemory(pvarDest
->u
.pclipdata
->pClipData
, pvarSrc
->u
.pclipdata
->pClipData
, len
);
2911 if (pvarSrc
->vt
& VT_VECTOR
)
2916 switch(pvarSrc
->vt
& ~VT_VECTOR
)
2918 case VT_I1
: elemSize
= sizeof(pvarSrc
->u
.cVal
); break;
2919 case VT_UI1
: elemSize
= sizeof(pvarSrc
->u
.bVal
); break;
2920 case VT_I2
: elemSize
= sizeof(pvarSrc
->u
.iVal
); break;
2921 case VT_UI2
: elemSize
= sizeof(pvarSrc
->u
.uiVal
); break;
2922 case VT_BOOL
: elemSize
= sizeof(pvarSrc
->u
.boolVal
); break;
2923 case VT_I4
: elemSize
= sizeof(pvarSrc
->u
.lVal
); break;
2924 case VT_UI4
: elemSize
= sizeof(pvarSrc
->u
.ulVal
); break;
2925 case VT_R4
: elemSize
= sizeof(pvarSrc
->u
.fltVal
); break;
2926 case VT_R8
: elemSize
= sizeof(pvarSrc
->u
.dblVal
); break;
2927 case VT_ERROR
: elemSize
= sizeof(pvarSrc
->u
.scode
); break;
2928 case VT_I8
: elemSize
= sizeof(pvarSrc
->u
.hVal
); break;
2929 case VT_UI8
: elemSize
= sizeof(pvarSrc
->u
.uhVal
); break;
2930 case VT_CY
: elemSize
= sizeof(pvarSrc
->u
.cyVal
); break;
2931 case VT_DATE
: elemSize
= sizeof(pvarSrc
->u
.date
); break;
2932 case VT_FILETIME
: elemSize
= sizeof(pvarSrc
->u
.filetime
); break;
2933 case VT_CLSID
: elemSize
= sizeof(*pvarSrc
->u
.puuid
); break;
2934 case VT_CF
: elemSize
= sizeof(*pvarSrc
->u
.pclipdata
); break;
2935 case VT_BSTR
: elemSize
= sizeof(*pvarSrc
->u
.bstrVal
); break;
2936 case VT_LPSTR
: elemSize
= sizeof(*pvarSrc
->u
.pszVal
); break;
2937 case VT_LPWSTR
: elemSize
= sizeof(*pvarSrc
->u
.pwszVal
); break;
2941 FIXME("Invalid element type: %ul\n", pvarSrc
->vt
& ~VT_VECTOR
);
2942 return E_INVALIDARG
;
2944 len
= pvarSrc
->u
.capropvar
.cElems
;
2945 pvarDest
->u
.capropvar
.pElems
= CoTaskMemAlloc(len
* elemSize
);
2946 if (pvarSrc
->vt
== (VT_VECTOR
| VT_VARIANT
))
2948 for (i
= 0; i
< len
; i
++)
2949 PropVariantCopy(&pvarDest
->u
.capropvar
.pElems
[i
], &pvarSrc
->u
.capropvar
.pElems
[i
]);
2951 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_CF
))
2953 FIXME("Copy clipformats\n");
2955 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_BSTR
))
2957 for (i
= 0; i
< len
; i
++)
2958 pvarDest
->u
.cabstr
.pElems
[i
] = PropSysAllocString(pvarSrc
->u
.cabstr
.pElems
[i
]);
2960 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPSTR
))
2963 for (i
= 0; i
< len
; i
++)
2965 strLen
= lstrlenA(pvarSrc
->u
.calpstr
.pElems
[i
]) + 1;
2966 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2967 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2968 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2971 else if (pvarSrc
->vt
== (VT_VECTOR
| VT_LPWSTR
))
2974 for (i
= 0; i
< len
; i
++)
2976 strLen
= (lstrlenW(pvarSrc
->u
.calpwstr
.pElems
[i
]) + 1) *
2978 pvarDest
->u
.calpstr
.pElems
[i
] = CoTaskMemAlloc(strLen
);
2979 memcpy(pvarDest
->u
.calpstr
.pElems
[i
],
2980 pvarSrc
->u
.calpstr
.pElems
[i
], strLen
);
2984 CopyMemory(pvarDest
->u
.capropvar
.pElems
, pvarSrc
->u
.capropvar
.pElems
, len
* elemSize
);
2987 WARN("Invalid/unsupported type %d\n", pvarSrc
->vt
);
2993 /***********************************************************************
2994 * FreePropVariantArray [OLE32.@]
2996 HRESULT WINAPI
FreePropVariantArray(ULONG cVariants
, /* [in] */
2997 PROPVARIANT
*rgvars
) /* [in/out] */
3001 TRACE("(%lu, %p)\n", cVariants
, rgvars
);
3003 for(i
= 0; i
< cVariants
; i
++)
3004 PropVariantClear(&rgvars
[i
]);
3009 /******************************************************************************
3010 * DllDebugObjectRPCHook (OLE32.@)
3011 * turns on and off internal debugging, pointer is only used on macintosh
3014 BOOL WINAPI
DllDebugObjectRPCHook(BOOL b
, void *dummy
)