Removed unused debug channels.
[wine] / dlls / ole32 / ole2.c
1 /*
2  *      OLE2 library
3  *
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
9  *
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.
14  *
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.
19  *
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
23  */
24
25 #include "config.h"
26
27 #include <assert.h>
28 #include <stdlib.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <string.h>
32
33 #define COBJMACROS
34 #define NONAMELESSUNION
35 #define NONAMELESSSTRUCT
36
37 #include "windef.h"
38 #include "winbase.h"
39 #include "winerror.h"
40 #include "wingdi.h"
41 #include "winuser.h"
42 #include "winnls.h"
43 #include "winreg.h"
44 #include "commctrl.h"
45 #include "ole2.h"
46 #include "ole2ver.h"
47 #include "wownt32.h"
48
49 #include "wine/unicode.h"
50 #include "wine/winbase16.h"
51 #include "wine/wingdi16.h"
52 #include "wine/winuser16.h"
53 #include "compobj_private.h"
54
55 #include "wine/debug.h"
56
57 WINE_DEFAULT_DEBUG_CHANNEL(ole);
58 WINE_DECLARE_DEBUG_CHANNEL(accel);
59
60 #define HICON_16(h32)           (LOWORD(h32))
61 #define HICON_32(h16)           ((HICON)(ULONG_PTR)(h16))
62 #define HINSTANCE_32(h16)       ((HINSTANCE)(ULONG_PTR)(h16))
63
64 /******************************************************************************
65  * These are static/global variables and internal data structures that the
66  * OLE module uses to maintain it's state.
67  */
68 typedef struct tagDropTargetNode
69 {
70   HWND          hwndTarget;
71   IDropTarget*    dropTarget;
72   struct tagDropTargetNode* prevDropTarget;
73   struct tagDropTargetNode* nextDropTarget;
74 } DropTargetNode;
75
76 typedef struct tagTrackerWindowInfo
77 {
78   IDataObject* dataObject;
79   IDropSource* dropSource;
80   DWORD        dwOKEffect;
81   DWORD*       pdwEffect;
82   BOOL       trackingDone;
83   HRESULT      returnValue;
84
85   BOOL       escPressed;
86   HWND       curTargetHWND;     /* window the mouse is hovering over */
87   HWND       curDragTargetHWND; /* might be a ancestor of curTargetHWND */
88   IDropTarget* curDragTarget;
89 } TrackerWindowInfo;
90
91 typedef struct tagOleMenuDescriptor  /* OleMenuDescriptor */
92 {
93   HWND               hwndFrame;         /* The containers frame window */
94   HWND               hwndActiveObject;  /* The active objects window */
95   OLEMENUGROUPWIDTHS mgw;               /* OLE menu group widths for the shared menu */
96   HMENU              hmenuCombined;     /* The combined menu */
97   BOOL               bIsServerItem;     /* True if the currently open popup belongs to the server */
98 } OleMenuDescriptor;
99
100 typedef struct tagOleMenuHookItem   /* OleMenu hook item in per thread hook list */
101 {
102   DWORD tid;                /* Thread Id  */
103   HANDLE hHeap;             /* Heap this is allocated from */
104   HHOOK GetMsg_hHook;       /* message hook for WH_GETMESSAGE */
105   HHOOK CallWndProc_hHook;  /* message hook for WH_CALLWNDPROC */
106   struct tagOleMenuHookItem *next;
107 } OleMenuHookItem;
108
109 static OleMenuHookItem *hook_list;
110
111 /*
112  * This is the lock count on the OLE library. It is controlled by the
113  * OLEInitialize/OLEUninitialize methods.
114  */
115 static ULONG OLE_moduleLockCount = 0;
116
117 /*
118  * Name of our registered window class.
119  */
120 static const char OLEDD_DRAGTRACKERCLASS[] = "WineDragDropTracker32";
121
122 /*
123  * This is the head of the Drop target container.
124  */
125 static DropTargetNode* targetListHead = NULL;
126
127 /******************************************************************************
128  * These are the prototypes of miscelaneous utility methods
129  */
130 static void OLEUTL_ReadRegistryDWORDValue(HKEY regKey, DWORD* pdwValue);
131
132 /******************************************************************************
133  * These are the prototypes of the utility methods used to manage a shared menu
134  */
135 static void OLEMenu_Initialize(void);
136 static void OLEMenu_UnInitialize(void);
137 BOOL OLEMenu_InstallHooks( DWORD tid );
138 BOOL OLEMenu_UnInstallHooks( DWORD tid );
139 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid );
140 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos );
141 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor );
142 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam);
143 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam);
144
145 /******************************************************************************
146  * These are the prototypes of the OLE Clipboard initialization methods (in clipboard.c)
147  */
148 extern void OLEClipbrd_UnInitialize(void);
149 extern void OLEClipbrd_Initialize(void);
150
151 /******************************************************************************
152  * These are the prototypes of the utility methods used for OLE Drag n Drop
153  */
154 static void            OLEDD_Initialize(void);
155 static void            OLEDD_UnInitialize(void);
156 static void            OLEDD_InsertDropTarget(
157                          DropTargetNode* nodeToAdd);
158 static DropTargetNode* OLEDD_ExtractDropTarget(
159                          HWND hwndOfTarget);
160 static DropTargetNode* OLEDD_FindDropTarget(
161                          HWND hwndOfTarget);
162 static LRESULT WINAPI  OLEDD_DragTrackerWindowProc(
163                          HWND   hwnd,
164                          UINT   uMsg,
165                          WPARAM wParam,
166                          LPARAM   lParam);
167 static void OLEDD_TrackMouseMove(
168                          TrackerWindowInfo* trackerInfo,
169                          POINT            mousePos,
170                          DWORD              keyState);
171 static void OLEDD_TrackStateChange(
172                          TrackerWindowInfo* trackerInfo,
173                          POINT            mousePos,
174                          DWORD              keyState);
175 static DWORD OLEDD_GetButtonState(void);
176
177
178 /******************************************************************************
179  *              OleBuildVersion [OLE2.1]
180  *              OleBuildVersion [OLE32.@]
181  */
182 DWORD WINAPI OleBuildVersion(void)
183 {
184     TRACE("Returning version %d, build %d.\n", rmm, rup);
185     return (rmm<<16)+rup;
186 }
187
188 /***********************************************************************
189  *           OleInitialize       (OLE2.2)
190  *           OleInitialize       (OLE32.@)
191  */
192 HRESULT WINAPI OleInitialize(LPVOID reserved)
193 {
194   HRESULT hr;
195
196   TRACE("(%p)\n", reserved);
197
198   /*
199    * The first duty of the OleInitialize is to initialize the COM libraries.
200    */
201   hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
202
203   /*
204    * If the CoInitializeEx call failed, the OLE libraries can't be
205    * initialized.
206    */
207   if (FAILED(hr))
208     return hr;
209
210   /*
211    * Then, it has to initialize the OLE specific modules.
212    * This includes:
213    *     Clipboard
214    *     Drag and Drop
215    *     Object linking and Embedding
216    *     In-place activation
217    */
218   if (OLE_moduleLockCount==0)
219   {
220     /*
221      * Initialize the libraries.
222      */
223     TRACE("() - Initializing the OLE libraries\n");
224
225     /*
226      * OLE Clipboard
227      */
228     OLEClipbrd_Initialize();
229
230     /*
231      * Drag and Drop
232      */
233     OLEDD_Initialize();
234
235     /*
236      * OLE shared menu
237      */
238     OLEMenu_Initialize();
239   }
240
241   /*
242    * Then, we increase the lock count on the OLE module.
243    */
244   OLE_moduleLockCount++;
245
246   return hr;
247 }
248
249 /******************************************************************************
250  *              OleUninitialize [OLE2.3]
251  *              OleUninitialize [OLE32.@]
252  */
253 void WINAPI OleUninitialize(void)
254 {
255   TRACE("()\n");
256
257   /*
258    * Decrease the lock count on the OLE module.
259    */
260   OLE_moduleLockCount--;
261
262   /*
263    * If we hit the bottom of the lock stack, free the libraries.
264    */
265   if (OLE_moduleLockCount==0)
266   {
267     /*
268      * Actually free the libraries.
269      */
270     TRACE("() - Freeing the last reference count\n");
271
272     /*
273      * OLE Clipboard
274      */
275     OLEClipbrd_UnInitialize();
276
277     /*
278      * Drag and Drop
279      */
280     OLEDD_UnInitialize();
281
282     /*
283      * OLE shared menu
284      */
285     OLEMenu_UnInitialize();
286   }
287
288   /*
289    * Then, uninitialize the COM libraries.
290    */
291   CoUninitialize();
292 }
293
294 /******************************************************************************
295  *              OleInitializeWOW        [OLE32.@]
296  */
297 HRESULT WINAPI OleInitializeWOW(DWORD x, DWORD y) {
298         FIXME("(0x%08lx, 0x%08lx),stub!\n",x, y);
299         return 0;
300 }
301
302 /***********************************************************************
303  *           RegisterDragDrop (OLE32.@)
304  */
305 HRESULT WINAPI RegisterDragDrop(
306         HWND hwnd,
307         LPDROPTARGET pDropTarget)
308 {
309   DropTargetNode* dropTargetInfo;
310
311   TRACE("(%p,%p)\n", hwnd, pDropTarget);
312
313   if (!pDropTarget)
314     return E_INVALIDARG;
315   
316   /*
317    * First, check if the window is already registered.
318    */
319   dropTargetInfo = OLEDD_FindDropTarget(hwnd);
320
321   if (dropTargetInfo!=NULL)
322     return DRAGDROP_E_ALREADYREGISTERED;
323
324   /*
325    * If it's not there, we can add it. We first create a node for it.
326    */
327   dropTargetInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(DropTargetNode));
328
329   if (dropTargetInfo==NULL)
330     return E_OUTOFMEMORY;
331
332   dropTargetInfo->hwndTarget     = hwnd;
333   dropTargetInfo->prevDropTarget = NULL;
334   dropTargetInfo->nextDropTarget = NULL;
335
336   /*
337    * Don't forget that this is an interface pointer, need to nail it down since
338    * we keep a copy of it.
339    */
340   dropTargetInfo->dropTarget  = pDropTarget;
341   IDropTarget_AddRef(dropTargetInfo->dropTarget);
342
343   OLEDD_InsertDropTarget(dropTargetInfo);
344
345         return S_OK;
346 }
347
348 /***********************************************************************
349  *           RevokeDragDrop (OLE32.@)
350  */
351 HRESULT WINAPI RevokeDragDrop(
352         HWND hwnd)
353 {
354   DropTargetNode* dropTargetInfo;
355
356   TRACE("(%p)\n", hwnd);
357
358   /*
359    * First, check if the window is already registered.
360    */
361   dropTargetInfo = OLEDD_ExtractDropTarget(hwnd);
362
363   /*
364    * If it ain't in there, it's an error.
365    */
366   if (dropTargetInfo==NULL)
367     return DRAGDROP_E_NOTREGISTERED;
368
369   /*
370    * If it's in there, clean-up it's used memory and
371    * references
372    */
373   IDropTarget_Release(dropTargetInfo->dropTarget);
374   HeapFree(GetProcessHeap(), 0, dropTargetInfo);
375
376         return S_OK;
377 }
378
379 /***********************************************************************
380  *           OleRegGetUserType (OLE32.@)
381  *
382  * This implementation of OleRegGetUserType ignores the dwFormOfType
383  * parameter and always returns the full name of the object. This is
384  * not too bad since this is the case for many objects because of the
385  * way they are registered.
386  */
387 HRESULT WINAPI OleRegGetUserType(
388         REFCLSID clsid,
389         DWORD dwFormOfType,
390         LPOLESTR* pszUserType)
391 {
392   char    keyName[60];
393   DWORD   dwKeyType;
394   DWORD   cbData;
395   HKEY    clsidKey;
396   LONG    hres;
397   LPSTR   buffer;
398   HRESULT retVal;
399   /*
400    * Initialize the out parameter.
401    */
402   *pszUserType = NULL;
403
404   /*
405    * Build the key name we're looking for
406    */
407   sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
408            clsid->Data1, clsid->Data2, clsid->Data3,
409            clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
410            clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
411
412   TRACE("(%s, %ld, %p)\n", keyName, dwFormOfType, pszUserType);
413
414   /*
415    * Open the class id Key
416    */
417   hres = RegOpenKeyA(HKEY_CLASSES_ROOT,
418                      keyName,
419                      &clsidKey);
420
421   if (hres != ERROR_SUCCESS)
422     return REGDB_E_CLASSNOTREG;
423
424   /*
425    * Retrieve the size of the name string.
426    */
427   cbData = 0;
428
429   hres = RegQueryValueExA(clsidKey,
430                           "",
431                           NULL,
432                           &dwKeyType,
433                           NULL,
434                           &cbData);
435
436   if (hres!=ERROR_SUCCESS)
437   {
438     RegCloseKey(clsidKey);
439     return REGDB_E_READREGDB;
440   }
441
442   /*
443    * Allocate a buffer for the registry value.
444    */
445   *pszUserType = CoTaskMemAlloc(cbData*2);
446
447   if (*pszUserType==NULL)
448   {
449     RegCloseKey(clsidKey);
450     return E_OUTOFMEMORY;
451   }
452
453   buffer = HeapAlloc(GetProcessHeap(), 0, cbData);
454
455   if (buffer == NULL)
456   {
457     RegCloseKey(clsidKey);
458     CoTaskMemFree(*pszUserType);
459     *pszUserType=NULL;
460     return E_OUTOFMEMORY;
461   }
462
463   hres = RegQueryValueExA(clsidKey,
464                           "",
465                           NULL,
466                           &dwKeyType,
467                           (LPBYTE) buffer,
468                           &cbData);
469
470   RegCloseKey(clsidKey);
471
472
473   if (hres!=ERROR_SUCCESS)
474   {
475     CoTaskMemFree(*pszUserType);
476     *pszUserType=NULL;
477
478     retVal = REGDB_E_READREGDB;
479   }
480   else
481   {
482     MultiByteToWideChar( CP_ACP, 0, buffer, -1, *pszUserType, cbData /*FIXME*/ );
483     retVal = S_OK;
484   }
485   HeapFree(GetProcessHeap(), 0, buffer);
486
487   return retVal;
488 }
489
490 /***********************************************************************
491  * DoDragDrop [OLE32.@]
492  */
493 HRESULT WINAPI DoDragDrop (
494   IDataObject *pDataObject,  /* [in] ptr to the data obj           */
495   IDropSource* pDropSource,  /* [in] ptr to the source obj         */
496   DWORD       dwOKEffect,    /* [in] effects allowed by the source */
497   DWORD       *pdwEffect)    /* [out] ptr to effects of the source */
498 {
499   TrackerWindowInfo trackerInfo;
500   HWND            hwndTrackWindow;
501   MSG             msg;
502
503   TRACE("(DataObject %p, DropSource %p)\n", pDataObject, pDropSource);
504
505   /*
506    * Setup the drag n drop tracking window.
507    */
508   if (!IsValidInterface((LPUNKNOWN)pDropSource))
509       return E_INVALIDARG;
510
511   trackerInfo.dataObject        = pDataObject;
512   trackerInfo.dropSource        = pDropSource;
513   trackerInfo.dwOKEffect        = dwOKEffect;
514   trackerInfo.pdwEffect         = pdwEffect;
515   trackerInfo.trackingDone      = FALSE;
516   trackerInfo.escPressed        = FALSE;
517   trackerInfo.curDragTargetHWND = 0;
518   trackerInfo.curTargetHWND     = 0;
519   trackerInfo.curDragTarget     = 0;
520
521   hwndTrackWindow = CreateWindowA(OLEDD_DRAGTRACKERCLASS,
522                                     "TrackerWindow",
523                                     WS_POPUP,
524                                     CW_USEDEFAULT, CW_USEDEFAULT,
525                                     CW_USEDEFAULT, CW_USEDEFAULT,
526                                     0,
527                                     0,
528                                     0,
529                                     (LPVOID)&trackerInfo);
530
531   if (hwndTrackWindow!=0)
532   {
533     /*
534      * Capture the mouse input
535      */
536     SetCapture(hwndTrackWindow);
537
538     /*
539      * Pump messages. All mouse input should go the the capture window.
540      */
541     while (!trackerInfo.trackingDone && GetMessageA(&msg, 0, 0, 0) )
542     {
543       if ( (msg.message >= WM_KEYFIRST) &&
544            (msg.message <= WM_KEYLAST) )
545       {
546         /*
547          * When keyboard messages are sent to windows on this thread, we
548          * want to ignore notify the drop source that the state changed.
549          * in the case of the Escape key, we also notify the drop source
550          * we give it a special meaning.
551          */
552         if ( (msg.message==WM_KEYDOWN) &&
553              (msg.wParam==VK_ESCAPE) )
554         {
555           trackerInfo.escPressed = TRUE;
556         }
557
558         /*
559          * Notify the drop source.
560          */
561         OLEDD_TrackStateChange(&trackerInfo,
562                                msg.pt,
563                                OLEDD_GetButtonState());
564       }
565       else
566       {
567         /*
568          * Dispatch the messages only when it's not a keyboard message.
569          */
570         DispatchMessageA(&msg);
571       }
572     }
573
574     /*
575      * Destroy the temporary window.
576      */
577     DestroyWindow(hwndTrackWindow);
578
579     return trackerInfo.returnValue;
580   }
581
582   return E_FAIL;
583 }
584
585 /***********************************************************************
586  * OleQueryLinkFromData [OLE32.@]
587  */
588 HRESULT WINAPI OleQueryLinkFromData(
589   IDataObject* pSrcDataObject)
590 {
591   FIXME("(%p),stub!\n", pSrcDataObject);
592   return S_OK;
593 }
594
595 /***********************************************************************
596  * OleRegGetMiscStatus [OLE32.@]
597  */
598 HRESULT WINAPI OleRegGetMiscStatus(
599   REFCLSID clsid,
600   DWORD    dwAspect,
601   DWORD*   pdwStatus)
602 {
603   char    keyName[60];
604   HKEY    clsidKey;
605   HKEY    miscStatusKey;
606   HKEY    aspectKey;
607   LONG    result;
608
609   /*
610    * Initialize the out parameter.
611    */
612   *pdwStatus = 0;
613
614   /*
615    * Build the key name we're looking for
616    */
617   sprintf( keyName, "CLSID\\{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\\",
618            clsid->Data1, clsid->Data2, clsid->Data3,
619            clsid->Data4[0], clsid->Data4[1], clsid->Data4[2], clsid->Data4[3],
620            clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7] );
621
622   TRACE("(%s, %ld, %p)\n", keyName, dwAspect, pdwStatus);
623
624   /*
625    * Open the class id Key
626    */
627   result = RegOpenKeyA(HKEY_CLASSES_ROOT,
628                        keyName,
629                        &clsidKey);
630
631   if (result != ERROR_SUCCESS)
632     return REGDB_E_CLASSNOTREG;
633
634   /*
635    * Get the MiscStatus
636    */
637   result = RegOpenKeyA(clsidKey,
638                        "MiscStatus",
639                        &miscStatusKey);
640
641
642   if (result != ERROR_SUCCESS)
643   {
644     RegCloseKey(clsidKey);
645     return REGDB_E_READREGDB;
646   }
647
648   /*
649    * Read the default value
650    */
651   OLEUTL_ReadRegistryDWORDValue(miscStatusKey, pdwStatus);
652
653   /*
654    * Open the key specific to the requested aspect.
655    */
656   sprintf(keyName, "%ld", dwAspect);
657
658   result = RegOpenKeyA(miscStatusKey,
659                        keyName,
660                        &aspectKey);
661
662   if (result == ERROR_SUCCESS)
663   {
664     OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
665     RegCloseKey(aspectKey);
666   }
667
668   /*
669    * Cleanup
670    */
671   RegCloseKey(miscStatusKey);
672   RegCloseKey(clsidKey);
673
674   return S_OK;
675 }
676
677 /******************************************************************************
678  *              OleSetContainedObject        [OLE32.@]
679  */
680 HRESULT WINAPI OleSetContainedObject(
681   LPUNKNOWN pUnknown,
682   BOOL      fContained)
683 {
684   IRunnableObject* runnable = NULL;
685   HRESULT          hres;
686
687   TRACE("(%p,%x), stub!\n", pUnknown, fContained);
688
689   hres = IUnknown_QueryInterface(pUnknown,
690                                  &IID_IRunnableObject,
691                                  (void**)&runnable);
692
693   if (SUCCEEDED(hres))
694   {
695     hres = IRunnableObject_SetContainedObject(runnable, fContained);
696
697     IRunnableObject_Release(runnable);
698
699     return hres;
700   }
701
702   return S_OK;
703 }
704
705 /******************************************************************************
706  *              OleLoad        [OLE32.@]
707  */
708 HRESULT WINAPI OleLoad(
709   LPSTORAGE       pStg,
710   REFIID          riid,
711   LPOLECLIENTSITE pClientSite,
712   LPVOID*         ppvObj)
713 {
714   IPersistStorage* persistStorage = NULL;
715   IOleObject*      oleObject      = NULL;
716   STATSTG          storageInfo;
717   HRESULT          hres;
718
719   TRACE("(%p,%p,%p,%p)\n", pStg, riid, pClientSite, ppvObj);
720
721   /*
722    * TODO, Conversion ... OleDoAutoConvert
723    */
724
725   /*
726    * Get the class ID for the object.
727    */
728   hres = IStorage_Stat(pStg, &storageInfo, STATFLAG_NONAME);
729
730   /*
731    * Now, try and create the handler for the object
732    */
733   hres = CoCreateInstance(&storageInfo.clsid,
734                           NULL,
735                           CLSCTX_INPROC_HANDLER,
736                           &IID_IOleObject,
737                           (void**)&oleObject);
738
739   /*
740    * If that fails, as it will most times, load the default
741    * OLE handler.
742    */
743   if (FAILED(hres))
744   {
745     hres = OleCreateDefaultHandler(&storageInfo.clsid,
746                                    NULL,
747                                    &IID_IOleObject,
748                                    (void**)&oleObject);
749   }
750
751   /*
752    * If we couldn't find a handler... this is bad. Abort the whole thing.
753    */
754   if (FAILED(hres))
755     return hres;
756
757   /*
758    * Inform the new object of it's client site.
759    */
760   hres = IOleObject_SetClientSite(oleObject, pClientSite);
761
762   /*
763    * Initialize the object with it's IPersistStorage interface.
764    */
765   hres = IOleObject_QueryInterface(oleObject,
766                                    &IID_IPersistStorage,
767                                    (void**)&persistStorage);
768
769   if (SUCCEEDED(hres))
770   {
771     IPersistStorage_Load(persistStorage, pStg);
772
773     IPersistStorage_Release(persistStorage);
774     persistStorage = NULL;
775   }
776
777   /*
778    * Return the requested interface to the caller.
779    */
780   hres = IOleObject_QueryInterface(oleObject, riid, ppvObj);
781
782   /*
783    * Cleanup interfaces used internally
784    */
785   IOleObject_Release(oleObject);
786
787   return hres;
788 }
789
790 /***********************************************************************
791  *           OleSave     [OLE32.@]
792  */
793 HRESULT WINAPI OleSave(
794   LPPERSISTSTORAGE pPS,
795   LPSTORAGE        pStg,
796   BOOL             fSameAsLoad)
797 {
798   HRESULT hres;
799   CLSID   objectClass;
800
801   TRACE("(%p,%p,%x)\n", pPS, pStg, fSameAsLoad);
802
803   /*
804    * First, we transfer the class ID (if available)
805    */
806   hres = IPersistStorage_GetClassID(pPS, &objectClass);
807
808   if (SUCCEEDED(hres))
809   {
810     WriteClassStg(pStg, &objectClass);
811   }
812
813   /*
814    * Then, we ask the object to save itself to the
815    * storage. If it is successful, we commit the storage.
816    */
817   hres = IPersistStorage_Save(pPS, pStg, fSameAsLoad);
818
819   if (SUCCEEDED(hres))
820   {
821     IStorage_Commit(pStg,
822                     STGC_DEFAULT);
823   }
824
825   return hres;
826 }
827
828
829 /******************************************************************************
830  *              OleLockRunning        [OLE32.@]
831  */
832 HRESULT WINAPI OleLockRunning(LPUNKNOWN pUnknown, BOOL fLock, BOOL fLastUnlockCloses)
833 {
834   IRunnableObject* runnable = NULL;
835   HRESULT          hres;
836
837   TRACE("(%p,%x,%x)\n", pUnknown, fLock, fLastUnlockCloses);
838
839   hres = IUnknown_QueryInterface(pUnknown,
840                                  &IID_IRunnableObject,
841                                  (void**)&runnable);
842
843   if (SUCCEEDED(hres))
844   {
845     hres = IRunnableObject_LockRunning(runnable, fLock, fLastUnlockCloses);
846
847     IRunnableObject_Release(runnable);
848
849     return hres;
850   }
851   else
852     return E_INVALIDARG;
853 }
854
855
856 /**************************************************************************
857  * Internal methods to manage the shared OLE menu in response to the
858  * OLE***MenuDescriptor API
859  */
860
861 /***
862  * OLEMenu_Initialize()
863  *
864  * Initializes the OLEMENU data structures.
865  */
866 static void OLEMenu_Initialize()
867 {
868 }
869
870 /***
871  * OLEMenu_UnInitialize()
872  *
873  * Releases the OLEMENU data structures.
874  */
875 static void OLEMenu_UnInitialize()
876 {
877 }
878
879 /*************************************************************************
880  * OLEMenu_InstallHooks
881  * Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
882  *
883  * RETURNS: TRUE if message hooks were successfully installed
884  *          FALSE on failure
885  */
886 BOOL OLEMenu_InstallHooks( DWORD tid )
887 {
888   OleMenuHookItem *pHookItem = NULL;
889
890   /* Create an entry for the hook table */
891   if ( !(pHookItem = HeapAlloc(GetProcessHeap(), 0,
892                                sizeof(OleMenuHookItem)) ) )
893     return FALSE;
894
895   pHookItem->tid = tid;
896   pHookItem->hHeap = GetProcessHeap();
897
898   /* Install a thread scope message hook for WH_GETMESSAGE */
899   pHookItem->GetMsg_hHook = SetWindowsHookExA( WH_GETMESSAGE, OLEMenu_GetMsgProc,
900                                                0, GetCurrentThreadId() );
901   if ( !pHookItem->GetMsg_hHook )
902     goto CLEANUP;
903
904   /* Install a thread scope message hook for WH_CALLWNDPROC */
905   pHookItem->CallWndProc_hHook = SetWindowsHookExA( WH_CALLWNDPROC, OLEMenu_CallWndProc,
906                                                     0, GetCurrentThreadId() );
907   if ( !pHookItem->CallWndProc_hHook )
908     goto CLEANUP;
909
910   /* Insert the hook table entry */
911   pHookItem->next = hook_list;
912   hook_list = pHookItem;
913
914   return TRUE;
915
916 CLEANUP:
917   /* Unhook any hooks */
918   if ( pHookItem->GetMsg_hHook )
919     UnhookWindowsHookEx( pHookItem->GetMsg_hHook );
920   if ( pHookItem->CallWndProc_hHook )
921     UnhookWindowsHookEx( pHookItem->CallWndProc_hHook );
922   /* Release the hook table entry */
923   HeapFree(pHookItem->hHeap, 0, pHookItem );
924
925   return FALSE;
926 }
927
928 /*************************************************************************
929  * OLEMenu_UnInstallHooks
930  * UnInstall thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC
931  *
932  * RETURNS: TRUE if message hooks were successfully installed
933  *          FALSE on failure
934  */
935 BOOL OLEMenu_UnInstallHooks( DWORD tid )
936 {
937   OleMenuHookItem *pHookItem = NULL;
938   OleMenuHookItem **ppHook = &hook_list;
939
940   while (*ppHook)
941   {
942       if ((*ppHook)->tid == tid)
943       {
944           pHookItem = *ppHook;
945           *ppHook = pHookItem->next;
946           break;
947       }
948       ppHook = &(*ppHook)->next;
949   }
950   if (!pHookItem) return FALSE;
951
952   /* Uninstall the hooks installed for this thread */
953   if ( !UnhookWindowsHookEx( pHookItem->GetMsg_hHook ) )
954     goto CLEANUP;
955   if ( !UnhookWindowsHookEx( pHookItem->CallWndProc_hHook ) )
956     goto CLEANUP;
957
958   /* Release the hook table entry */
959   HeapFree(pHookItem->hHeap, 0, pHookItem );
960
961   return TRUE;
962
963 CLEANUP:
964   /* Release the hook table entry */
965   HeapFree(pHookItem->hHeap, 0, pHookItem );
966
967   return FALSE;
968 }
969
970 /*************************************************************************
971  * OLEMenu_IsHookInstalled
972  * Tests if OLEMenu hooks have been installed for a thread
973  *
974  * RETURNS: The pointer and index of the hook table entry for the tid
975  *          NULL and -1 for the index if no hooks were installed for this thread
976  */
977 OleMenuHookItem * OLEMenu_IsHookInstalled( DWORD tid )
978 {
979   OleMenuHookItem *pHookItem = NULL;
980
981   /* Do a simple linear search for an entry whose tid matches ours.
982    * We really need a map but efficiency is not a concern here. */
983   for (pHookItem = hook_list; pHookItem; pHookItem = pHookItem->next)
984   {
985     if ( tid == pHookItem->tid )
986       return pHookItem;
987   }
988
989   return NULL;
990 }
991
992 /***********************************************************************
993  *           OLEMenu_FindMainMenuIndex
994  *
995  * Used by OLEMenu API to find the top level group a menu item belongs to.
996  * On success pnPos contains the index of the item in the top level menu group
997  *
998  * RETURNS: TRUE if the ID was found, FALSE on failure
999  */
1000 static BOOL OLEMenu_FindMainMenuIndex( HMENU hMainMenu, HMENU hPopupMenu, UINT *pnPos )
1001 {
1002   UINT i, nItems;
1003
1004   nItems = GetMenuItemCount( hMainMenu );
1005
1006   for (i = 0; i < nItems; i++)
1007   {
1008     HMENU hsubmenu;
1009
1010     /*  Is the current item a submenu? */
1011     if ( (hsubmenu = GetSubMenu(hMainMenu, i)) )
1012     {
1013       /* If the handle is the same we're done */
1014       if ( hsubmenu == hPopupMenu )
1015       {
1016         if (pnPos)
1017           *pnPos = i;
1018         return TRUE;
1019       }
1020       /* Recursively search without updating pnPos */
1021       else if ( OLEMenu_FindMainMenuIndex( hsubmenu, hPopupMenu, NULL ) )
1022       {
1023         if (pnPos)
1024           *pnPos = i;
1025         return TRUE;
1026       }
1027     }
1028   }
1029
1030   return FALSE;
1031 }
1032
1033 /***********************************************************************
1034  *           OLEMenu_SetIsServerMenu
1035  *
1036  * Checks whether a popup menu belongs to a shared menu group which is
1037  * owned by the server, and sets the menu descriptor state accordingly.
1038  * All menu messages from these groups should be routed to the server.
1039  *
1040  * RETURNS: TRUE if the popup menu is part of a server owned group
1041  *          FALSE if the popup menu is part of a container owned group
1042  */
1043 BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDescriptor )
1044 {
1045   UINT nPos = 0, nWidth, i;
1046
1047   pOleMenuDescriptor->bIsServerItem = FALSE;
1048
1049   /* Don't bother searching if the popup is the combined menu itself */
1050   if ( hmenu == pOleMenuDescriptor->hmenuCombined )
1051     return FALSE;
1052
1053   /* Find the menu item index in the shared OLE menu that this item belongs to */
1054   if ( !OLEMenu_FindMainMenuIndex( pOleMenuDescriptor->hmenuCombined, hmenu,  &nPos ) )
1055     return FALSE;
1056
1057   /* The group widths array has counts for the number of elements
1058    * in the groups File, Edit, Container, Object, Window, Help.
1059    * The Edit, Object & Help groups belong to the server object
1060    * and the other three belong to the container.
1061    * Loop through the group widths and locate the group we are a member of.
1062    */
1063   for ( i = 0, nWidth = 0; i < 6; i++ )
1064   {
1065     nWidth += pOleMenuDescriptor->mgw.width[i];
1066     if ( nPos < nWidth )
1067     {
1068       /* Odd elements are server menu widths */
1069       pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
1070       break;
1071     }
1072   }
1073
1074   return pOleMenuDescriptor->bIsServerItem;
1075 }
1076
1077 /*************************************************************************
1078  * OLEMenu_CallWndProc
1079  * Thread scope WH_CALLWNDPROC hook proc filter function (callback)
1080  * This is invoked from a message hook installed in OleSetMenuDescriptor.
1081  */
1082 LRESULT CALLBACK OLEMenu_CallWndProc(INT code, WPARAM wParam, LPARAM lParam)
1083 {
1084   LPCWPSTRUCT pMsg = NULL;
1085   HOLEMENU hOleMenu = 0;
1086   OleMenuDescriptor *pOleMenuDescriptor = NULL;
1087   OleMenuHookItem *pHookItem = NULL;
1088   WORD fuFlags;
1089
1090   TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1091
1092   /* Check if we're being asked to process the message */
1093   if ( HC_ACTION != code )
1094     goto NEXTHOOK;
1095
1096   /* Retrieve the current message being dispatched from lParam */
1097   pMsg = (LPCWPSTRUCT)lParam;
1098
1099   /* Check if the message is destined for a window we are interested in:
1100    * If the window has an OLEMenu property we may need to dispatch
1101    * the menu message to its active objects window instead. */
1102
1103   hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1104   if ( !hOleMenu )
1105     goto NEXTHOOK;
1106
1107   /* Get the menu descriptor */
1108   pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1109   if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1110     goto NEXTHOOK;
1111
1112   /* Process menu messages */
1113   switch( pMsg->message )
1114   {
1115     case WM_INITMENU:
1116     {
1117       /* Reset the menu descriptor state */
1118       pOleMenuDescriptor->bIsServerItem = FALSE;
1119
1120       /* Send this message to the server as well */
1121       SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1122                   pMsg->message, pMsg->wParam, pMsg->lParam );
1123       goto NEXTHOOK;
1124     }
1125
1126     case WM_INITMENUPOPUP:
1127     {
1128       /* Save the state for whether this is a server owned menu */
1129       OLEMenu_SetIsServerMenu( (HMENU)pMsg->wParam, pOleMenuDescriptor );
1130       break;
1131     }
1132
1133     case WM_MENUSELECT:
1134     {
1135       fuFlags = HIWORD(pMsg->wParam);  /* Get flags */
1136       if ( fuFlags & MF_SYSMENU )
1137          goto NEXTHOOK;
1138
1139       /* Save the state for whether this is a server owned popup menu */
1140       else if ( fuFlags & MF_POPUP )
1141         OLEMenu_SetIsServerMenu( (HMENU)pMsg->lParam, pOleMenuDescriptor );
1142
1143       break;
1144     }
1145
1146     case WM_DRAWITEM:
1147     {
1148       LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT) pMsg->lParam;
1149       if ( pMsg->wParam != 0 || lpdis->CtlType != ODT_MENU )
1150         goto NEXTHOOK;  /* Not a menu message */
1151
1152       break;
1153     }
1154
1155     default:
1156       goto NEXTHOOK;
1157   }
1158
1159   /* If the message was for the server dispatch it accordingly */
1160   if ( pOleMenuDescriptor->bIsServerItem )
1161   {
1162     SendMessageA( pOleMenuDescriptor->hwndActiveObject,
1163                   pMsg->message, pMsg->wParam, pMsg->lParam );
1164   }
1165
1166 NEXTHOOK:
1167   if ( pOleMenuDescriptor )
1168     GlobalUnlock( hOleMenu );
1169
1170   /* Lookup the hook item for the current thread */
1171   if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1172   {
1173     /* This should never fail!! */
1174     WARN("could not retrieve hHook for current thread!\n" );
1175     return 0;
1176   }
1177
1178   /* Pass on the message to the next hooker */
1179   return CallNextHookEx( pHookItem->CallWndProc_hHook, code, wParam, lParam );
1180 }
1181
1182 /*************************************************************************
1183  * OLEMenu_GetMsgProc
1184  * Thread scope WH_GETMESSAGE hook proc filter function (callback)
1185  * This is invoked from a message hook installed in OleSetMenuDescriptor.
1186  */
1187 LRESULT CALLBACK OLEMenu_GetMsgProc(INT code, WPARAM wParam, LPARAM lParam)
1188 {
1189   LPMSG pMsg = NULL;
1190   HOLEMENU hOleMenu = 0;
1191   OleMenuDescriptor *pOleMenuDescriptor = NULL;
1192   OleMenuHookItem *pHookItem = NULL;
1193   WORD wCode;
1194
1195   TRACE("%i, %04x, %08x\n", code, wParam, (unsigned)lParam );
1196
1197   /* Check if we're being asked to process a  messages */
1198   if ( HC_ACTION != code )
1199     goto NEXTHOOK;
1200
1201   /* Retrieve the current message being dispatched from lParam */
1202   pMsg = (LPMSG)lParam;
1203
1204   /* Check if the message is destined for a window we are interested in:
1205    * If the window has an OLEMenu property we may need to dispatch
1206    * the menu message to its active objects window instead. */
1207
1208   hOleMenu = (HOLEMENU)GetPropA( pMsg->hwnd, "PROP_OLEMenuDescriptor" );
1209   if ( !hOleMenu )
1210     goto NEXTHOOK;
1211
1212   /* Process menu messages */
1213   switch( pMsg->message )
1214   {
1215     case WM_COMMAND:
1216     {
1217       wCode = HIWORD(pMsg->wParam);  /* Get notification code */
1218       if ( wCode )
1219         goto NEXTHOOK;  /* Not a menu message */
1220       break;
1221     }
1222     default:
1223       goto NEXTHOOK;
1224   }
1225
1226   /* Get the menu descriptor */
1227   pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1228   if ( !pOleMenuDescriptor ) /* Bad descriptor! */
1229     goto NEXTHOOK;
1230
1231   /* If the message was for the server dispatch it accordingly */
1232   if ( pOleMenuDescriptor->bIsServerItem )
1233   {
1234     /* Change the hWnd in the message to the active objects hWnd.
1235      * The message loop which reads this message will automatically
1236      * dispatch it to the embedded objects window. */
1237     pMsg->hwnd = pOleMenuDescriptor->hwndActiveObject;
1238   }
1239
1240 NEXTHOOK:
1241   if ( pOleMenuDescriptor )
1242     GlobalUnlock( hOleMenu );
1243
1244   /* Lookup the hook item for the current thread */
1245   if ( !( pHookItem = OLEMenu_IsHookInstalled( GetCurrentThreadId() ) ) )
1246   {
1247     /* This should never fail!! */
1248     WARN("could not retrieve hHook for current thread!\n" );
1249     return FALSE;
1250   }
1251
1252   /* Pass on the message to the next hooker */
1253   return CallNextHookEx( pHookItem->GetMsg_hHook, code, wParam, lParam );
1254 }
1255
1256 /***********************************************************************
1257  * OleCreateMenuDescriptor [OLE32.@]
1258  * Creates an OLE menu descriptor for OLE to use when dispatching
1259  * menu messages and commands.
1260  *
1261  * PARAMS:
1262  *    hmenuCombined  -  Handle to the objects combined menu
1263  *    lpMenuWidths   -  Pointer to array of 6 LONG's indicating menus per group
1264  *
1265  */
1266 HOLEMENU WINAPI OleCreateMenuDescriptor(
1267   HMENU                hmenuCombined,
1268   LPOLEMENUGROUPWIDTHS lpMenuWidths)
1269 {
1270   HOLEMENU hOleMenu;
1271   OleMenuDescriptor *pOleMenuDescriptor;
1272   int i;
1273
1274   if ( !hmenuCombined || !lpMenuWidths )
1275     return 0;
1276
1277   /* Create an OLE menu descriptor */
1278   if ( !(hOleMenu = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT,
1279                                 sizeof(OleMenuDescriptor) ) ) )
1280   return 0;
1281
1282   pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1283   if ( !pOleMenuDescriptor )
1284     return 0;
1285
1286   /* Initialize menu group widths and hmenu */
1287   for ( i = 0; i < 6; i++ )
1288     pOleMenuDescriptor->mgw.width[i] = lpMenuWidths->width[i];
1289
1290   pOleMenuDescriptor->hmenuCombined = hmenuCombined;
1291   pOleMenuDescriptor->bIsServerItem = FALSE;
1292   GlobalUnlock( hOleMenu );
1293
1294   return hOleMenu;
1295 }
1296
1297 /***********************************************************************
1298  * OleDestroyMenuDescriptor [OLE32.@]
1299  * Destroy the shared menu descriptor
1300  */
1301 HRESULT WINAPI OleDestroyMenuDescriptor(
1302   HOLEMENU hmenuDescriptor)
1303 {
1304   if ( hmenuDescriptor )
1305     GlobalFree( hmenuDescriptor );
1306         return S_OK;
1307 }
1308
1309 /***********************************************************************
1310  * OleSetMenuDescriptor [OLE32.@]
1311  * Installs or removes OLE dispatching code for the containers frame window
1312  * FIXME: The lpFrame and lpActiveObject parameters are currently ignored
1313  * OLE should install context sensitive help F1 filtering for the app when
1314  * these are non null.
1315  *
1316  * PARAMS:
1317  *     hOleMenu         Handle to composite menu descriptor
1318  *     hwndFrame        Handle to containers frame window
1319  *     hwndActiveObject Handle to objects in-place activation window
1320  *     lpFrame          Pointer to IOleInPlaceFrame on containers window
1321  *     lpActiveObject   Pointer to IOleInPlaceActiveObject on active in-place object
1322  *
1323  * RETURNS:
1324  *      S_OK                               - menu installed correctly
1325  *      E_FAIL, E_INVALIDARG, E_UNEXPECTED - failure
1326  */
1327 HRESULT WINAPI OleSetMenuDescriptor(
1328   HOLEMENU               hOleMenu,
1329   HWND                   hwndFrame,
1330   HWND                   hwndActiveObject,
1331   LPOLEINPLACEFRAME        lpFrame,
1332   LPOLEINPLACEACTIVEOBJECT lpActiveObject)
1333 {
1334   OleMenuDescriptor *pOleMenuDescriptor = NULL;
1335
1336   /* Check args */
1337   if ( !hwndFrame || (hOleMenu && !hwndActiveObject) )
1338     return E_INVALIDARG;
1339
1340   if ( lpFrame || lpActiveObject )
1341   {
1342      FIXME("(%p, %p, %p, %p, %p), Context sensitive help filtering not implemented!\n",
1343         hOleMenu,
1344         hwndFrame,
1345         hwndActiveObject,
1346         lpFrame,
1347         lpActiveObject);
1348   }
1349
1350   /* Set up a message hook to intercept the containers frame window messages.
1351    * The message filter is responsible for dispatching menu messages from the
1352    * shared menu which are intended for the object.
1353    */
1354
1355   if ( hOleMenu )  /* Want to install dispatching code */
1356   {
1357     /* If OLEMenu hooks are already installed for this thread, fail
1358      * Note: This effectively means that OleSetMenuDescriptor cannot
1359      * be called twice in succession on the same frame window
1360      * without first calling it with a null hOleMenu to uninstall */
1361     if ( OLEMenu_IsHookInstalled( GetCurrentThreadId() ) )
1362   return E_FAIL;
1363
1364     /* Get the menu descriptor */
1365     pOleMenuDescriptor = (OleMenuDescriptor *) GlobalLock( hOleMenu );
1366     if ( !pOleMenuDescriptor )
1367       return E_UNEXPECTED;
1368
1369     /* Update the menu descriptor */
1370     pOleMenuDescriptor->hwndFrame = hwndFrame;
1371     pOleMenuDescriptor->hwndActiveObject = hwndActiveObject;
1372
1373     GlobalUnlock( hOleMenu );
1374     pOleMenuDescriptor = NULL;
1375
1376     /* Add a menu descriptor windows property to the frame window */
1377     SetPropA( hwndFrame, "PROP_OLEMenuDescriptor", hOleMenu );
1378
1379     /* Install thread scope message hooks for WH_GETMESSAGE and WH_CALLWNDPROC */
1380     if ( !OLEMenu_InstallHooks( GetCurrentThreadId() ) )
1381       return E_FAIL;
1382   }
1383   else  /* Want to uninstall dispatching code */
1384   {
1385     /* Uninstall the hooks */
1386     if ( !OLEMenu_UnInstallHooks( GetCurrentThreadId() ) )
1387       return E_FAIL;
1388
1389     /* Remove the menu descriptor property from the frame window */
1390     RemovePropA( hwndFrame, "PROP_OLEMenuDescriptor" );
1391   }
1392
1393   return S_OK;
1394 }
1395
1396 /******************************************************************************
1397  *              IsAccelerator        [OLE32.@]
1398  * Mostly copied from controls/menu.c TranslateAccelerator implementation
1399  */
1400 BOOL WINAPI IsAccelerator(HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD* lpwCmd)
1401 {
1402     LPACCEL lpAccelTbl;
1403     int i;
1404
1405     if(!lpMsg) return FALSE;
1406     if (!hAccel)
1407     {
1408         WARN_(accel)("NULL accel handle\n");
1409         return FALSE;
1410     }
1411     if((lpMsg->message != WM_KEYDOWN &&
1412         lpMsg->message != WM_KEYUP &&
1413         lpMsg->message != WM_SYSKEYDOWN &&
1414         lpMsg->message != WM_SYSKEYUP &&
1415         lpMsg->message != WM_CHAR)) return FALSE;
1416     lpAccelTbl = HeapAlloc(GetProcessHeap(), 0, cAccelEntries * sizeof(ACCEL));
1417     if (NULL == lpAccelTbl)
1418     {
1419         return FALSE;
1420     }
1421     if (CopyAcceleratorTableW(hAccel, lpAccelTbl, cAccelEntries) != cAccelEntries)
1422     {
1423         WARN_(accel)("CopyAcceleratorTableW failed\n");
1424         HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1425         return FALSE;
1426     }
1427
1428     TRACE_(accel)("hAccel=%p, cAccelEntries=%d,"
1429                 "msg->hwnd=%p, msg->message=%04x, wParam=%08x, lParam=%08lx\n",
1430                 hAccel, cAccelEntries,
1431                 lpMsg->hwnd, lpMsg->message, lpMsg->wParam, lpMsg->lParam);
1432     for(i = 0; i < cAccelEntries; i++)
1433     {
1434         if(lpAccelTbl[i].key != lpMsg->wParam)
1435             continue;
1436
1437         if(lpMsg->message == WM_CHAR)
1438         {
1439             if(!(lpAccelTbl[i].fVirt & FALT) && !(lpAccelTbl[i].fVirt & FVIRTKEY))
1440             {
1441                 TRACE_(accel)("found accel for WM_CHAR: ('%c')\n", lpMsg->wParam & 0xff);
1442                 goto found;
1443             }
1444         }
1445         else
1446         {
1447             if(lpAccelTbl[i].fVirt & FVIRTKEY)
1448             {
1449                 INT mask = 0;
1450                 TRACE_(accel)("found accel for virt_key %04x (scan %04x)\n",
1451                                 lpMsg->wParam, HIWORD(lpMsg->lParam) & 0xff);
1452                 if(GetKeyState(VK_SHIFT) & 0x8000) mask |= FSHIFT;
1453                 if(GetKeyState(VK_CONTROL) & 0x8000) mask |= FCONTROL;
1454                 if(GetKeyState(VK_MENU) & 0x8000) mask |= FALT;
1455                 if(mask == (lpAccelTbl[i].fVirt & (FSHIFT | FCONTROL | FALT))) goto found;
1456                 TRACE_(accel)("incorrect SHIFT/CTRL/ALT-state\n");
1457             }
1458             else
1459             {
1460                 if(!(lpMsg->lParam & 0x01000000))  /* no special_key */
1461                 {
1462                     if((lpAccelTbl[i].fVirt & FALT) && (lpMsg->lParam & 0x20000000))
1463                     {                                                  /* ^^ ALT pressed */
1464                         TRACE_(accel)("found accel for Alt-%c\n", lpMsg->wParam & 0xff);
1465                         goto found;
1466                     }
1467                 }
1468             }
1469         }
1470     }
1471
1472     WARN_(accel)("couldn't translate accelerator key\n");
1473     HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1474     return FALSE;
1475
1476 found:
1477     if(lpwCmd) *lpwCmd = lpAccelTbl[i].cmd;
1478     HeapFree(GetProcessHeap(), 0, lpAccelTbl);
1479     return TRUE;
1480 }
1481
1482 /***********************************************************************
1483  * ReleaseStgMedium [OLE32.@]
1484  */
1485 void WINAPI ReleaseStgMedium(
1486   STGMEDIUM* pmedium)
1487 {
1488   switch (pmedium->tymed)
1489   {
1490     case TYMED_HGLOBAL:
1491     {
1492       if ( (pmedium->pUnkForRelease==0) &&
1493            (pmedium->u.hGlobal!=0) )
1494         GlobalFree(pmedium->u.hGlobal);
1495       break;
1496     }
1497     case TYMED_FILE:
1498     {
1499       if (pmedium->u.lpszFileName!=0)
1500       {
1501         if (pmedium->pUnkForRelease==0)
1502         {
1503           DeleteFileW(pmedium->u.lpszFileName);
1504         }
1505
1506         CoTaskMemFree(pmedium->u.lpszFileName);
1507       }
1508       break;
1509     }
1510     case TYMED_ISTREAM:
1511     {
1512       if (pmedium->u.pstm!=0)
1513       {
1514         IStream_Release(pmedium->u.pstm);
1515       }
1516       break;
1517     }
1518     case TYMED_ISTORAGE:
1519     {
1520       if (pmedium->u.pstg!=0)
1521       {
1522         IStorage_Release(pmedium->u.pstg);
1523       }
1524       break;
1525     }
1526     case TYMED_GDI:
1527     {
1528       if ( (pmedium->pUnkForRelease==0) &&
1529            (pmedium->u.hBitmap!=0) )
1530         DeleteObject(pmedium->u.hBitmap);
1531       break;
1532     }
1533     case TYMED_MFPICT:
1534     {
1535       if ( (pmedium->pUnkForRelease==0) &&
1536            (pmedium->u.hMetaFilePict!=0) )
1537       {
1538         LPMETAFILEPICT pMP = GlobalLock(pmedium->u.hMetaFilePict);
1539         DeleteMetaFile(pMP->hMF);
1540         GlobalUnlock(pmedium->u.hMetaFilePict);
1541         GlobalFree(pmedium->u.hMetaFilePict);
1542       }
1543       break;
1544     }
1545     case TYMED_ENHMF:
1546     {
1547       if ( (pmedium->pUnkForRelease==0) &&
1548            (pmedium->u.hEnhMetaFile!=0) )
1549       {
1550         DeleteEnhMetaFile(pmedium->u.hEnhMetaFile);
1551       }
1552       break;
1553     }
1554     case TYMED_NULL:
1555     default:
1556       break;
1557   }
1558   pmedium->tymed=TYMED_NULL;
1559
1560   /*
1561    * After cleaning up, the unknown is released
1562    */
1563   if (pmedium->pUnkForRelease!=0)
1564   {
1565     IUnknown_Release(pmedium->pUnkForRelease);
1566     pmedium->pUnkForRelease = 0;
1567   }
1568 }
1569
1570 /***
1571  * OLEDD_Initialize()
1572  *
1573  * Initializes the OLE drag and drop data structures.
1574  */
1575 static void OLEDD_Initialize()
1576 {
1577     WNDCLASSA wndClass;
1578
1579     ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1580     wndClass.style         = CS_GLOBALCLASS;
1581     wndClass.lpfnWndProc   = OLEDD_DragTrackerWindowProc;
1582     wndClass.cbClsExtra    = 0;
1583     wndClass.cbWndExtra    = sizeof(TrackerWindowInfo*);
1584     wndClass.hCursor       = 0;
1585     wndClass.hbrBackground = 0;
1586     wndClass.lpszClassName = OLEDD_DRAGTRACKERCLASS;
1587
1588     RegisterClassA (&wndClass);
1589 }
1590
1591 /***
1592  * OLEDD_UnInitialize()
1593  *
1594  * Releases the OLE drag and drop data structures.
1595  */
1596 static void OLEDD_UnInitialize()
1597 {
1598   /*
1599    * Simply empty the list.
1600    */
1601   while (targetListHead!=NULL)
1602   {
1603     RevokeDragDrop(targetListHead->hwndTarget);
1604   }
1605 }
1606
1607 /***
1608  * OLEDD_InsertDropTarget()
1609  *
1610  * Insert the target node in the tree.
1611  */
1612 static void OLEDD_InsertDropTarget(DropTargetNode* nodeToAdd)
1613 {
1614   DropTargetNode*  curNode;
1615   DropTargetNode** parentNodeLink;
1616
1617   /*
1618    * Iterate the tree to find the insertion point.
1619    */
1620   curNode        = targetListHead;
1621   parentNodeLink = &targetListHead;
1622
1623   while (curNode!=NULL)
1624   {
1625     if (nodeToAdd->hwndTarget<curNode->hwndTarget)
1626     {
1627       /*
1628        * If the node we want to add has a smaller HWND, go left
1629        */
1630       parentNodeLink = &curNode->prevDropTarget;
1631       curNode        =  curNode->prevDropTarget;
1632     }
1633     else if (nodeToAdd->hwndTarget>curNode->hwndTarget)
1634     {
1635       /*
1636        * If the node we want to add has a larger HWND, go right
1637        */
1638       parentNodeLink = &curNode->nextDropTarget;
1639       curNode        =  curNode->nextDropTarget;
1640     }
1641     else
1642     {
1643       /*
1644        * The item was found in the list. It shouldn't have been there
1645        */
1646       assert(FALSE);
1647       return;
1648     }
1649   }
1650
1651   /*
1652    * If we get here, we have found a spot for our item. The parentNodeLink
1653    * pointer points to the pointer that we have to modify.
1654    * The curNode should be NULL. We just have to establish the link and Voila!
1655    */
1656   assert(curNode==NULL);
1657   assert(parentNodeLink!=NULL);
1658   assert(*parentNodeLink==NULL);
1659
1660   *parentNodeLink=nodeToAdd;
1661 }
1662
1663 /***
1664  * OLEDD_ExtractDropTarget()
1665  *
1666  * Removes the target node from the tree.
1667  */
1668 static DropTargetNode* OLEDD_ExtractDropTarget(HWND hwndOfTarget)
1669 {
1670   DropTargetNode*  curNode;
1671   DropTargetNode** parentNodeLink;
1672
1673   /*
1674    * Iterate the tree to find the insertion point.
1675    */
1676   curNode        = targetListHead;
1677   parentNodeLink = &targetListHead;
1678
1679   while (curNode!=NULL)
1680   {
1681     if (hwndOfTarget<curNode->hwndTarget)
1682     {
1683       /*
1684        * If the node we want to add has a smaller HWND, go left
1685        */
1686       parentNodeLink = &curNode->prevDropTarget;
1687       curNode        =  curNode->prevDropTarget;
1688     }
1689     else if (hwndOfTarget>curNode->hwndTarget)
1690     {
1691       /*
1692        * If the node we want to add has a larger HWND, go right
1693        */
1694       parentNodeLink = &curNode->nextDropTarget;
1695       curNode        =  curNode->nextDropTarget;
1696     }
1697     else
1698     {
1699       /*
1700        * The item was found in the list. Detach it from it's parent and
1701        * re-insert it's kids in the tree.
1702        */
1703       assert(parentNodeLink!=NULL);
1704       assert(*parentNodeLink==curNode);
1705
1706       /*
1707        * We arbitrately re-attach the left sub-tree to the parent.
1708        */
1709       *parentNodeLink = curNode->prevDropTarget;
1710
1711       /*
1712        * And we re-insert the right subtree
1713        */
1714       if (curNode->nextDropTarget!=NULL)
1715       {
1716         OLEDD_InsertDropTarget(curNode->nextDropTarget);
1717       }
1718
1719       /*
1720        * The node we found is still a valid node once we complete
1721        * the unlinking of the kids.
1722        */
1723       curNode->nextDropTarget=NULL;
1724       curNode->prevDropTarget=NULL;
1725
1726       return curNode;
1727     }
1728   }
1729
1730   /*
1731    * If we get here, the node is not in the tree
1732    */
1733   return NULL;
1734 }
1735
1736 /***
1737  * OLEDD_FindDropTarget()
1738  *
1739  * Finds information about the drop target.
1740  */
1741 static DropTargetNode* OLEDD_FindDropTarget(HWND hwndOfTarget)
1742 {
1743   DropTargetNode*  curNode;
1744
1745   /*
1746    * Iterate the tree to find the HWND value.
1747    */
1748   curNode        = targetListHead;
1749
1750   while (curNode!=NULL)
1751   {
1752     if (hwndOfTarget<curNode->hwndTarget)
1753     {
1754       /*
1755        * If the node we want to add has a smaller HWND, go left
1756        */
1757       curNode =  curNode->prevDropTarget;
1758     }
1759     else if (hwndOfTarget>curNode->hwndTarget)
1760     {
1761       /*
1762        * If the node we want to add has a larger HWND, go right
1763        */
1764       curNode =  curNode->nextDropTarget;
1765     }
1766     else
1767     {
1768       /*
1769        * The item was found in the list.
1770        */
1771       return curNode;
1772     }
1773   }
1774
1775   /*
1776    * If we get here, the item is not in the list
1777    */
1778   return NULL;
1779 }
1780
1781 /***
1782  * OLEDD_DragTrackerWindowProc()
1783  *
1784  * This method is the WindowProcedure of the drag n drop tracking
1785  * window. During a drag n Drop operation, an invisible window is created
1786  * to receive the user input and act upon it. This procedure is in charge
1787  * of this behavior.
1788  */
1789 static LRESULT WINAPI OLEDD_DragTrackerWindowProc(
1790                          HWND   hwnd,
1791                          UINT   uMsg,
1792                          WPARAM wParam,
1793                          LPARAM   lParam)
1794 {
1795   switch (uMsg)
1796   {
1797     case WM_CREATE:
1798     {
1799       LPCREATESTRUCTA createStruct = (LPCREATESTRUCTA)lParam;
1800
1801       SetWindowLongA(hwnd, 0, (LONG)createStruct->lpCreateParams);
1802
1803
1804       break;
1805     }
1806     case WM_MOUSEMOVE:
1807     {
1808       TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1809       POINT            mousePos;
1810
1811       /*
1812        * Get the current mouse position in screen coordinates.
1813        */
1814       mousePos.x = LOWORD(lParam);
1815       mousePos.y = HIWORD(lParam);
1816       ClientToScreen(hwnd, &mousePos);
1817
1818       /*
1819        * Track the movement of the mouse.
1820        */
1821       OLEDD_TrackMouseMove(trackerInfo, mousePos, wParam);
1822
1823       break;
1824     }
1825     case WM_LBUTTONUP:
1826     case WM_MBUTTONUP:
1827     case WM_RBUTTONUP:
1828     case WM_LBUTTONDOWN:
1829     case WM_MBUTTONDOWN:
1830     case WM_RBUTTONDOWN:
1831     {
1832       TrackerWindowInfo* trackerInfo = (TrackerWindowInfo*)GetWindowLongA(hwnd, 0);
1833       POINT            mousePos;
1834
1835       /*
1836        * Get the current mouse position in screen coordinates.
1837        */
1838       mousePos.x = LOWORD(lParam);
1839       mousePos.y = HIWORD(lParam);
1840       ClientToScreen(hwnd, &mousePos);
1841
1842       /*
1843        * Notify everyone that the button state changed
1844        * TODO: Check if the "escape" key was pressed.
1845        */
1846       OLEDD_TrackStateChange(trackerInfo, mousePos, wParam);
1847
1848       break;
1849     }
1850   }
1851
1852   /*
1853    * This is a window proc after all. Let's call the default.
1854    */
1855   return DefWindowProcA (hwnd, uMsg, wParam, lParam);
1856 }
1857
1858 /***
1859  * OLEDD_TrackMouseMove()
1860  *
1861  * This method is invoked while a drag and drop operation is in effect.
1862  * it will generate the appropriate callbacks in the drop source
1863  * and drop target. It will also provide the expected feedback to
1864  * the user.
1865  *
1866  * params:
1867  *    trackerInfo - Pointer to the structure identifying the
1868  *                  drag & drop operation that is currently
1869  *                  active.
1870  *    mousePos    - Current position of the mouse in screen
1871  *                  coordinates.
1872  *    keyState    - Contains the state of the shift keys and the
1873  *                  mouse buttons (MK_LBUTTON and the like)
1874  */
1875 static void OLEDD_TrackMouseMove(
1876   TrackerWindowInfo* trackerInfo,
1877   POINT            mousePos,
1878   DWORD              keyState)
1879 {
1880   HWND   hwndNewTarget = 0;
1881   HRESULT  hr = S_OK;
1882
1883   /*
1884    * Get the handle of the window under the mouse
1885    */
1886   hwndNewTarget = WindowFromPoint(mousePos);
1887
1888   /*
1889    * Every time, we re-initialize the effects passed to the
1890    * IDropTarget to the effects allowed by the source.
1891    */
1892   *trackerInfo->pdwEffect = trackerInfo->dwOKEffect;
1893
1894   /*
1895    * If we are hovering over the same target as before, send the
1896    * DragOver notification
1897    */
1898   if ( (trackerInfo->curDragTarget != 0) &&
1899        (trackerInfo->curTargetHWND == hwndNewTarget) )
1900   {
1901     POINTL  mousePosParam;
1902
1903     /*
1904      * The documentation tells me that the coordinate should be in the target
1905      * window's coordinate space. However, the tests I made tell me the
1906      * coordinates should be in screen coordinates.
1907      */
1908     mousePosParam.x = mousePos.x;
1909     mousePosParam.y = mousePos.y;
1910
1911     IDropTarget_DragOver(trackerInfo->curDragTarget,
1912                          keyState,
1913                          mousePosParam,
1914                          trackerInfo->pdwEffect);
1915   }
1916   else
1917   {
1918     DropTargetNode* newDropTargetNode = 0;
1919
1920     /*
1921      * If we changed window, we have to notify our old target and check for
1922      * the new one.
1923      */
1924     if (trackerInfo->curDragTarget!=0)
1925     {
1926       IDropTarget_DragLeave(trackerInfo->curDragTarget);
1927     }
1928
1929     /*
1930      * Make sure we're hovering over a window.
1931      */
1932     if (hwndNewTarget!=0)
1933     {
1934       /*
1935        * Find-out if there is a drag target under the mouse
1936        */
1937       HWND nexttar = hwndNewTarget;
1938       trackerInfo->curTargetHWND = hwndNewTarget;
1939
1940       do {
1941         newDropTargetNode = OLEDD_FindDropTarget(nexttar);
1942       } while (!newDropTargetNode && (nexttar = GetParent(nexttar)) != 0);
1943       if(nexttar) hwndNewTarget = nexttar;
1944
1945       trackerInfo->curDragTargetHWND = hwndNewTarget;
1946       trackerInfo->curDragTarget     = newDropTargetNode ? newDropTargetNode->dropTarget : 0;
1947
1948       /*
1949        * If there is, notify it that we just dragged-in
1950        */
1951       if (trackerInfo->curDragTarget!=0)
1952       {
1953         POINTL  mousePosParam;
1954
1955         /*
1956          * The documentation tells me that the coordinate should be in the target
1957          * window's coordinate space. However, the tests I made tell me the
1958          * coordinates should be in screen coordinates.
1959          */
1960         mousePosParam.x = mousePos.x;
1961         mousePosParam.y = mousePos.y;
1962
1963         IDropTarget_DragEnter(trackerInfo->curDragTarget,
1964                               trackerInfo->dataObject,
1965                               keyState,
1966                               mousePosParam,
1967                               trackerInfo->pdwEffect);
1968       }
1969     }
1970     else
1971     {
1972       /*
1973        * The mouse is not over a window so we don't track anything.
1974        */
1975       trackerInfo->curDragTargetHWND = 0;
1976       trackerInfo->curTargetHWND     = 0;
1977       trackerInfo->curDragTarget     = 0;
1978     }
1979   }
1980
1981   /*
1982    * Now that we have done that, we have to tell the source to give
1983    * us feedback on the work being done by the target.  If we don't
1984    * have a target, simulate no effect.
1985    */
1986   if (trackerInfo->curDragTarget==0)
1987   {
1988     *trackerInfo->pdwEffect = DROPEFFECT_NONE;
1989   }
1990
1991   hr = IDropSource_GiveFeedback(trackerInfo->dropSource,
1992                                 *trackerInfo->pdwEffect);
1993
1994   /*
1995    * When we ask for feedback from the drop source, sometimes it will
1996    * do all the necessary work and sometimes it will not handle it
1997    * when that's the case, we must display the standard drag and drop
1998    * cursors.
1999    */
2000   if (hr==DRAGDROP_S_USEDEFAULTCURSORS)
2001   {
2002     if (*trackerInfo->pdwEffect & DROPEFFECT_MOVE)
2003     {
2004       SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(1)));
2005     }
2006     else if (*trackerInfo->pdwEffect & DROPEFFECT_COPY)
2007     {
2008       SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(2)));
2009     }
2010     else if (*trackerInfo->pdwEffect & DROPEFFECT_LINK)
2011     {
2012       SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(3)));
2013     }
2014     else
2015     {
2016       SetCursor(LoadCursorA(OLE32_hInstance, MAKEINTRESOURCEA(0)));
2017     }
2018   }
2019 }
2020
2021 /***
2022  * OLEDD_TrackStateChange()
2023  *
2024  * This method is invoked while a drag and drop operation is in effect.
2025  * It is used to notify the drop target/drop source callbacks when
2026  * the state of the keyboard or mouse button change.
2027  *
2028  * params:
2029  *    trackerInfo - Pointer to the structure identifying the
2030  *                  drag & drop operation that is currently
2031  *                  active.
2032  *    mousePos    - Current position of the mouse in screen
2033  *                  coordinates.
2034  *    keyState    - Contains the state of the shift keys and the
2035  *                  mouse buttons (MK_LBUTTON and the like)
2036  */
2037 static void OLEDD_TrackStateChange(
2038   TrackerWindowInfo* trackerInfo,
2039   POINT            mousePos,
2040   DWORD              keyState)
2041 {
2042   /*
2043    * Ask the drop source what to do with the operation.
2044    */
2045   trackerInfo->returnValue = IDropSource_QueryContinueDrag(
2046                                trackerInfo->dropSource,
2047                                trackerInfo->escPressed,
2048                                keyState);
2049
2050   /*
2051    * All the return valued will stop the operation except the S_OK
2052    * return value.
2053    */
2054   if (trackerInfo->returnValue!=S_OK)
2055   {
2056     /*
2057      * Make sure the message loop in DoDragDrop stops
2058      */
2059     trackerInfo->trackingDone = TRUE;
2060
2061     /*
2062      * Release the mouse in case the drop target decides to show a popup
2063      * or a menu or something.
2064      */
2065     ReleaseCapture();
2066
2067     /*
2068      * If we end-up over a target, drop the object in the target or
2069      * inform the target that the operation was cancelled.
2070      */
2071     if (trackerInfo->curDragTarget!=0)
2072     {
2073       switch (trackerInfo->returnValue)
2074       {
2075         /*
2076          * If the source wants us to complete the operation, we tell
2077          * the drop target that we just dropped the object in it.
2078          */
2079         case DRAGDROP_S_DROP:
2080         {
2081           POINTL  mousePosParam;
2082
2083           /*
2084            * The documentation tells me that the coordinate should be
2085            * in the target window's coordinate space. However, the tests
2086            * I made tell me the coordinates should be in screen coordinates.
2087            */
2088           mousePosParam.x = mousePos.x;
2089           mousePosParam.y = mousePos.y;
2090
2091           IDropTarget_Drop(trackerInfo->curDragTarget,
2092                            trackerInfo->dataObject,
2093                            keyState,
2094                            mousePosParam,
2095                            trackerInfo->pdwEffect);
2096           break;
2097         }
2098         /*
2099          * If the source told us that we should cancel, fool the drop
2100          * target by telling it that the mouse left it's window.
2101          * Also set the drop effect to "NONE" in case the application
2102          * ignores the result of DoDragDrop.
2103          */
2104         case DRAGDROP_S_CANCEL:
2105           IDropTarget_DragLeave(trackerInfo->curDragTarget);
2106           *trackerInfo->pdwEffect = DROPEFFECT_NONE;
2107           break;
2108       }
2109     }
2110   }
2111 }
2112
2113 /***
2114  * OLEDD_GetButtonState()
2115  *
2116  * This method will use the current state of the keyboard to build
2117  * a button state mask equivalent to the one passed in the
2118  * WM_MOUSEMOVE wParam.
2119  */
2120 static DWORD OLEDD_GetButtonState()
2121 {
2122   BYTE  keyboardState[256];
2123   DWORD keyMask = 0;
2124
2125   GetKeyboardState(keyboardState);
2126
2127   if ( (keyboardState[VK_SHIFT] & 0x80) !=0)
2128     keyMask |= MK_SHIFT;
2129
2130   if ( (keyboardState[VK_CONTROL] & 0x80) !=0)
2131     keyMask |= MK_CONTROL;
2132
2133   if ( (keyboardState[VK_LBUTTON] & 0x80) !=0)
2134     keyMask |= MK_LBUTTON;
2135
2136   if ( (keyboardState[VK_RBUTTON] & 0x80) !=0)
2137     keyMask |= MK_RBUTTON;
2138
2139   if ( (keyboardState[VK_MBUTTON] & 0x80) !=0)
2140     keyMask |= MK_MBUTTON;
2141
2142   return keyMask;
2143 }
2144
2145 /***
2146  * OLEDD_GetButtonState()
2147  *
2148  * This method will read the default value of the registry key in
2149  * parameter and extract a DWORD value from it. The registry key value
2150  * can be in a string key or a DWORD key.
2151  *
2152  * params:
2153  *     regKey   - Key to read the default value from
2154  *     pdwValue - Pointer to the location where the DWORD
2155  *                value is returned. This value is not modified
2156  *                if the value is not found.
2157  */
2158
2159 static void OLEUTL_ReadRegistryDWORDValue(
2160   HKEY   regKey,
2161   DWORD* pdwValue)
2162 {
2163   char  buffer[20];
2164   DWORD dwKeyType;
2165   DWORD cbData = 20;
2166   LONG  lres;
2167
2168   lres = RegQueryValueExA(regKey,
2169                           "",
2170                           NULL,
2171                           &dwKeyType,
2172                           (LPBYTE)buffer,
2173                           &cbData);
2174
2175   if (lres==ERROR_SUCCESS)
2176   {
2177     switch (dwKeyType)
2178     {
2179       case REG_DWORD:
2180         *pdwValue = *(DWORD*)buffer;
2181         break;
2182       case REG_EXPAND_SZ:
2183       case REG_MULTI_SZ:
2184       case REG_SZ:
2185         *pdwValue = (DWORD)strtoul(buffer, NULL, 10);
2186         break;
2187     }
2188   }
2189 }
2190
2191 /******************************************************************************
2192  * OleDraw (OLE32.@)
2193  *
2194  * The operation of this function is documented literally in the WinAPI
2195  * documentation to involve a QueryInterface for the IViewObject interface,
2196  * followed by a call to IViewObject::Draw.
2197  */
2198 HRESULT WINAPI OleDraw(
2199         IUnknown *pUnk,
2200         DWORD dwAspect,
2201         HDC hdcDraw,
2202         LPCRECT lprcBounds)
2203 {
2204   HRESULT hres;
2205   IViewObject *viewobject;
2206
2207   hres = IUnknown_QueryInterface(pUnk,
2208                                  &IID_IViewObject,
2209                                  (void**)&viewobject);
2210
2211   if (SUCCEEDED(hres))
2212   {
2213     RECTL rectl;
2214
2215     rectl.left = lprcBounds->left;
2216     rectl.right = lprcBounds->right;
2217     rectl.top = lprcBounds->top;
2218     rectl.bottom = lprcBounds->bottom;
2219     hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
2220
2221     IViewObject_Release(viewobject);
2222     return hres;
2223   }
2224   else
2225   {
2226     return DV_E_NOIVIEWOBJECT;
2227   }
2228 }
2229
2230 /***********************************************************************
2231  *             OleTranslateAccelerator [OLE32.@]
2232  */
2233 HRESULT WINAPI OleTranslateAccelerator (LPOLEINPLACEFRAME lpFrame,
2234                    LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpmsg)
2235 {
2236     WORD wID;
2237
2238     TRACE("(%p,%p,%p)\n", lpFrame, lpFrameInfo, lpmsg);
2239
2240     if (IsAccelerator(lpFrameInfo->haccel,lpFrameInfo->cAccelEntries,lpmsg,&wID))
2241         return IOleInPlaceFrame_TranslateAccelerator(lpFrame,lpmsg,wID);
2242
2243     return S_FALSE;
2244 }
2245
2246 /******************************************************************************
2247  *              OleCreate        [OLE32.@]
2248  *
2249  */
2250 HRESULT WINAPI OleCreate(
2251         REFCLSID rclsid,
2252         REFIID riid,
2253         DWORD renderopt,
2254         LPFORMATETC pFormatEtc,
2255         LPOLECLIENTSITE pClientSite,
2256         LPSTORAGE pStg,
2257         LPVOID* ppvObj)
2258 {
2259     HRESULT hres, hres1;
2260     IUnknown * pUnk = NULL;
2261
2262     FIXME("\n\t%s\n\t%s semi-stub!\n", debugstr_guid(rclsid), debugstr_guid(riid));
2263
2264     if (SUCCEEDED((hres = CoCreateInstance(rclsid, 0, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER|CLSCTX_LOCAL_SERVER , riid, (LPVOID*)&pUnk))))
2265     {
2266         if (pClientSite)
2267         {
2268             IOleObject * pOE;
2269             IPersistStorage * pPS;
2270             if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IOleObject, (LPVOID*)&pOE))))
2271             {
2272                 TRACE("trying to set clientsite %p\n", pClientSite);
2273                 hres1 = IOleObject_SetClientSite(pOE, pClientSite);
2274                 TRACE("-- result 0x%08lx\n", hres1);
2275                 IOleObject_Release(pOE);
2276             }
2277             if (SUCCEEDED((hres = IUnknown_QueryInterface( pUnk, &IID_IPersistStorage, (LPVOID*)&pPS))))
2278             {
2279                 TRACE("trying to set stg %p\n", pStg);
2280                 hres1 = IPersistStorage_InitNew(pPS, pStg);
2281                 TRACE("-- result 0x%08lx\n", hres1);
2282                 IPersistStorage_Release(pPS);
2283             }
2284         }
2285     }
2286
2287     *ppvObj = pUnk;
2288
2289     TRACE("-- %p \n", pUnk);
2290     return hres;
2291 }
2292
2293 /******************************************************************************
2294  *              OleSetAutoConvert        [OLE32.@]
2295  */
2296 HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
2297 {
2298     static const WCHAR wszAutoConvertTo[] = {'A','u','t','o','C','o','n','v','e','r','t','T','o',0};
2299     HKEY hkey = NULL;
2300     WCHAR szClsidNew[CHARS_IN_GUID];
2301     HRESULT res = S_OK;
2302
2303     TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
2304     
2305     if (COM_OpenKeyForCLSID(clsidOld, KEY_READ | KEY_WRITE, &hkey))
2306     {
2307         res = REGDB_E_CLASSNOTREG;
2308         goto done;
2309     }
2310     StringFromGUID2(clsidNew, szClsidNew, CHARS_IN_GUID);
2311     if (RegSetValueW(hkey, wszAutoConvertTo, REG_SZ, szClsidNew, (strlenW(szClsidNew)+1) * sizeof(WCHAR)))
2312     {
2313         res = REGDB_E_WRITEREGDB;
2314         goto done;
2315     }
2316
2317 done:
2318     if (hkey) RegCloseKey(hkey);
2319     return res;
2320 }
2321
2322 /******************************************************************************
2323  *              OleDoAutoConvert        [OLE32.@]
2324  */
2325 HRESULT WINAPI OleDoAutoConvert(LPSTORAGE pStg, LPCLSID pClsidNew)
2326 {
2327     FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2328     return E_NOTIMPL;
2329 }
2330
2331 /******************************************************************************
2332  *              OleDoAutoConvert        [OLE2.79]
2333  */
2334 HRESULT WINAPI OleDoAutoConvert16(LPSTORAGE pStg, LPCLSID pClsidNew)
2335 {
2336     FIXME("(%p,%p) : stub\n",pStg,pClsidNew);
2337     return E_NOTIMPL;
2338 }
2339
2340 /******************************************************************************
2341  *              OleIsRunning        [OLE32.@]
2342  */
2343 BOOL WINAPI OleIsRunning(LPOLEOBJECT pObject)
2344 {
2345     IRunnableObject *pRunnable;
2346     HRESULT hr;
2347     BOOL running;
2348
2349     TRACE("(%p)\n", pObject);
2350
2351     hr = IOleObject_QueryInterface(pObject, &IID_IRunnableObject, (void **)&pRunnable);
2352     if (FAILED(hr))
2353         return FALSE;
2354     running = IRunnableObject_IsRunning(pRunnable);
2355     IRunnableObject_Release(pRunnable);
2356     return running;
2357 }
2358
2359 /***********************************************************************
2360  *           OLE_FreeClipDataArray   [internal]
2361  *
2362  * NOTES:
2363  *  frees the data associated with an array of CLIPDATAs
2364  */
2365 static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
2366 {
2367     ULONG i;
2368     for (i = 0; i < count; i++)
2369         if (pClipDataArray[i].pClipData)
2370             CoTaskMemFree(pClipDataArray[i].pClipData);
2371 }
2372
2373 /***********************************************************************
2374  *           PropSysAllocString                     [OLE32.@]
2375  * NOTES:
2376  *  Basically a copy of SysAllocStringLen.
2377  */
2378 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
2379 {
2380     DWORD  bufferSize;
2381     DWORD* newBuffer;
2382     WCHAR* stringBuffer;
2383     int len;
2384
2385     if (!str) return 0;
2386
2387     len = lstrlenW(str);
2388     /*
2389      * Find the length of the buffer passed-in in bytes.
2390      */
2391     bufferSize = len * sizeof (WCHAR);
2392
2393     /*
2394      * Allocate a new buffer to hold the string.
2395      * don't forget to keep an empty spot at the beginning of the
2396      * buffer for the character count and an extra character at the
2397      * end for the NULL.
2398      */
2399     newBuffer = HeapAlloc(GetProcessHeap(), 0,
2400                           bufferSize + sizeof(WCHAR) + sizeof(DWORD));
2401
2402     /*
2403      * If the memory allocation failed, return a null pointer.
2404      */
2405     if (newBuffer==0)
2406       return 0;
2407
2408     /*
2409      * Copy the length of the string in the placeholder.
2410      */
2411     *newBuffer = bufferSize;
2412
2413     /*
2414      * Skip the byte count.
2415      */
2416     newBuffer++;
2417
2418     /*
2419      * Copy the information in the buffer.
2420      * Since it is valid to pass a NULL pointer here, we'll initialize the
2421      * buffer to nul if it is the case.
2422      */
2423     if (str != 0)
2424       memcpy(newBuffer, str, bufferSize);
2425     else
2426       memset(newBuffer, 0, bufferSize);
2427
2428     /*
2429      * Make sure that there is a nul character at the end of the
2430      * string.
2431      */
2432     stringBuffer = (WCHAR*)newBuffer;
2433     stringBuffer[len] = L'\0';
2434
2435     return (LPWSTR)stringBuffer;
2436 }
2437
2438 /***********************************************************************
2439  *           PropSysFreeString                      [OLE32.@]
2440  * NOTES
2441  *  Copy of SysFreeString.
2442  */
2443 void WINAPI PropSysFreeString(LPOLESTR str)
2444 {
2445     DWORD* bufferPointer;
2446
2447     /* NULL is a valid parameter */
2448     if(!str) return;
2449
2450     /*
2451      * We have to be careful when we free a BSTR pointer, it points to
2452      * the beginning of the string but it skips the byte count contained
2453      * before the string.
2454      */
2455     bufferPointer = (DWORD*)str;
2456
2457     bufferPointer--;
2458
2459     /*
2460      * Free the memory from its "real" origin.
2461      */
2462     HeapFree(GetProcessHeap(), 0, bufferPointer);
2463 }
2464
2465 /******************************************************************************
2466  * Check if a PROPVARIANT's type is valid.
2467  */
2468 static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
2469 {
2470     switch (vt)
2471     {
2472     case VT_EMPTY:
2473     case VT_NULL:
2474     case VT_I2:
2475     case VT_I4:
2476     case VT_R4:
2477     case VT_R8:
2478     case VT_CY:
2479     case VT_DATE:
2480     case VT_BSTR:
2481     case VT_ERROR:
2482     case VT_BOOL:
2483     case VT_UI1:
2484     case VT_UI2:
2485     case VT_UI4:
2486     case VT_I8:
2487     case VT_UI8:
2488     case VT_LPSTR:
2489     case VT_LPWSTR:
2490     case VT_FILETIME:
2491     case VT_BLOB:
2492     case VT_STREAM:
2493     case VT_STORAGE:
2494     case VT_STREAMED_OBJECT:
2495     case VT_STORED_OBJECT:
2496     case VT_BLOB_OBJECT:
2497     case VT_CF:
2498     case VT_CLSID:
2499     case VT_I2|VT_VECTOR:
2500     case VT_I4|VT_VECTOR:
2501     case VT_R4|VT_VECTOR:
2502     case VT_R8|VT_VECTOR:
2503     case VT_CY|VT_VECTOR:
2504     case VT_DATE|VT_VECTOR:
2505     case VT_BSTR|VT_VECTOR:
2506     case VT_ERROR|VT_VECTOR:
2507     case VT_BOOL|VT_VECTOR:
2508     case VT_VARIANT|VT_VECTOR:
2509     case VT_UI1|VT_VECTOR:
2510     case VT_UI2|VT_VECTOR:
2511     case VT_UI4|VT_VECTOR:
2512     case VT_I8|VT_VECTOR:
2513     case VT_UI8|VT_VECTOR:
2514     case VT_LPSTR|VT_VECTOR:
2515     case VT_LPWSTR|VT_VECTOR:
2516     case VT_FILETIME|VT_VECTOR:
2517     case VT_CF|VT_VECTOR:
2518     case VT_CLSID|VT_VECTOR:
2519         return S_OK;
2520     }
2521     WARN("Bad type %d\n", vt);
2522     return STG_E_INVALIDPARAMETER;
2523 }
2524
2525 /***********************************************************************
2526  *           PropVariantClear                       [OLE32.@]
2527  */
2528 HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
2529 {
2530     HRESULT hr;
2531
2532     TRACE("(%p)\n", pvar);
2533
2534     if (!pvar)
2535         return S_OK;
2536
2537     hr = PROPVARIANT_ValidateType(pvar->vt);
2538     if (FAILED(hr))
2539         return hr;
2540
2541     switch(pvar->vt)
2542     {
2543     case VT_STREAM:
2544     case VT_STREAMED_OBJECT:
2545     case VT_STORAGE:
2546     case VT_STORED_OBJECT:
2547         if (pvar->u.pStream)
2548             IUnknown_Release(pvar->u.pStream);
2549         break;
2550     case VT_CLSID:
2551     case VT_LPSTR:
2552     case VT_LPWSTR:
2553         /* pick an arbitary typed pointer - we don't care about the type
2554          * as we are just freeing it */
2555         CoTaskMemFree(pvar->u.puuid);
2556         break;
2557     case VT_BLOB:
2558     case VT_BLOB_OBJECT:
2559         CoTaskMemFree(pvar->u.blob.pBlobData);
2560         break;
2561     case VT_BSTR:
2562         if (pvar->u.bstrVal)
2563             PropSysFreeString(pvar->u.bstrVal);
2564         break;
2565    case VT_CF:
2566         if (pvar->u.pclipdata)
2567         {
2568             OLE_FreeClipDataArray(1, pvar->u.pclipdata);
2569             CoTaskMemFree(pvar->u.pclipdata);
2570         }
2571         break;
2572     default:
2573         if (pvar->vt & VT_VECTOR)
2574         {
2575             ULONG i;
2576
2577             switch (pvar->vt & ~VT_VECTOR)
2578             {
2579             case VT_VARIANT:
2580                 FreePropVariantArray(pvar->u.capropvar.cElems, pvar->u.capropvar.pElems);
2581                 break;
2582             case VT_CF:
2583                 OLE_FreeClipDataArray(pvar->u.caclipdata.cElems, pvar->u.caclipdata.pElems);
2584                 break;
2585             case VT_BSTR:
2586                 for (i = 0; i < pvar->u.cabstr.cElems; i++)
2587                     PropSysFreeString(pvar->u.cabstr.pElems[i]);
2588                 break;
2589             case VT_LPSTR:
2590                 for (i = 0; i < pvar->u.calpstr.cElems; i++)
2591                     CoTaskMemFree(pvar->u.calpstr.pElems[i]);
2592                 break;
2593             case VT_LPWSTR:
2594                 for (i = 0; i < pvar->u.calpwstr.cElems; i++)
2595                     CoTaskMemFree(pvar->u.calpwstr.pElems[i]);
2596                 break;
2597             }
2598             if (pvar->vt & ~VT_VECTOR)
2599             {
2600                 /* pick an arbitary VT_VECTOR structure - they all have the same
2601                  * memory layout */
2602                 CoTaskMemFree(pvar->u.capropvar.pElems);
2603             }
2604         }
2605         else
2606             WARN("Invalid/unsupported type %d\n", pvar->vt);
2607     }
2608
2609     ZeroMemory(pvar, sizeof(*pvar));
2610
2611     return S_OK;
2612 }
2613
2614 /***********************************************************************
2615  *           PropVariantCopy                        [OLE32.@]
2616  */
2617 HRESULT WINAPI PropVariantCopy(PROPVARIANT *pvarDest,      /* [out] */
2618                                const PROPVARIANT *pvarSrc) /* [in] */
2619 {
2620     ULONG len;
2621     HRESULT hr;
2622
2623     TRACE("(%p, %p)\n", pvarDest, pvarSrc);
2624
2625     hr = PROPVARIANT_ValidateType(pvarSrc->vt);
2626     if (FAILED(hr))
2627         return hr;
2628
2629     /* this will deal with most cases */
2630     CopyMemory(pvarDest, pvarSrc, sizeof(*pvarDest));
2631
2632     switch(pvarSrc->vt)
2633     {
2634     case VT_STREAM:
2635     case VT_STREAMED_OBJECT:
2636     case VT_STORAGE:
2637     case VT_STORED_OBJECT:
2638         IUnknown_AddRef((LPUNKNOWN)pvarDest->u.pStream);
2639         break;
2640     case VT_CLSID:
2641         pvarDest->u.puuid = CoTaskMemAlloc(sizeof(CLSID));
2642         CopyMemory(pvarDest->u.puuid, pvarSrc->u.puuid, sizeof(CLSID));
2643         break;
2644     case VT_LPSTR:
2645         len = strlen(pvarSrc->u.pszVal);
2646         pvarDest->u.pszVal = CoTaskMemAlloc((len+1)*sizeof(CHAR));
2647         CopyMemory(pvarDest->u.pszVal, pvarSrc->u.pszVal, (len+1)*sizeof(CHAR));
2648         break;
2649     case VT_LPWSTR:
2650         len = lstrlenW(pvarSrc->u.pwszVal);
2651         pvarDest->u.pwszVal = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
2652         CopyMemory(pvarDest->u.pwszVal, pvarSrc->u.pwszVal, (len+1)*sizeof(WCHAR));
2653         break;
2654     case VT_BLOB:
2655     case VT_BLOB_OBJECT:
2656         if (pvarSrc->u.blob.pBlobData)
2657         {
2658             len = pvarSrc->u.blob.cbSize;
2659             pvarDest->u.blob.pBlobData = CoTaskMemAlloc(len);
2660             CopyMemory(pvarDest->u.blob.pBlobData, pvarSrc->u.blob.pBlobData, len);
2661         }
2662         break;
2663     case VT_BSTR:
2664         pvarDest->u.bstrVal = PropSysAllocString(pvarSrc->u.bstrVal);
2665         break;
2666     case VT_CF:
2667         if (pvarSrc->u.pclipdata)
2668         {
2669             len = pvarSrc->u.pclipdata->cbSize - sizeof(pvarSrc->u.pclipdata->ulClipFmt);
2670             CoTaskMemAlloc(len);
2671             CopyMemory(pvarDest->u.pclipdata->pClipData, pvarSrc->u.pclipdata->pClipData, len);
2672         }
2673         break;
2674     default:
2675         if (pvarSrc->vt & VT_VECTOR)
2676         {
2677             int elemSize;
2678             ULONG i;
2679
2680             switch(pvarSrc->vt & ~VT_VECTOR)
2681             {
2682             case VT_I1:       elemSize = sizeof(pvarSrc->u.cVal); break;
2683             case VT_UI1:      elemSize = sizeof(pvarSrc->u.bVal); break;
2684             case VT_I2:       elemSize = sizeof(pvarSrc->u.iVal); break;
2685             case VT_UI2:      elemSize = sizeof(pvarSrc->u.uiVal); break;
2686             case VT_BOOL:     elemSize = sizeof(pvarSrc->u.boolVal); break;
2687             case VT_I4:       elemSize = sizeof(pvarSrc->u.lVal); break;
2688             case VT_UI4:      elemSize = sizeof(pvarSrc->u.ulVal); break;
2689             case VT_R4:       elemSize = sizeof(pvarSrc->u.fltVal); break;
2690             case VT_R8:       elemSize = sizeof(pvarSrc->u.dblVal); break;
2691             case VT_ERROR:    elemSize = sizeof(pvarSrc->u.scode); break;
2692             case VT_I8:       elemSize = sizeof(pvarSrc->u.hVal); break;
2693             case VT_UI8:      elemSize = sizeof(pvarSrc->u.uhVal); break;
2694             case VT_CY:       elemSize = sizeof(pvarSrc->u.cyVal); break;
2695             case VT_DATE:     elemSize = sizeof(pvarSrc->u.date); break;
2696             case VT_FILETIME: elemSize = sizeof(pvarSrc->u.filetime); break;
2697             case VT_CLSID:    elemSize = sizeof(*pvarSrc->u.puuid); break;
2698             case VT_CF:       elemSize = sizeof(*pvarSrc->u.pclipdata); break;
2699             case VT_BSTR:     elemSize = sizeof(*pvarSrc->u.bstrVal); break;
2700             case VT_LPSTR:    elemSize = sizeof(*pvarSrc->u.pszVal); break;
2701             case VT_LPWSTR:   elemSize = sizeof(*pvarSrc->u.pwszVal); break;
2702
2703             case VT_VARIANT:
2704             default:
2705                 FIXME("Invalid element type: %ul\n", pvarSrc->vt & ~VT_VECTOR);
2706                 return E_INVALIDARG;
2707             }
2708             len = pvarSrc->u.capropvar.cElems;
2709             pvarDest->u.capropvar.pElems = CoTaskMemAlloc(len * elemSize);
2710             if (pvarSrc->vt == (VT_VECTOR | VT_VARIANT))
2711             {
2712                 for (i = 0; i < len; i++)
2713                     PropVariantCopy(&pvarDest->u.capropvar.pElems[i], &pvarSrc->u.capropvar.pElems[i]);
2714             }
2715             else if (pvarSrc->vt == (VT_VECTOR | VT_CF))
2716             {
2717                 FIXME("Copy clipformats\n");
2718             }
2719             else if (pvarSrc->vt == (VT_VECTOR | VT_BSTR))
2720             {
2721                 for (i = 0; i < len; i++)
2722                     pvarDest->u.cabstr.pElems[i] = PropSysAllocString(pvarSrc->u.cabstr.pElems[i]);
2723             }
2724             else if (pvarSrc->vt == (VT_VECTOR | VT_LPSTR))
2725             {
2726                 size_t strLen;
2727                 for (i = 0; i < len; i++)
2728                 {
2729                     strLen = lstrlenA(pvarSrc->u.calpstr.pElems[i]) + 1;
2730                     pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2731                     memcpy(pvarDest->u.calpstr.pElems[i],
2732                      pvarSrc->u.calpstr.pElems[i], strLen);
2733                 }
2734             }
2735             else if (pvarSrc->vt == (VT_VECTOR | VT_LPWSTR))
2736             {
2737                 size_t strLen;
2738                 for (i = 0; i < len; i++)
2739                 {
2740                     strLen = (lstrlenW(pvarSrc->u.calpwstr.pElems[i]) + 1) *
2741                      sizeof(WCHAR);
2742                     pvarDest->u.calpstr.pElems[i] = CoTaskMemAlloc(strLen);
2743                     memcpy(pvarDest->u.calpstr.pElems[i],
2744                      pvarSrc->u.calpstr.pElems[i], strLen);
2745                 }
2746             }
2747             else
2748                 CopyMemory(pvarDest->u.capropvar.pElems, pvarSrc->u.capropvar.pElems, len * elemSize);
2749         }
2750         else
2751             WARN("Invalid/unsupported type %d\n", pvarSrc->vt);
2752     }
2753
2754     return S_OK;
2755 }
2756
2757 /***********************************************************************
2758  *           FreePropVariantArray                           [OLE32.@]
2759  */
2760 HRESULT WINAPI FreePropVariantArray(ULONG cVariants, /* [in] */
2761                                     PROPVARIANT *rgvars)    /* [in/out] */
2762 {
2763     ULONG i;
2764
2765     TRACE("(%lu, %p)\n", cVariants, rgvars);
2766
2767     for(i = 0; i < cVariants; i++)
2768         PropVariantClear(&rgvars[i]);
2769
2770     return S_OK;
2771 }
2772
2773 /******************************************************************************
2774  * DllDebugObjectRPCHook (OLE32.@)
2775  * turns on and off internal debugging,  pointer is only used on macintosh
2776  */
2777
2778 BOOL WINAPI DllDebugObjectRPCHook(BOOL b, void *dummy)
2779 {
2780   FIXME("stub\n");
2781   return TRUE;
2782 }