| 1 | /*
|
|---|
| 2 | * COMPOBJ library
|
|---|
| 3 | *
|
|---|
| 4 | * Copyright 1995 Martin von Loewis
|
|---|
| 5 | * Copyright 1998 Justin Bradford
|
|---|
| 6 | * Copyright 1999 Francis Beaudet
|
|---|
| 7 | * Copyright 1999 Sylvain St-Germain
|
|---|
| 8 | * Copyright 2002 Marcus Meissner
|
|---|
| 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 <stdlib.h>
|
|---|
| 28 | #include <stdio.h>
|
|---|
| 29 | #include <string.h>
|
|---|
| 30 | #include <assert.h>
|
|---|
| 31 |
|
|---|
| 32 | #include "windef.h"
|
|---|
| 33 | #include "objbase.h"
|
|---|
| 34 | #include "ole2.h"
|
|---|
| 35 | #include "ole2ver.h"
|
|---|
| 36 | #include "rpc.h"
|
|---|
| 37 | #include "winerror.h"
|
|---|
| 38 | #include "winreg.h"
|
|---|
| 39 | #include "wownt32.h"
|
|---|
| 40 | #include "wtypes.h"
|
|---|
| 41 | #include "wine/unicode.h"
|
|---|
| 42 | #include "wine/obj_base.h"
|
|---|
| 43 | #include "wine/obj_clientserver.h"
|
|---|
| 44 | #include "wine/obj_misc.h"
|
|---|
| 45 | #include "wine/obj_marshal.h"
|
|---|
| 46 | #include "wine/obj_storage.h"
|
|---|
| 47 | #include "wine/obj_channel.h"
|
|---|
| 48 | #include "wine/winbase16.h"
|
|---|
| 49 | #include "compobj_private.h"
|
|---|
| 50 | #include "ifs.h"
|
|---|
| 51 |
|
|---|
| 52 | #include "debugtools.h"
|
|---|
| 53 |
|
|---|
| 54 | DEFAULT_DEBUG_CHANNEL(ole);
|
|---|
| 55 |
|
|---|
| 56 | /****************************************************************************
|
|---|
| 57 | * COM External Lock structures and methods declaration
|
|---|
| 58 | *
|
|---|
| 59 | * This api provides a linked list to managed external references to
|
|---|
| 60 | * COM objects.
|
|---|
| 61 | *
|
|---|
| 62 | * The public interface consists of three calls:
|
|---|
| 63 | * COM_ExternalLockAddRef
|
|---|
| 64 | * COM_ExternalLockRelease
|
|---|
| 65 | * COM_ExternalLockFreeList
|
|---|
| 66 | */
|
|---|
| 67 |
|
|---|
| 68 | #define EL_END_OF_LIST 0
|
|---|
| 69 | #define EL_NOT_FOUND 0
|
|---|
| 70 |
|
|---|
| 71 | /*
|
|---|
| 72 | * Declaration of the static structure that manage the
|
|---|
| 73 | * external lock to COM objects.
|
|---|
| 74 | */
|
|---|
| 75 | typedef struct COM_ExternalLock COM_ExternalLock;
|
|---|
| 76 | typedef struct COM_ExternalLockList COM_ExternalLockList;
|
|---|
| 77 |
|
|---|
| 78 | struct COM_ExternalLock
|
|---|
| 79 | {
|
|---|
| 80 | IUnknown *pUnk; /* IUnknown referenced */
|
|---|
| 81 | ULONG uRefCount; /* external lock counter to IUnknown object*/
|
|---|
| 82 | COM_ExternalLock *next; /* Pointer to next element in list */
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 | struct COM_ExternalLockList
|
|---|
| 86 | {
|
|---|
| 87 | COM_ExternalLock *head; /* head of list */
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | /*
|
|---|
| 91 | * Declaration and initialization of the static structure that manages
|
|---|
| 92 | * the external lock to COM objects.
|
|---|
| 93 | */
|
|---|
| 94 | static COM_ExternalLockList elList = { EL_END_OF_LIST };
|
|---|
| 95 |
|
|---|
| 96 | /*
|
|---|
| 97 | * Public Interface to the external lock list
|
|---|
| 98 | */
|
|---|
| 99 | static void COM_ExternalLockFreeList();
|
|---|
| 100 | static void COM_ExternalLockAddRef(IUnknown *pUnk);
|
|---|
| 101 | static void COM_ExternalLockRelease(IUnknown *pUnk, BOOL bRelAll);
|
|---|
| 102 | void COM_ExternalLockDump(); /* testing purposes, not static to avoid warning */
|
|---|
| 103 |
|
|---|
| 104 | /*
|
|---|
| 105 | * Private methods used to managed the linked list
|
|---|
| 106 | */
|
|---|
| 107 | static BOOL COM_ExternalLockInsert(
|
|---|
| 108 | IUnknown *pUnk);
|
|---|
| 109 |
|
|---|
| 110 | static void COM_ExternalLockDelete(
|
|---|
| 111 | COM_ExternalLock *element);
|
|---|
| 112 |
|
|---|
| 113 | static COM_ExternalLock* COM_ExternalLockFind(
|
|---|
| 114 | IUnknown *pUnk);
|
|---|
| 115 |
|
|---|
| 116 | static COM_ExternalLock* COM_ExternalLockLocate(
|
|---|
| 117 | COM_ExternalLock *element,
|
|---|
| 118 | IUnknown *pUnk);
|
|---|
| 119 |
|
|---|
| 120 | /****************************************************************************
|
|---|
| 121 | * This section defines variables internal to the COM module.
|
|---|
| 122 | *
|
|---|
| 123 | * TODO: Most of these things will have to be made thread-safe.
|
|---|
| 124 | */
|
|---|
| 125 | HINSTANCE16 COMPOBJ_hInstance = 0;
|
|---|
| 126 | HINSTANCE COMPOBJ_hInstance32 = 0;
|
|---|
| 127 | static int COMPOBJ_Attach = 0;
|
|---|
| 128 |
|
|---|
| 129 | LPMALLOC16 currentMalloc16=NULL;
|
|---|
| 130 | LPMALLOC currentMalloc32=NULL;
|
|---|
| 131 |
|
|---|
| 132 | HTASK16 hETask = 0;
|
|---|
| 133 | WORD Table_ETask[62];
|
|---|
| 134 |
|
|---|
| 135 | /*
|
|---|
| 136 | * This lock count counts the number of times CoInitialize is called. It is
|
|---|
| 137 | * decreased every time CoUninitialize is called. When it hits 0, the COM
|
|---|
| 138 | * libraries are freed
|
|---|
| 139 | */
|
|---|
| 140 | static LONG s_COMLockCount = 0;
|
|---|
| 141 |
|
|---|
| 142 | /*
|
|---|
| 143 | * This linked list contains the list of registered class objects. These
|
|---|
| 144 | * are mostly used to register the factories for out-of-proc servers of OLE
|
|---|
| 145 | * objects.
|
|---|
| 146 | *
|
|---|
| 147 | * TODO: Make this data structure aware of inter-process communication. This
|
|---|
| 148 | * means that parts of this will be exported to the Wine Server.
|
|---|
| 149 | */
|
|---|
| 150 | typedef struct tagRegisteredClass
|
|---|
| 151 | {
|
|---|
| 152 | CLSID classIdentifier;
|
|---|
| 153 | LPUNKNOWN classObject;
|
|---|
| 154 | DWORD runContext;
|
|---|
| 155 | DWORD connectFlags;
|
|---|
| 156 | DWORD dwCookie;
|
|---|
| 157 | HANDLE hThread; /* only for localserver */
|
|---|
| 158 | struct tagRegisteredClass* nextClass;
|
|---|
| 159 | } RegisteredClass;
|
|---|
| 160 |
|
|---|
| 161 | static CRITICAL_SECTION csRegisteredClassList;
|
|---|
| 162 | static RegisteredClass* firstRegisteredClass = NULL;
|
|---|
| 163 |
|
|---|
| 164 | /* this open DLL table belongs in a per process table, but my guess is that
|
|---|
| 165 | * it shouldn't live in the kernel, so I'll put them out here in DLL
|
|---|
| 166 | * space assuming that there is one OLE32 per process.
|
|---|
| 167 | */
|
|---|
| 168 | typedef struct tagOpenDll {
|
|---|
| 169 | HINSTANCE hLibrary;
|
|---|
| 170 | struct tagOpenDll *next;
|
|---|
| 171 | } OpenDll;
|
|---|
| 172 |
|
|---|
| 173 | static CRITICAL_SECTION csOpenDllList;
|
|---|
| 174 | static OpenDll *openDllList = NULL; /* linked list of open dlls */
|
|---|
| 175 |
|
|---|
| 176 | /*****************************************************************************
|
|---|
| 177 | * This section contains prototypes to internal methods for this
|
|---|
| 178 | * module
|
|---|
| 179 | */
|
|---|
| 180 | static HRESULT COM_GetRegisteredClassObject(REFCLSID rclsid,
|
|---|
| 181 | DWORD dwClsContext,
|
|---|
| 182 | LPUNKNOWN* ppUnk);
|
|---|
| 183 |
|
|---|
| 184 | static void COM_RevokeAllClasses();
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 | /******************************************************************************
|
|---|
| 188 | * Initialize/Uninitialize critical sections.
|
|---|
| 189 | */
|
|---|
| 190 | void COMPOBJ_InitProcess( void )
|
|---|
| 191 | {
|
|---|
| 192 | InitializeCriticalSection( &csRegisteredClassList );
|
|---|
| 193 | InitializeCriticalSection( &csOpenDllList );
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | void COMPOBJ_UninitProcess( void )
|
|---|
| 197 | {
|
|---|
| 198 | DeleteCriticalSection( &csRegisteredClassList );
|
|---|
| 199 | DeleteCriticalSection( &csOpenDllList );
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /******************************************************************************
|
|---|
| 203 | * CoBuildVersion [COMPOBJ.1]
|
|---|
| 204 | * CoBuildVersion [OLE32.4]
|
|---|
| 205 | *
|
|---|
| 206 | * RETURNS
|
|---|
| 207 | * Current build version, hiword is majornumber, loword is minornumber
|
|---|
| 208 | */
|
|---|
| 209 | DWORD WINAPI CoBuildVersion(void)
|
|---|
| 210 | {
|
|---|
| 211 | TRACE("Returning version %d, build %d.\n", rmm, rup);
|
|---|
| 212 | return (rmm<<16)+rup;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | /******************************************************************************
|
|---|
| 216 | * CoInitialize [COMPOBJ.2]
|
|---|
| 217 | * Set the win16 IMalloc used for memory management
|
|---|
| 218 | */
|
|---|
| 219 | HRESULT WINAPI CoInitialize16(
|
|---|
| 220 | LPVOID lpReserved /* [in] pointer to win16 malloc interface */
|
|---|
| 221 | ) {
|
|---|
| 222 | currentMalloc16 = (LPMALLOC16)lpReserved;
|
|---|
| 223 | return S_OK;
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | /******************************************************************************
|
|---|
| 227 | * CoInitialize [OLE32.26]
|
|---|
| 228 | *
|
|---|
| 229 | * Initializes the COM libraries.
|
|---|
| 230 | *
|
|---|
| 231 | * See CoInitializeEx
|
|---|
| 232 | */
|
|---|
| 233 | HRESULT WINAPI CoInitialize(
|
|---|
| 234 | LPVOID lpReserved /* [in] pointer to win32 malloc interface
|
|---|
| 235 | (obsolete, should be NULL) */
|
|---|
| 236 | )
|
|---|
| 237 | {
|
|---|
| 238 | /*
|
|---|
| 239 | * Just delegate to the newer method.
|
|---|
| 240 | */
|
|---|
| 241 | return CoInitializeEx(lpReserved, COINIT_APARTMENTTHREADED);
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | /******************************************************************************
|
|---|
| 245 | * CoInitializeEx [OLE32.163]
|
|---|
| 246 | *
|
|---|
| 247 | * Initializes the COM libraries. The behavior used to set the win32 IMalloc
|
|---|
| 248 | * used for memory management is obsolete.
|
|---|
| 249 | *
|
|---|
| 250 | * RETURNS
|
|---|
| 251 | * S_OK if successful,
|
|---|
| 252 | * S_FALSE if this function was called already.
|
|---|
| 253 | * RPC_E_CHANGED_MODE if a previous call to CoInitialize specified another
|
|---|
| 254 | * threading model.
|
|---|
| 255 | *
|
|---|
| 256 | * BUGS
|
|---|
| 257 | * Only the single threaded model is supported. As a result RPC_E_CHANGED_MODE
|
|---|
| 258 | * is never returned.
|
|---|
| 259 | *
|
|---|
| 260 | * See the windows documentation for more details.
|
|---|
| 261 | */
|
|---|
| 262 | HRESULT WINAPI CoInitializeEx(
|
|---|
| 263 | LPVOID lpReserved, /* [in] pointer to win32 malloc interface
|
|---|
| 264 | (obsolete, should be NULL) */
|
|---|
| 265 | DWORD dwCoInit /* [in] A value from COINIT specifies the threading model */
|
|---|
| 266 | )
|
|---|
| 267 | {
|
|---|
| 268 | HRESULT hr;
|
|---|
| 269 |
|
|---|
| 270 | TRACE("(%p, %x)\n", lpReserved, (int)dwCoInit);
|
|---|
| 271 |
|
|---|
| 272 | if (lpReserved!=NULL)
|
|---|
| 273 | {
|
|---|
| 274 | ERR("(%p, %x) - Bad parameter passed-in %p, must be an old Windows Application\n", lpReserved, (int)dwCoInit, lpReserved);
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | /*
|
|---|
| 278 | * Check for unsupported features.
|
|---|
| 279 | */
|
|---|
| 280 | if (dwCoInit!=COINIT_APARTMENTTHREADED)
|
|---|
| 281 | {
|
|---|
| 282 | FIXME(":(%p,%x): unsupported flag %x\n", lpReserved, (int)dwCoInit, (int)dwCoInit);
|
|---|
| 283 | /* Hope for the best and continue anyway */
|
|---|
| 284 | }
|
|---|
| 285 |
|
|---|
| 286 | /*
|
|---|
| 287 | * Check the lock count. If this is the first time going through the initialize
|
|---|
| 288 | * process, we have to initialize the libraries.
|
|---|
| 289 | *
|
|---|
| 290 | * And crank-up that lock count.
|
|---|
| 291 | */
|
|---|
| 292 | if (InterlockedExchangeAdd(&s_COMLockCount,1)==0)
|
|---|
| 293 | {
|
|---|
| 294 | /*
|
|---|
| 295 | * Initialize the various COM libraries and data structures.
|
|---|
| 296 | */
|
|---|
| 297 | TRACE("() - Initializing the COM libraries\n");
|
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 | RunningObjectTableImpl_Initialize();
|
|---|
| 301 |
|
|---|
| 302 | hr = S_OK;
|
|---|
| 303 | }
|
|---|
| 304 | else
|
|---|
| 305 | hr = S_FALSE;
|
|---|
| 306 |
|
|---|
| 307 | return hr;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | /***********************************************************************
|
|---|
| 311 | * CoUninitialize [COMPOBJ.3]
|
|---|
| 312 | * Don't know what it does.
|
|---|
| 313 | * 3-Nov-98 -- this was originally misspelled, I changed it to what I
|
|---|
| 314 | * believe is the correct spelling
|
|---|
| 315 | */
|
|---|
| 316 | void WINAPI CoUninitialize16(void)
|
|---|
| 317 | {
|
|---|
| 318 | TRACE("()\n");
|
|---|
| 319 | CoFreeAllLibraries();
|
|---|
| 320 | }
|
|---|
| 321 |
|
|---|
| 322 | /***********************************************************************
|
|---|
| 323 | * CoUninitialize [OLE32.47]
|
|---|
| 324 | *
|
|---|
| 325 | * This method will release the COM libraries.
|
|---|
| 326 | *
|
|---|
| 327 | * See the windows documentation for more details.
|
|---|
| 328 | */
|
|---|
| 329 | void WINAPI CoUninitialize(void)
|
|---|
| 330 | {
|
|---|
| 331 | LONG lCOMRefCnt;
|
|---|
| 332 | TRACE("()\n");
|
|---|
| 333 |
|
|---|
| 334 | /*
|
|---|
| 335 | * Decrease the reference count.
|
|---|
| 336 | * If we are back to 0 locks on the COM library, make sure we free
|
|---|
| 337 | * all the associated data structures.
|
|---|
| 338 | */
|
|---|
| 339 | lCOMRefCnt = InterlockedExchangeAdd(&s_COMLockCount,-1);
|
|---|
| 340 | if (lCOMRefCnt==1)
|
|---|
| 341 | {
|
|---|
| 342 | /*
|
|---|
| 343 | * Release the various COM libraries and data structures.
|
|---|
| 344 | */
|
|---|
| 345 | TRACE("() - Releasing the COM libraries\n");
|
|---|
| 346 |
|
|---|
| 347 | RunningObjectTableImpl_UnInitialize();
|
|---|
| 348 | /*
|
|---|
| 349 | * Release the references to the registered class objects.
|
|---|
| 350 | */
|
|---|
| 351 | COM_RevokeAllClasses();
|
|---|
| 352 |
|
|---|
| 353 | /*
|
|---|
| 354 | * This will free the loaded COM Dlls.
|
|---|
| 355 | */
|
|---|
| 356 | CoFreeAllLibraries();
|
|---|
| 357 |
|
|---|
| 358 | /*
|
|---|
| 359 | * This will free list of external references to COM objects.
|
|---|
| 360 | */
|
|---|
| 361 | COM_ExternalLockFreeList();
|
|---|
| 362 |
|
|---|
| 363 | }
|
|---|
| 364 | else if (lCOMRefCnt<1) {
|
|---|
| 365 | ERR( "CoUninitialize() - not CoInitialized.\n" );
|
|---|
| 366 | InterlockedExchangeAdd(&s_COMLockCount,1); /* restore the lock count. */
|
|---|
| 367 | }
|
|---|
| 368 | }
|
|---|
| 369 |
|
|---|
| 370 | #ifndef __WIN32OS2__
|
|---|
| 371 | /***********************************************************************
|
|---|
| 372 | * CoGetMalloc [COMPOBJ.4]
|
|---|
| 373 | * RETURNS
|
|---|
| 374 | * The current win16 IMalloc
|
|---|
| 375 | */
|
|---|
| 376 | HRESULT WINAPI CoGetMalloc16(
|
|---|
| 377 | DWORD dwMemContext, /* [in] unknown */
|
|---|
| 378 | LPMALLOC16 * lpMalloc /* [out] current win16 malloc interface */
|
|---|
| 379 | ) {
|
|---|
| 380 | if(!currentMalloc16)
|
|---|
| 381 | currentMalloc16 = IMalloc16_Constructor();
|
|---|
| 382 | *lpMalloc = currentMalloc16;
|
|---|
| 383 | return S_OK;
|
|---|
| 384 | }
|
|---|
| 385 | #endif
|
|---|
| 386 | /******************************************************************************
|
|---|
| 387 | * CoGetMalloc [OLE32.20]
|
|---|
| 388 | *
|
|---|
| 389 | * RETURNS
|
|---|
| 390 | * The current win32 IMalloc
|
|---|
| 391 | */
|
|---|
| 392 | HRESULT WINAPI CoGetMalloc(
|
|---|
| 393 | DWORD dwMemContext, /* [in] unknown */
|
|---|
| 394 | LPMALLOC *lpMalloc /* [out] current win32 malloc interface */
|
|---|
| 395 | ) {
|
|---|
| 396 | if(!currentMalloc32)
|
|---|
| 397 | currentMalloc32 = IMalloc_Constructor();
|
|---|
| 398 | *lpMalloc = currentMalloc32;
|
|---|
| 399 | return S_OK;
|
|---|
| 400 | }
|
|---|
| 401 |
|
|---|
| 402 | #ifndef __WIN32OS2__
|
|---|
| 403 | /***********************************************************************
|
|---|
| 404 | * CoCreateStandardMalloc [COMPOBJ.71]
|
|---|
| 405 | */
|
|---|
| 406 | HRESULT WINAPI CoCreateStandardMalloc16(DWORD dwMemContext,
|
|---|
| 407 | LPMALLOC16 *lpMalloc)
|
|---|
| 408 | {
|
|---|
| 409 | /* FIXME: docu says we shouldn't return the same allocator as in
|
|---|
| 410 | * CoGetMalloc16 */
|
|---|
| 411 | *lpMalloc = IMalloc16_Constructor();
|
|---|
| 412 | return S_OK;
|
|---|
| 413 | }
|
|---|
| 414 | #endif
|
|---|
| 415 |
|
|---|
| 416 | /******************************************************************************
|
|---|
| 417 | * CoDisconnectObject [COMPOBJ.15]
|
|---|
| 418 | * CoDisconnectObject [OLE32.8]
|
|---|
| 419 | */
|
|---|
| 420 | HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
|
|---|
| 421 | {
|
|---|
| 422 | TRACE("(%p, %lx)\n",lpUnk,reserved);
|
|---|
| 423 | return S_OK;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | /***********************************************************************
|
|---|
| 427 | * IsEqualGUID [COMPOBJ.18]
|
|---|
| 428 | *
|
|---|
| 429 | * Compares two Unique Identifiers.
|
|---|
| 430 | *
|
|---|
| 431 | * RETURNS
|
|---|
| 432 | * TRUE if equal
|
|---|
| 433 | */
|
|---|
| 434 | BOOL16 WINAPI IsEqualGUID16(
|
|---|
| 435 | GUID* g1, /* [in] unique id 1 */
|
|---|
| 436 | GUID* g2 /* [in] unique id 2 */
|
|---|
| 437 | ) {
|
|---|
| 438 | return !memcmp( g1, g2, sizeof(GUID) );
|
|---|
| 439 | }
|
|---|
| 440 |
|
|---|
| 441 | /******************************************************************************
|
|---|
| 442 | * CLSIDFromString [COMPOBJ.20]
|
|---|
| 443 | * Converts a unique identifier from its string representation into
|
|---|
| 444 | * the GUID struct.
|
|---|
| 445 | *
|
|---|
| 446 | * Class id: DWORD-WORD-WORD-BYTES[2]-BYTES[6]
|
|---|
| 447 | *
|
|---|
| 448 | * RETURNS
|
|---|
| 449 | * the converted GUID
|
|---|
| 450 | */
|
|---|
| 451 | HRESULT WINAPI CLSIDFromString16(
|
|---|
| 452 | LPCOLESTR16 idstr, /* [in] string representation of guid */
|
|---|
| 453 | CLSID *id /* [out] GUID converted from string */
|
|---|
| 454 | ) {
|
|---|
| 455 | BYTE *s = (BYTE *) idstr;
|
|---|
| 456 | BYTE *p;
|
|---|
| 457 | int i;
|
|---|
| 458 | BYTE table[256];
|
|---|
| 459 |
|
|---|
| 460 | if (!s)
|
|---|
| 461 | s = "{00000000-0000-0000-0000-000000000000}";
|
|---|
| 462 | else { /* validate the CLSID string */
|
|---|
| 463 |
|
|---|
| 464 | if (strlen(s) != 38)
|
|---|
| 465 | return CO_E_CLASSSTRING;
|
|---|
| 466 |
|
|---|
| 467 | if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') || (s[24]!='-') || (s[37]!='}'))
|
|---|
| 468 | return CO_E_CLASSSTRING;
|
|---|
| 469 |
|
|---|
| 470 | for (i=1; i<37; i++)
|
|---|
| 471 | {
|
|---|
| 472 | if ((i == 9)||(i == 14)||(i == 19)||(i == 24)) continue;
|
|---|
| 473 | if (!(((s[i] >= '0') && (s[i] <= '9')) ||
|
|---|
| 474 | ((s[i] >= 'a') && (s[i] <= 'f')) ||
|
|---|
| 475 | ((s[i] >= 'A') && (s[i] <= 'F')))
|
|---|
| 476 | )
|
|---|
| 477 | return CO_E_CLASSSTRING;
|
|---|
| 478 | }
|
|---|
| 479 | }
|
|---|
| 480 |
|
|---|
| 481 | TRACE("%s -> %p\n", s, id);
|
|---|
| 482 |
|
|---|
| 483 | /* quick lookup table */
|
|---|
| 484 | memset(table, 0, 256);
|
|---|
| 485 |
|
|---|
| 486 | for (i = 0; i < 10; i++) {
|
|---|
| 487 | table['0' + i] = i;
|
|---|
| 488 | }
|
|---|
| 489 | for (i = 0; i < 6; i++) {
|
|---|
| 490 | table['A' + i] = i+10;
|
|---|
| 491 | table['a' + i] = i+10;
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
|
|---|
| 495 |
|
|---|
| 496 | p = (BYTE *) id;
|
|---|
| 497 |
|
|---|
| 498 | s++; /* skip leading brace */
|
|---|
| 499 | for (i = 0; i < 4; i++) {
|
|---|
| 500 | p[3 - i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 501 | s += 2;
|
|---|
| 502 | }
|
|---|
| 503 | p += 4;
|
|---|
| 504 | s++; /* skip - */
|
|---|
| 505 |
|
|---|
| 506 | for (i = 0; i < 2; i++) {
|
|---|
| 507 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 508 | s += 2;
|
|---|
| 509 | }
|
|---|
| 510 | p += 2;
|
|---|
| 511 | s++; /* skip - */
|
|---|
| 512 |
|
|---|
| 513 | for (i = 0; i < 2; i++) {
|
|---|
| 514 | p[1-i] = table[*s]<<4 | table[*(s+1)];
|
|---|
| 515 | s += 2;
|
|---|
| 516 | }
|
|---|
| 517 | p += 2;
|
|---|
| 518 | s++; /* skip - */
|
|---|
| 519 |
|
|---|
| 520 | /* these are just sequential bytes */
|
|---|
| 521 | for (i = 0; i < 2; i++) {
|
|---|
| 522 | *p++ = table[*s]<<4 | table[*(s+1)];
|
|---|
| 523 | s += 2;
|
|---|
| 524 | }
|
|---|
| 525 | s++; /* skip - */
|
|---|
| 526 |
|
|---|
| 527 | for (i = 0; i < 6; i++) {
|
|---|
| 528 | *p++ = table[*s]<<4 | table[*(s+1)];
|
|---|
| 529 | s += 2;
|
|---|
| 530 | }
|
|---|
| 531 |
|
|---|
| 532 | return S_OK;
|
|---|
| 533 | }
|
|---|
| 534 |
|
|---|
| 535 | /******************************************************************************
|
|---|
| 536 | * CoCreateGuid[OLE32.6]
|
|---|
| 537 | *
|
|---|
| 538 | */
|
|---|
| 539 | HRESULT WINAPI CoCreateGuid(
|
|---|
| 540 | GUID *pguid /* [out] points to the GUID to initialize */
|
|---|
| 541 | ) {
|
|---|
| 542 | return UuidCreate(pguid);
|
|---|
| 543 | }
|
|---|
| 544 |
|
|---|
| 545 | /******************************************************************************
|
|---|
| 546 | * CLSIDFromString [OLE32.3]
|
|---|
| 547 | * IIDFromString [OLE32.74]
|
|---|
| 548 | * Converts a unique identifier from its string representation into
|
|---|
| 549 | * the GUID struct.
|
|---|
| 550 | *
|
|---|
| 551 | * UNDOCUMENTED
|
|---|
| 552 | * If idstr is not a valid CLSID string then it gets treated as a ProgID
|
|---|
| 553 | *
|
|---|
| 554 | * RETURNS
|
|---|
| 555 | * the converted GUID
|
|---|
| 556 | */
|
|---|
| 557 | HRESULT WINAPI CLSIDFromString(
|
|---|
| 558 | LPCOLESTR idstr, /* [in] string representation of GUID */
|
|---|
| 559 | CLSID *id ) /* [out] GUID represented by above string */
|
|---|
| 560 | {
|
|---|
| 561 | char xid[40];
|
|---|
| 562 | HRESULT ret;
|
|---|
| 563 |
|
|---|
| 564 | if (!WideCharToMultiByte( CP_ACP, 0, idstr, -1, xid, sizeof(xid), NULL, NULL ))
|
|---|
| 565 | return CO_E_CLASSSTRING;
|
|---|
| 566 | ret = CLSIDFromString16(xid,id);
|
|---|
| 567 | if(ret != S_OK) { /* It appears a ProgID is also valid */
|
|---|
| 568 | ret = CLSIDFromProgID(idstr, id);
|
|---|
| 569 | }
|
|---|
| 570 | return ret;
|
|---|
| 571 | }
|
|---|
| 572 |
|
|---|
| 573 | /******************************************************************************
|
|---|
| 574 | * WINE_StringFromCLSID [Internal]
|
|---|
| 575 | * Converts a GUID into the respective string representation.
|
|---|
| 576 | *
|
|---|
| 577 | * NOTES
|
|---|
| 578 | *
|
|---|
| 579 | * RETURNS
|
|---|
| 580 | * the string representation and HRESULT
|
|---|
| 581 | */
|
|---|
| 582 | HRESULT WINE_StringFromCLSID(
|
|---|
| 583 | const CLSID *id, /* [in] GUID to be converted */
|
|---|
| 584 | LPSTR idstr /* [out] pointer to buffer to contain converted guid */
|
|---|
| 585 | ) {
|
|---|
| 586 | static const char *hex = "0123456789ABCDEF";
|
|---|
| 587 | char *s;
|
|---|
| 588 | int i;
|
|---|
| 589 |
|
|---|
| 590 | if (!id)
|
|---|
| 591 | { ERR("called with id=Null\n");
|
|---|
| 592 | *idstr = 0x00;
|
|---|
| 593 | return E_FAIL;
|
|---|
| 594 | }
|
|---|
| 595 |
|
|---|
| 596 | sprintf(idstr, "{%08lX-%04X-%04X-%02X%02X-",
|
|---|
| 597 | id->Data1, id->Data2, id->Data3,
|
|---|
| 598 | id->Data4[0], id->Data4[1]);
|
|---|
| 599 | s = &idstr[25];
|
|---|
| 600 |
|
|---|
| 601 | /* 6 hex bytes */
|
|---|
| 602 | for (i = 2; i < 8; i++) {
|
|---|
| 603 | *s++ = hex[id->Data4[i]>>4];
|
|---|
| 604 | *s++ = hex[id->Data4[i] & 0xf];
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | *s++ = '}';
|
|---|
| 608 | *s++ = '\0';
|
|---|
| 609 |
|
|---|
| 610 | TRACE("%p->%s\n", id, idstr);
|
|---|
| 611 |
|
|---|
| 612 | return S_OK;
|
|---|
| 613 | }
|
|---|
| 614 |
|
|---|
| 615 | #ifndef __WIN32OS2__
|
|---|
| 616 | /******************************************************************************
|
|---|
| 617 | * StringFromCLSID [COMPOBJ.19]
|
|---|
| 618 | * Converts a GUID into the respective string representation.
|
|---|
| 619 | * The target string is allocated using the OLE IMalloc.
|
|---|
| 620 | * RETURNS
|
|---|
| 621 | * the string representation and HRESULT
|
|---|
| 622 | */
|
|---|
| 623 | HRESULT WINAPI StringFromCLSID16(
|
|---|
| 624 | REFCLSID id, /* [in] the GUID to be converted */
|
|---|
| 625 | LPOLESTR16 *idstr /* [out] a pointer to a to-be-allocated segmented pointer pointing to the resulting string */
|
|---|
| 626 |
|
|---|
| 627 | ) {
|
|---|
| 628 | extern BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
|
|---|
| 629 | DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode );
|
|---|
| 630 | LPMALLOC16 mllc;
|
|---|
| 631 | HRESULT ret;
|
|---|
| 632 | DWORD args[2];
|
|---|
| 633 |
|
|---|
| 634 | ret = CoGetMalloc16(0,&mllc);
|
|---|
| 635 | if (ret) return ret;
|
|---|
| 636 |
|
|---|
| 637 | args[0] = (DWORD)mllc;
|
|---|
| 638 | args[1] = 40;
|
|---|
| 639 |
|
|---|
| 640 | /* No need for a Callback entry, we have WOWCallback16Ex which does
|
|---|
| 641 | * everything we need.
|
|---|
| 642 | */
|
|---|
| 643 | if (!K32WOWCallback16Ex(
|
|---|
| 644 | (DWORD)((ICOM_VTABLE(IMalloc16)*)MapSL(
|
|---|
| 645 | (SEGPTR)ICOM_VTBL(((LPMALLOC16)MapSL((SEGPTR)mllc))))
|
|---|
| 646 | )->Alloc,
|
|---|
| 647 | WCB16_CDECL,
|
|---|
| 648 | 2*sizeof(DWORD),
|
|---|
| 649 | (LPVOID)args,
|
|---|
| 650 | (LPDWORD)idstr
|
|---|
| 651 | )) {
|
|---|
| 652 | WARN("CallTo16 IMalloc16 failed\n");
|
|---|
| 653 | return E_FAIL;
|
|---|
| 654 | }
|
|---|
| 655 | return WINE_StringFromCLSID(id,MapSL((SEGPTR)*idstr));
|
|---|
| 656 | }
|
|---|
| 657 | #endif
|
|---|
| 658 |
|
|---|
| 659 | /******************************************************************************
|
|---|
| 660 | * StringFromCLSID [OLE32.151]
|
|---|
| 661 | * StringFromIID [OLE32.153]
|
|---|
| 662 | * Converts a GUID into the respective string representation.
|
|---|
| 663 | * The target string is allocated using the OLE IMalloc.
|
|---|
| 664 | * RETURNS
|
|---|
| 665 | * the string representation and HRESULT
|
|---|
| 666 | */
|
|---|
| 667 | HRESULT WINAPI StringFromCLSID(
|
|---|
| 668 | REFCLSID id, /* [in] the GUID to be converted */
|
|---|
| 669 | LPOLESTR *idstr /* [out] a pointer to a to-be-allocated pointer pointing to the resulting string */
|
|---|
| 670 | ) {
|
|---|
| 671 | char buf[80];
|
|---|
| 672 | HRESULT ret;
|
|---|
| 673 | LPMALLOC mllc;
|
|---|
| 674 |
|
|---|
| 675 | if ((ret=CoGetMalloc(0,&mllc)))
|
|---|
| 676 | return ret;
|
|---|
| 677 |
|
|---|
| 678 | ret=WINE_StringFromCLSID(id,buf);
|
|---|
| 679 | if (!ret) {
|
|---|
| 680 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf, -1, NULL, 0 );
|
|---|
| 681 | *idstr = IMalloc_Alloc( mllc, len * sizeof(WCHAR) );
|
|---|
| 682 | MultiByteToWideChar( CP_ACP, 0, buf, -1, *idstr, len );
|
|---|
| 683 | }
|
|---|
| 684 | return ret;
|
|---|
| 685 | }
|
|---|
| 686 |
|
|---|
| 687 | /******************************************************************************
|
|---|
| 688 | * StringFromGUID2 [COMPOBJ.76]
|
|---|
| 689 | * StringFromGUID2 [OLE32.152]
|
|---|
| 690 | *
|
|---|
| 691 | * Converts a global unique identifier into a string of an API-
|
|---|
| 692 | * specified fixed format. (The usual {.....} stuff.)
|
|---|
| 693 | *
|
|---|
| 694 | * RETURNS
|
|---|
| 695 | * The (UNICODE) string representation of the GUID in 'str'
|
|---|
| 696 | * The length of the resulting string, 0 if there was any problem.
|
|---|
| 697 | */
|
|---|
| 698 | INT WINAPI
|
|---|
| 699 | StringFromGUID2(REFGUID id, LPOLESTR str, INT cmax)
|
|---|
| 700 | {
|
|---|
| 701 | char xguid[80];
|
|---|
| 702 |
|
|---|
| 703 | if (WINE_StringFromCLSID(id,xguid))
|
|---|
| 704 | return 0;
|
|---|
| 705 | return MultiByteToWideChar( CP_ACP, 0, xguid, -1, str, cmax );
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | /******************************************************************************
|
|---|
| 709 | * ProgIDFromCLSID [OLE32.133]
|
|---|
| 710 | * Converts a class id into the respective Program ID. (By using a registry lookup)
|
|---|
| 711 | * RETURNS S_OK on success
|
|---|
| 712 | * riid associated with the progid
|
|---|
| 713 | */
|
|---|
| 714 |
|
|---|
| 715 | HRESULT WINAPI ProgIDFromCLSID(
|
|---|
| 716 | REFCLSID clsid, /* [in] class id as found in registry */
|
|---|
| 717 | LPOLESTR *lplpszProgID/* [out] associated Prog ID */
|
|---|
| 718 | )
|
|---|
| 719 | {
|
|---|
| 720 | char strCLSID[50], *buf, *buf2;
|
|---|
| 721 | DWORD buf2len;
|
|---|
| 722 | HKEY xhkey;
|
|---|
| 723 | LPMALLOC mllc;
|
|---|
| 724 | HRESULT ret = S_OK;
|
|---|
| 725 |
|
|---|
| 726 | WINE_StringFromCLSID(clsid, strCLSID);
|
|---|
| 727 |
|
|---|
| 728 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(strCLSID)+14);
|
|---|
| 729 | sprintf(buf,"CLSID\\%s\\ProgID", strCLSID);
|
|---|
| 730 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
|---|
| 731 | ret = REGDB_E_CLASSNOTREG;
|
|---|
| 732 |
|
|---|
| 733 | HeapFree(GetProcessHeap(), 0, buf);
|
|---|
| 734 |
|
|---|
| 735 | if (ret == S_OK)
|
|---|
| 736 | {
|
|---|
| 737 | buf2 = HeapAlloc(GetProcessHeap(), 0, 255);
|
|---|
| 738 | buf2len = 255;
|
|---|
| 739 | if (RegQueryValueA(xhkey, NULL, buf2, &buf2len))
|
|---|
| 740 | ret = REGDB_E_CLASSNOTREG;
|
|---|
| 741 |
|
|---|
| 742 | if (ret == S_OK)
|
|---|
| 743 | {
|
|---|
| 744 | if (CoGetMalloc(0,&mllc))
|
|---|
| 745 | ret = E_OUTOFMEMORY;
|
|---|
| 746 | else
|
|---|
| 747 | {
|
|---|
| 748 | DWORD len = MultiByteToWideChar( CP_ACP, 0, buf2, -1, NULL, 0 );
|
|---|
| 749 | *lplpszProgID = IMalloc_Alloc(mllc, len * sizeof(WCHAR) );
|
|---|
| 750 | MultiByteToWideChar( CP_ACP, 0, buf2, -1, *lplpszProgID, len );
|
|---|
| 751 | }
|
|---|
| 752 | }
|
|---|
| 753 | HeapFree(GetProcessHeap(), 0, buf2);
|
|---|
| 754 | }
|
|---|
| 755 |
|
|---|
| 756 | RegCloseKey(xhkey);
|
|---|
| 757 | return ret;
|
|---|
| 758 | }
|
|---|
| 759 |
|
|---|
| 760 | /******************************************************************************
|
|---|
| 761 | * CLSIDFromProgID [COMPOBJ.61]
|
|---|
| 762 | * Converts a program id into the respective GUID. (By using a registry lookup)
|
|---|
| 763 | * RETURNS
|
|---|
| 764 | * riid associated with the progid
|
|---|
| 765 | */
|
|---|
| 766 | HRESULT WINAPI CLSIDFromProgID16(
|
|---|
| 767 | LPCOLESTR16 progid, /* [in] program id as found in registry */
|
|---|
| 768 | LPCLSID riid /* [out] associated CLSID */
|
|---|
| 769 | ) {
|
|---|
| 770 | char *buf,buf2[80];
|
|---|
| 771 | DWORD buf2len;
|
|---|
| 772 | HRESULT err;
|
|---|
| 773 | HKEY xhkey;
|
|---|
| 774 |
|
|---|
| 775 | buf = HeapAlloc(GetProcessHeap(),0,strlen(progid)+8);
|
|---|
| 776 | sprintf(buf,"%s\\CLSID",progid);
|
|---|
| 777 | if ((err=RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&xhkey))) {
|
|---|
| 778 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 779 | return CO_E_CLASSSTRING;
|
|---|
| 780 | }
|
|---|
| 781 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 782 | buf2len = sizeof(buf2);
|
|---|
| 783 | if ((err=RegQueryValueA(xhkey,NULL,buf2,&buf2len))) {
|
|---|
| 784 | RegCloseKey(xhkey);
|
|---|
| 785 | return CO_E_CLASSSTRING;
|
|---|
| 786 | }
|
|---|
| 787 | RegCloseKey(xhkey);
|
|---|
| 788 | return CLSIDFromString16(buf2,riid);
|
|---|
| 789 | }
|
|---|
| 790 |
|
|---|
| 791 | /******************************************************************************
|
|---|
| 792 | * CLSIDFromProgID [OLE32.2]
|
|---|
| 793 | * Converts a program id into the respective GUID. (By using a registry lookup)
|
|---|
| 794 | * RETURNS
|
|---|
| 795 | * riid associated with the progid
|
|---|
| 796 | */
|
|---|
| 797 | HRESULT WINAPI CLSIDFromProgID(
|
|---|
| 798 | LPCOLESTR progid, /* [in] program id as found in registry */
|
|---|
| 799 | LPCLSID riid ) /* [out] associated CLSID */
|
|---|
| 800 | {
|
|---|
| 801 | static const WCHAR clsidW[] = { '\\','C','L','S','I','D',0 };
|
|---|
| 802 | char buf2[80];
|
|---|
| 803 | DWORD buf2len = sizeof(buf2);
|
|---|
| 804 | HKEY xhkey;
|
|---|
| 805 |
|
|---|
| 806 | WCHAR *buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
|
|---|
| 807 | strcpyW( buf, progid );
|
|---|
| 808 | strcatW( buf, clsidW );
|
|---|
| 809 | if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
|
|---|
| 810 | {
|
|---|
| 811 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 812 | return CO_E_CLASSSTRING;
|
|---|
| 813 | }
|
|---|
| 814 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 815 |
|
|---|
| 816 | if (RegQueryValueA(xhkey,NULL,buf2,&buf2len))
|
|---|
| 817 | {
|
|---|
| 818 | RegCloseKey(xhkey);
|
|---|
| 819 | return CO_E_CLASSSTRING;
|
|---|
| 820 | }
|
|---|
| 821 | RegCloseKey(xhkey);
|
|---|
| 822 | return CLSIDFromString16(buf2,riid);
|
|---|
| 823 | }
|
|---|
| 824 |
|
|---|
| 825 |
|
|---|
| 826 |
|
|---|
| 827 | /*****************************************************************************
|
|---|
| 828 | * CoGetPSClsid [OLE32.22]
|
|---|
| 829 | *
|
|---|
| 830 | * This function returns the CLSID of the DLL that implements the proxy and stub
|
|---|
| 831 | * for the specified interface.
|
|---|
| 832 | *
|
|---|
| 833 | * It determines this by searching the
|
|---|
| 834 | * HKEY_CLASSES_ROOT\Interface\{string form of riid}\ProxyStubClsid32 in the registry
|
|---|
| 835 | * and any interface id registered by CoRegisterPSClsid within the current process.
|
|---|
| 836 | *
|
|---|
| 837 | * FIXME: We only search the registry, not ids registered with CoRegisterPSClsid.
|
|---|
| 838 | */
|
|---|
| 839 | HRESULT WINAPI CoGetPSClsid(
|
|---|
| 840 | REFIID riid, /* [in] Interface whose proxy/stub CLSID is to be returned */
|
|---|
| 841 | CLSID *pclsid ) /* [out] Where to store returned proxy/stub CLSID */
|
|---|
| 842 | {
|
|---|
| 843 | char *buf, buf2[40];
|
|---|
| 844 | DWORD buf2len;
|
|---|
| 845 | HKEY xhkey;
|
|---|
| 846 |
|
|---|
| 847 | TRACE("() riid=%s, pclsid=%p\n", debugstr_guid(riid), pclsid);
|
|---|
| 848 |
|
|---|
| 849 | /* Get the input iid as a string */
|
|---|
| 850 | WINE_StringFromCLSID(riid, buf2);
|
|---|
| 851 | /* Allocate memory for the registry key we will construct.
|
|---|
| 852 | (length of iid string plus constant length of static text */
|
|---|
| 853 | buf = HeapAlloc(GetProcessHeap(), 0, strlen(buf2)+27);
|
|---|
| 854 | if (buf == NULL)
|
|---|
| 855 | {
|
|---|
| 856 | return (E_OUTOFMEMORY);
|
|---|
| 857 | }
|
|---|
| 858 |
|
|---|
| 859 | /* Construct the registry key we want */
|
|---|
| 860 | sprintf(buf,"Interface\\%s\\ProxyStubClsid32", buf2);
|
|---|
| 861 |
|
|---|
| 862 | /* Open the key.. */
|
|---|
| 863 | if (RegOpenKeyA(HKEY_CLASSES_ROOT, buf, &xhkey))
|
|---|
| 864 | {
|
|---|
| 865 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 866 | return (E_INVALIDARG);
|
|---|
| 867 | }
|
|---|
| 868 | HeapFree(GetProcessHeap(),0,buf);
|
|---|
| 869 |
|
|---|
| 870 | /* ... Once we have the key, query the registry to get the
|
|---|
| 871 | value of CLSID as a string, and convert it into a
|
|---|
| 872 | proper CLSID structure to be passed back to the app */
|
|---|
| 873 | buf2len = sizeof(buf2);
|
|---|
| 874 | if ( (RegQueryValueA(xhkey,NULL,buf2,&buf2len)) )
|
|---|
| 875 | {
|
|---|
| 876 | RegCloseKey(xhkey);
|
|---|
| 877 | return E_INVALIDARG;
|
|---|
| 878 | }
|
|---|
| 879 | RegCloseKey(xhkey);
|
|---|
| 880 |
|
|---|
| 881 | /* We have the CLSid we want back from the registry as a string, so
|
|---|
| 882 | lets convert it into a CLSID structure */
|
|---|
| 883 | if ( (CLSIDFromString16(buf2,pclsid)) != NOERROR)
|
|---|
| 884 | {
|
|---|
| 885 | return E_INVALIDARG;
|
|---|
| 886 | }
|
|---|
| 887 |
|
|---|
| 888 | TRACE ("() Returning CLSID=%s\n", debugstr_guid(pclsid));
|
|---|
| 889 | return (S_OK);
|
|---|
| 890 | }
|
|---|
| 891 |
|
|---|
| 892 |
|
|---|
| 893 |
|
|---|
| 894 | /***********************************************************************
|
|---|
| 895 | * WriteClassStm (OLE32.159)
|
|---|
| 896 | *
|
|---|
| 897 | * This function write a CLSID on stream
|
|---|
| 898 | */
|
|---|
| 899 | HRESULT WINAPI WriteClassStm(IStream *pStm,REFCLSID rclsid)
|
|---|
| 900 | {
|
|---|
| 901 | TRACE("(%p,%p)\n",pStm,rclsid);
|
|---|
| 902 |
|
|---|
| 903 | if (rclsid==NULL)
|
|---|
| 904 | return E_INVALIDARG;
|
|---|
| 905 |
|
|---|
| 906 | return IStream_Write(pStm,rclsid,sizeof(CLSID),NULL);
|
|---|
| 907 | }
|
|---|
| 908 |
|
|---|
| 909 | /***********************************************************************
|
|---|
| 910 | * ReadClassStm (OLE32.135)
|
|---|
| 911 | *
|
|---|
| 912 | * This function read a CLSID from a stream
|
|---|
| 913 | */
|
|---|
| 914 | HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
|
|---|
| 915 | {
|
|---|
| 916 | ULONG nbByte;
|
|---|
| 917 | HRESULT res;
|
|---|
| 918 |
|
|---|
| 919 | TRACE("(%p,%p)\n",pStm,pclsid);
|
|---|
| 920 |
|
|---|
| 921 | if (pclsid==NULL)
|
|---|
| 922 | return E_INVALIDARG;
|
|---|
| 923 |
|
|---|
| 924 | res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
|
|---|
| 925 |
|
|---|
| 926 | if (FAILED(res))
|
|---|
| 927 | return res;
|
|---|
| 928 |
|
|---|
| 929 | if (nbByte != sizeof(CLSID))
|
|---|
| 930 | return S_FALSE;
|
|---|
| 931 | else
|
|---|
| 932 | return S_OK;
|
|---|
| 933 | }
|
|---|
| 934 |
|
|---|
| 935 | #ifndef __WIN32OS2__
|
|---|
| 936 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
|---|
| 937 | /***********************************************************************
|
|---|
| 938 | * LookupETask (COMPOBJ.94)
|
|---|
| 939 | */
|
|---|
| 940 | HRESULT WINAPI LookupETask16(HTASK16 *hTask,LPVOID p) {
|
|---|
| 941 | FIXME("(%p,%p),stub!\n",hTask,p);
|
|---|
| 942 | if ((*hTask = GetCurrentTask()) == hETask) {
|
|---|
| 943 | memcpy(p, Table_ETask, sizeof(Table_ETask));
|
|---|
| 944 | }
|
|---|
| 945 | return 0;
|
|---|
| 946 | }
|
|---|
| 947 |
|
|---|
| 948 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
|---|
| 949 | /***********************************************************************
|
|---|
| 950 | * SetETask (COMPOBJ.95)
|
|---|
| 951 | */
|
|---|
| 952 | HRESULT WINAPI SetETask16(HTASK16 hTask, LPVOID p) {
|
|---|
| 953 | FIXME("(%04x,%p),stub!\n",hTask,p);
|
|---|
| 954 | hETask = hTask;
|
|---|
| 955 | return 0;
|
|---|
| 956 | }
|
|---|
| 957 | #endif
|
|---|
| 958 | /* FIXME: this function is not declared in the WINELIB headers. But where should it go ? */
|
|---|
| 959 | /***********************************************************************
|
|---|
| 960 | * CALLOBJECTINWOW (COMPOBJ.201)
|
|---|
| 961 | */
|
|---|
| 962 | HRESULT WINAPI CallObjectInWOW(LPVOID p1,LPVOID p2) {
|
|---|
| 963 | FIXME("(%p,%p),stub!\n",p1,p2);
|
|---|
| 964 | return 0;
|
|---|
| 965 | }
|
|---|
| 966 |
|
|---|
| 967 | /******************************************************************************
|
|---|
| 968 | * CoRegisterClassObject [COMPOBJ.5]
|
|---|
| 969 | *
|
|---|
| 970 | * Don't know where it registers it ...
|
|---|
| 971 | */
|
|---|
| 972 | HRESULT WINAPI CoRegisterClassObject16(
|
|---|
| 973 | REFCLSID rclsid,
|
|---|
| 974 | LPUNKNOWN pUnk,
|
|---|
| 975 | DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
|
|---|
| 976 | DWORD flags, /* [in] REGCLS flags indicating how connections are made */
|
|---|
| 977 | LPDWORD lpdwRegister
|
|---|
| 978 | ) {
|
|---|
| 979 | char buf[80];
|
|---|
| 980 |
|
|---|
| 981 | WINE_StringFromCLSID(rclsid,buf);
|
|---|
| 982 |
|
|---|
| 983 | FIXME("(%s,%p,0x%08lx,0x%08lx,%p),stub\n",
|
|---|
| 984 | buf,pUnk,dwClsContext,flags,lpdwRegister
|
|---|
| 985 | );
|
|---|
| 986 | return 0;
|
|---|
| 987 | }
|
|---|
| 988 |
|
|---|
| 989 |
|
|---|
| 990 | /******************************************************************************
|
|---|
| 991 | * CoRevokeClassObject [COMPOBJ.6]
|
|---|
| 992 | *
|
|---|
| 993 | */
|
|---|
| 994 | HRESULT WINAPI CoRevokeClassObject16(DWORD dwRegister) /* [in] token on class obj */
|
|---|
| 995 | {
|
|---|
| 996 | FIXME("(0x%08lx),stub!\n", dwRegister);
|
|---|
| 997 | return 0;
|
|---|
| 998 | }
|
|---|
| 999 |
|
|---|
| 1000 | /******************************************************************************
|
|---|
| 1001 | * CoFileTimeToDosDateTime [COMPOBJ.30]
|
|---|
| 1002 | */
|
|---|
| 1003 | BOOL16 WINAPI CoFileTimeToDosDateTime16(const FILETIME *ft, LPWORD lpDosDate, LPWORD lpDosTime)
|
|---|
| 1004 | {
|
|---|
| 1005 | return FileTimeToDosDateTime(ft, lpDosDate, lpDosTime);
|
|---|
| 1006 | }
|
|---|
| 1007 |
|
|---|
| 1008 | /******************************************************************************
|
|---|
| 1009 | * CoDosDateTimeToFileTime [COMPOBJ.31]
|
|---|
| 1010 | */
|
|---|
| 1011 | BOOL16 WINAPI CoDosDateTimeToFileTime16(WORD wDosDate, WORD wDosTime, FILETIME *ft)
|
|---|
| 1012 | {
|
|---|
| 1013 | return DosDateTimeToFileTime(wDosDate, wDosTime, ft);
|
|---|
| 1014 | }
|
|---|
| 1015 |
|
|---|
| 1016 | /***
|
|---|
| 1017 | * COM_GetRegisteredClassObject
|
|---|
| 1018 | *
|
|---|
| 1019 | * This internal method is used to scan the registered class list to
|
|---|
| 1020 | * find a class object.
|
|---|
| 1021 | *
|
|---|
| 1022 | * Params:
|
|---|
| 1023 | * rclsid Class ID of the class to find.
|
|---|
| 1024 | * dwClsContext Class context to match.
|
|---|
| 1025 | * ppv [out] returns a pointer to the class object. Complying
|
|---|
| 1026 | * to normal COM usage, this method will increase the
|
|---|
| 1027 | * reference count on this object.
|
|---|
| 1028 | */
|
|---|
| 1029 | static HRESULT COM_GetRegisteredClassObject(
|
|---|
| 1030 | REFCLSID rclsid,
|
|---|
| 1031 | DWORD dwClsContext,
|
|---|
| 1032 | LPUNKNOWN* ppUnk)
|
|---|
| 1033 | {
|
|---|
| 1034 | HRESULT hr = S_FALSE;
|
|---|
| 1035 | RegisteredClass* curClass;
|
|---|
| 1036 |
|
|---|
| 1037 | EnterCriticalSection( &csRegisteredClassList );
|
|---|
| 1038 |
|
|---|
| 1039 | /*
|
|---|
| 1040 | * Sanity check
|
|---|
| 1041 | */
|
|---|
| 1042 | assert(ppUnk!=0);
|
|---|
| 1043 |
|
|---|
| 1044 | /*
|
|---|
| 1045 | * Iterate through the whole list and try to match the class ID.
|
|---|
| 1046 | */
|
|---|
| 1047 | curClass = firstRegisteredClass;
|
|---|
| 1048 |
|
|---|
| 1049 | while (curClass != 0)
|
|---|
| 1050 | {
|
|---|
| 1051 | /*
|
|---|
| 1052 | * Check if we have a match on the class ID.
|
|---|
| 1053 | */
|
|---|
| 1054 | if (IsEqualGUID(&(curClass->classIdentifier), rclsid))
|
|---|
| 1055 | {
|
|---|
| 1056 | /*
|
|---|
| 1057 | * Since we don't do out-of process or DCOM just right away, let's ignore the
|
|---|
| 1058 | * class context.
|
|---|
| 1059 | */
|
|---|
| 1060 |
|
|---|
| 1061 | /*
|
|---|
| 1062 | * We have a match, return the pointer to the class object.
|
|---|
| 1063 | */
|
|---|
| 1064 | *ppUnk = curClass->classObject;
|
|---|
| 1065 |
|
|---|
| 1066 | IUnknown_AddRef(curClass->classObject);
|
|---|
| 1067 |
|
|---|
| 1068 | hr = S_OK;
|
|---|
| 1069 | goto end;
|
|---|
| 1070 | }
|
|---|
| 1071 |
|
|---|
| 1072 | /*
|
|---|
| 1073 | * Step to the next class in the list.
|
|---|
| 1074 | */
|
|---|
| 1075 | curClass = curClass->nextClass;
|
|---|
| 1076 | }
|
|---|
| 1077 |
|
|---|
| 1078 | end:
|
|---|
| 1079 | LeaveCriticalSection( &csRegisteredClassList );
|
|---|
| 1080 | /*
|
|---|
| 1081 | * If we get to here, we haven't found our class.
|
|---|
| 1082 | */
|
|---|
| 1083 | return hr;
|
|---|
| 1084 | }
|
|---|
| 1085 |
|
|---|
| 1086 | static DWORD WINAPI
|
|---|
| 1087 | _LocalServerThread(LPVOID param) {
|
|---|
| 1088 | HANDLE hPipe;
|
|---|
| 1089 | char pipefn[200];
|
|---|
| 1090 | RegisteredClass *newClass = (RegisteredClass*)param;
|
|---|
| 1091 | HRESULT hres;
|
|---|
| 1092 | IStream *pStm;
|
|---|
| 1093 | STATSTG ststg;
|
|---|
| 1094 | unsigned char *buffer;
|
|---|
| 1095 | int buflen;
|
|---|
| 1096 | IClassFactory *classfac;
|
|---|
| 1097 | LARGE_INTEGER seekto;
|
|---|
| 1098 | ULARGE_INTEGER newpos;
|
|---|
| 1099 | ULONG res;
|
|---|
| 1100 |
|
|---|
| 1101 | TRACE("Starting threader for %s.\n",debugstr_guid(&newClass->classIdentifier));
|
|---|
| 1102 | strcpy(pipefn,PIPEPREF);
|
|---|
| 1103 | WINE_StringFromCLSID(&newClass->classIdentifier,pipefn+strlen(PIPEPREF));
|
|---|
| 1104 |
|
|---|
| 1105 | hres = IUnknown_QueryInterface(newClass->classObject,&IID_IClassFactory,(LPVOID*)&classfac);
|
|---|
| 1106 | if (hres) return hres;
|
|---|
| 1107 |
|
|---|
| 1108 | hres = CreateStreamOnHGlobal(0,TRUE,&pStm);
|
|---|
| 1109 | if (hres) {
|
|---|
| 1110 | FIXME("Failed to create stream on hglobal.\n");
|
|---|
| 1111 | return hres;
|
|---|
| 1112 | }
|
|---|
| 1113 | hres = CoMarshalInterface(pStm,&IID_IClassFactory,(LPVOID)classfac,0,NULL,0);
|
|---|
| 1114 | if (hres) {
|
|---|
| 1115 | FIXME("CoMarshalInterface failed, %lx!\n",hres);
|
|---|
| 1116 | return hres;
|
|---|
| 1117 | }
|
|---|
| 1118 | hres = IStream_Stat(pStm,&ststg,0);
|
|---|
| 1119 | if (hres) return hres;
|
|---|
| 1120 |
|
|---|
| 1121 | buflen = ststg.cbSize.s.LowPart;
|
|---|
| 1122 | buffer = HeapAlloc(GetProcessHeap(),0,buflen);
|
|---|
| 1123 | seekto.s.LowPart = 0;
|
|---|
| 1124 | seekto.s.HighPart = 0;
|
|---|
| 1125 | hres = IStream_Seek(pStm,seekto,SEEK_SET,&newpos);
|
|---|
| 1126 | if (hres) {
|
|---|
| 1127 | FIXME("IStream_Seek failed, %lx\n",hres);
|
|---|
| 1128 | return hres;
|
|---|
| 1129 | }
|
|---|
| 1130 | hres = IStream_Read(pStm,buffer,buflen,&res);
|
|---|
| 1131 | if (hres) {
|
|---|
| 1132 | FIXME("Stream Read failed, %lx\n",hres);
|
|---|
| 1133 | return hres;
|
|---|
| 1134 | }
|
|---|
| 1135 | IStream_Release(pStm);
|
|---|
| 1136 |
|
|---|
| 1137 | while (1) {
|
|---|
| 1138 | hPipe = CreateNamedPipeA(
|
|---|
| 1139 | pipefn,
|
|---|
| 1140 | PIPE_ACCESS_DUPLEX,
|
|---|
| 1141 | PIPE_TYPE_BYTE|PIPE_WAIT,
|
|---|
| 1142 | PIPE_UNLIMITED_INSTANCES,
|
|---|
| 1143 | 4096,
|
|---|
| 1144 | 4096,
|
|---|
| 1145 | NMPWAIT_USE_DEFAULT_WAIT,
|
|---|
| 1146 | NULL
|
|---|
| 1147 | );
|
|---|
| 1148 | if (hPipe == INVALID_HANDLE_VALUE) {
|
|---|
| 1149 | FIXME("pipe creation failed for %s, le is %lx\n",pipefn,GetLastError());
|
|---|
| 1150 | return 1;
|
|---|
| 1151 | }
|
|---|
| 1152 | if (!ConnectNamedPipe(hPipe,NULL)) {
|
|---|
| 1153 | ERR("Failure during ConnectNamedPipe %lx, ABORT!\n",GetLastError());
|
|---|
| 1154 | CloseHandle(hPipe);
|
|---|
| 1155 | continue;
|
|---|
| 1156 | }
|
|---|
| 1157 | WriteFile(hPipe,buffer,buflen,&res,NULL);
|
|---|
| 1158 | CloseHandle(hPipe);
|
|---|
| 1159 | }
|
|---|
| 1160 | return 0;
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | /******************************************************************************
|
|---|
| 1164 | * CoRegisterClassObject [OLE32.36]
|
|---|
| 1165 | *
|
|---|
| 1166 | * This method will register the class object for a given class ID.
|
|---|
| 1167 | *
|
|---|
| 1168 | * See the Windows documentation for more details.
|
|---|
| 1169 | */
|
|---|
| 1170 | HRESULT WINAPI CoRegisterClassObject(
|
|---|
| 1171 | REFCLSID rclsid,
|
|---|
| 1172 | LPUNKNOWN pUnk,
|
|---|
| 1173 | DWORD dwClsContext, /* [in] CLSCTX flags indicating the context in which to run the executable */
|
|---|
| 1174 | DWORD flags, /* [in] REGCLS flags indicating how connections are made */
|
|---|
| 1175 | LPDWORD lpdwRegister
|
|---|
| 1176 | )
|
|---|
| 1177 | {
|
|---|
| 1178 | RegisteredClass* newClass;
|
|---|
| 1179 | LPUNKNOWN foundObject;
|
|---|
| 1180 | HRESULT hr;
|
|---|
| 1181 |
|
|---|
| 1182 | TRACE("(%s,%p,0x%08lx,0x%08lx,%p)\n",
|
|---|
| 1183 | debugstr_guid(rclsid),pUnk,dwClsContext,flags,lpdwRegister);
|
|---|
| 1184 |
|
|---|
| 1185 | if ( (lpdwRegister==0) || (pUnk==0) )
|
|---|
| 1186 | return E_INVALIDARG;
|
|---|
| 1187 |
|
|---|
| 1188 | *lpdwRegister = 0;
|
|---|
| 1189 |
|
|---|
| 1190 | /*
|
|---|
| 1191 | * First, check if the class is already registered.
|
|---|
| 1192 | * If it is, this should cause an error.
|
|---|
| 1193 | */
|
|---|
| 1194 | hr = COM_GetRegisteredClassObject(rclsid, dwClsContext, &foundObject);
|
|---|
| 1195 | if (hr == S_OK) {
|
|---|
| 1196 | IUnknown_Release(foundObject);
|
|---|
| 1197 | return CO_E_OBJISREG;
|
|---|
| 1198 | }
|
|---|
| 1199 |
|
|---|
| 1200 | newClass = HeapAlloc(GetProcessHeap(), 0, sizeof(RegisteredClass));
|
|---|
| 1201 | if ( newClass == NULL )
|
|---|
| 1202 | return E_OUTOFMEMORY;
|
|---|
| 1203 |
|
|---|
| 1204 | EnterCriticalSection( &csRegisteredClassList );
|
|---|
| 1205 |
|
|---|
| 1206 | newClass->classIdentifier = *rclsid;
|
|---|
| 1207 | newClass->runContext = dwClsContext;
|
|---|
| 1208 | newClass->connectFlags = flags;
|
|---|
| 1209 | /*
|
|---|
| 1210 | * Use the address of the chain node as the cookie since we are sure it's
|
|---|
| 1211 | * unique.
|
|---|
| 1212 | */
|
|---|
| 1213 | newClass->dwCookie = (DWORD)newClass;
|
|---|
| 1214 | newClass->nextClass = firstRegisteredClass;
|
|---|
| 1215 |
|
|---|
| 1216 | /*
|
|---|
| 1217 | * Since we're making a copy of the object pointer, we have to increase its
|
|---|
| 1218 | * reference count.
|
|---|
| 1219 | */
|
|---|
| 1220 | newClass->classObject = pUnk;
|
|---|
| 1221 | IUnknown_AddRef(newClass->classObject);
|
|---|
| 1222 |
|
|---|
| 1223 | firstRegisteredClass = newClass;
|
|---|
| 1224 | LeaveCriticalSection( &csRegisteredClassList );
|
|---|
| 1225 |
|
|---|
| 1226 | *lpdwRegister = newClass->dwCookie;
|
|---|
| 1227 |
|
|---|
| 1228 | if (dwClsContext & CLSCTX_LOCAL_SERVER) {
|
|---|
| 1229 | DWORD tid;
|
|---|
| 1230 |
|
|---|
| 1231 | STUBMGR_Start();
|
|---|
| 1232 | newClass->hThread=CreateThread(NULL,0,_LocalServerThread,newClass,0,&tid);
|
|---|
| 1233 | }
|
|---|
| 1234 | return S_OK;
|
|---|
| 1235 | }
|
|---|
| 1236 |
|
|---|
| 1237 | /***********************************************************************
|
|---|
| 1238 | * CoRevokeClassObject [OLE32.40]
|
|---|
| 1239 | *
|
|---|
| 1240 | * This method will remove a class object from the class registry
|
|---|
| 1241 | *
|
|---|
| 1242 | * See the Windows documentation for more details.
|
|---|
| 1243 | */
|
|---|
| 1244 | HRESULT WINAPI CoRevokeClassObject(
|
|---|
| 1245 | DWORD dwRegister)
|
|---|
| 1246 | {
|
|---|
| 1247 | HRESULT hr = E_INVALIDARG;
|
|---|
| 1248 | RegisteredClass** prevClassLink;
|
|---|
| 1249 | RegisteredClass* curClass;
|
|---|
| 1250 |
|
|---|
| 1251 | TRACE("(%08lx)\n",dwRegister);
|
|---|
| 1252 |
|
|---|
| 1253 | EnterCriticalSection( &csRegisteredClassList );
|
|---|
| 1254 |
|
|---|
| 1255 | /*
|
|---|
| 1256 | * Iterate through the whole list and try to match the cookie.
|
|---|
| 1257 | */
|
|---|
| 1258 | curClass = firstRegisteredClass;
|
|---|
| 1259 | prevClassLink = &firstRegisteredClass;
|
|---|
| 1260 |
|
|---|
| 1261 | while (curClass != 0)
|
|---|
| 1262 | {
|
|---|
| 1263 | /*
|
|---|
| 1264 | * Check if we have a match on the cookie.
|
|---|
| 1265 | */
|
|---|
| 1266 | if (curClass->dwCookie == dwRegister)
|
|---|
| 1267 | {
|
|---|
| 1268 | /*
|
|---|
| 1269 | * Remove the class from the chain.
|
|---|
| 1270 | */
|
|---|
| 1271 | *prevClassLink = curClass->nextClass;
|
|---|
| 1272 |
|
|---|
| 1273 | /*
|
|---|
| 1274 | * Release the reference to the class object.
|
|---|
| 1275 | */
|
|---|
| 1276 | IUnknown_Release(curClass->classObject);
|
|---|
| 1277 |
|
|---|
| 1278 | /*
|
|---|
| 1279 | * Free the memory used by the chain node.
|
|---|
| 1280 | */
|
|---|
| 1281 | HeapFree(GetProcessHeap(), 0, curClass);
|
|---|
| 1282 |
|
|---|
| 1283 | hr = S_OK;
|
|---|
| 1284 | goto end;
|
|---|
| 1285 | }
|
|---|
| 1286 |
|
|---|
| 1287 | /*
|
|---|
| 1288 | * Step to the next class in the list.
|
|---|
| 1289 | */
|
|---|
| 1290 | prevClassLink = &(curClass->nextClass);
|
|---|
| 1291 | curClass = curClass->nextClass;
|
|---|
| 1292 | }
|
|---|
| 1293 |
|
|---|
| 1294 | end:
|
|---|
| 1295 | LeaveCriticalSection( &csRegisteredClassList );
|
|---|
| 1296 | /*
|
|---|
| 1297 | * If we get to here, we haven't found our class.
|
|---|
| 1298 | */
|
|---|
| 1299 | return hr;
|
|---|
| 1300 | }
|
|---|
| 1301 |
|
|---|
| 1302 | static HRESULT WINAPI Remote_CoGetClassObject(
|
|---|
| 1303 | REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
|
|---|
| 1304 | REFIID iid, LPVOID *ppv
|
|---|
| 1305 | ) {
|
|---|
| 1306 | HKEY key;
|
|---|
| 1307 | char buf[200];
|
|---|
| 1308 | HRESULT hres = E_UNEXPECTED;
|
|---|
| 1309 | char xclsid[80];
|
|---|
| 1310 | WCHAR dllName[MAX_PATH+1];
|
|---|
| 1311 | DWORD dllNameLen = sizeof(dllName);
|
|---|
| 1312 | STARTUPINFOW sinfo;
|
|---|
| 1313 | PROCESS_INFORMATION pinfo;
|
|---|
| 1314 |
|
|---|
| 1315 | WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
|
|---|
| 1316 |
|
|---|
| 1317 | sprintf(buf,"CLSID\\%s\\LocalServer32",xclsid);
|
|---|
| 1318 | hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key);
|
|---|
| 1319 |
|
|---|
| 1320 | if (hres != ERROR_SUCCESS)
|
|---|
| 1321 | return REGDB_E_CLASSNOTREG;
|
|---|
| 1322 |
|
|---|
| 1323 | memset(dllName,0,sizeof(dllName));
|
|---|
| 1324 | hres= RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)dllName,&dllNameLen);
|
|---|
| 1325 | if (hres)
|
|---|
| 1326 | return REGDB_E_CLASSNOTREG; /* FIXME: check retval */
|
|---|
| 1327 | RegCloseKey(key);
|
|---|
| 1328 |
|
|---|
| 1329 | TRACE("found LocalServer32 exe %s\n", debugstr_w(dllName));
|
|---|
| 1330 |
|
|---|
| 1331 | memset(&sinfo,0,sizeof(sinfo));
|
|---|
| 1332 | sinfo.cb = sizeof(sinfo);
|
|---|
| 1333 | if (!CreateProcessW(NULL,dllName,NULL,NULL,FALSE,0,NULL,NULL,&sinfo,&pinfo))
|
|---|
| 1334 | return E_FAIL;
|
|---|
| 1335 | return create_marshalled_proxy(rclsid,iid,ppv);
|
|---|
| 1336 | }
|
|---|
| 1337 |
|
|---|
| 1338 | /***********************************************************************
|
|---|
| 1339 | * CoGetClassObject [COMPOBJ.7]
|
|---|
| 1340 | * CoGetClassObject [OLE32.16]
|
|---|
| 1341 | *
|
|---|
| 1342 | * FIXME. If request allows of several options and there is a failure
|
|---|
| 1343 | * with one (other than not being registered) do we try the
|
|---|
| 1344 | * others or return failure? (E.g. inprocess is registered but
|
|---|
| 1345 | * the DLL is not found but the server version works)
|
|---|
| 1346 | */
|
|---|
| 1347 | HRESULT WINAPI CoGetClassObject(
|
|---|
| 1348 | REFCLSID rclsid, DWORD dwClsContext, COSERVERINFO *pServerInfo,
|
|---|
| 1349 | REFIID iid, LPVOID *ppv
|
|---|
| 1350 | ) {
|
|---|
| 1351 | LPUNKNOWN regClassObject;
|
|---|
| 1352 | HRESULT hres = E_UNEXPECTED;
|
|---|
| 1353 | char xclsid[80];
|
|---|
| 1354 | WCHAR ProviderName[MAX_PATH+1];
|
|---|
| 1355 | DWORD ProviderNameLen = sizeof(ProviderName);
|
|---|
| 1356 | HINSTANCE hLibrary;
|
|---|
| 1357 | #ifdef __WIN32OS2__
|
|---|
| 1358 | typedef HRESULT (* CALLBACK DllGetClassObjectFunc)(REFCLSID clsid,
|
|---|
| 1359 | REFIID iid, LPVOID *ppv);
|
|---|
| 1360 | #else
|
|---|
| 1361 | typedef HRESULT (CALLBACK *DllGetClassObjectFunc)(REFCLSID clsid,
|
|---|
| 1362 | REFIID iid, LPVOID *ppv);
|
|---|
| 1363 | #endif
|
|---|
| 1364 | DllGetClassObjectFunc DllGetClassObject;
|
|---|
| 1365 | HKEY key;
|
|---|
| 1366 | char buf[200];
|
|---|
| 1367 |
|
|---|
| 1368 | WINE_StringFromCLSID((LPCLSID)rclsid,xclsid);
|
|---|
| 1369 |
|
|---|
| 1370 | TRACE("\n\tCLSID:\t%s,\n\tIID:\t%s\n",
|
|---|
| 1371 | debugstr_guid(rclsid),
|
|---|
| 1372 | debugstr_guid(iid)
|
|---|
| 1373 | );
|
|---|
| 1374 |
|
|---|
| 1375 | if (pServerInfo) {
|
|---|
| 1376 | FIXME("\tpServerInfo: name=%s\n",debugstr_w(pServerInfo->pwszName));
|
|---|
| 1377 | FIXME("\t\tpAuthInfo=%p\n",pServerInfo->pAuthInfo);
|
|---|
| 1378 | }
|
|---|
| 1379 |
|
|---|
| 1380 | /*
|
|---|
| 1381 | * First, try and see if we can't match the class ID with one of the
|
|---|
| 1382 | * registered classes.
|
|---|
| 1383 | */
|
|---|
| 1384 | if (S_OK == COM_GetRegisteredClassObject(rclsid, dwClsContext, ®ClassObject))
|
|---|
| 1385 | {
|
|---|
| 1386 | /*
|
|---|
| 1387 | * Get the required interface from the retrieved pointer.
|
|---|
| 1388 | */
|
|---|
| 1389 | hres = IUnknown_QueryInterface(regClassObject, iid, ppv);
|
|---|
| 1390 |
|
|---|
| 1391 | /*
|
|---|
| 1392 | * Since QI got another reference on the pointer, we want to release the
|
|---|
| 1393 | * one we already have. If QI was unsuccessful, this will release the object. This
|
|---|
| 1394 | * is good since we are not returning it in the "out" parameter.
|
|---|
| 1395 | */
|
|---|
| 1396 | IUnknown_Release(regClassObject);
|
|---|
| 1397 |
|
|---|
| 1398 | return hres;
|
|---|
| 1399 | }
|
|---|
| 1400 |
|
|---|
| 1401 | if (((CLSCTX_LOCAL_SERVER) & dwClsContext)
|
|---|
| 1402 | && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext))
|
|---|
| 1403 | return Remote_CoGetClassObject(rclsid,dwClsContext,pServerInfo,iid,ppv);
|
|---|
| 1404 |
|
|---|
| 1405 | /* remote servers not supported yet */
|
|---|
| 1406 | if ( ((CLSCTX_REMOTE_SERVER) & dwClsContext)
|
|---|
| 1407 | && !((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext)
|
|---|
| 1408 | ){
|
|---|
| 1409 | FIXME("CLSCTX_REMOTE_SERVER not supported!\n");
|
|---|
| 1410 | return E_NOINTERFACE;
|
|---|
| 1411 | }
|
|---|
| 1412 |
|
|---|
| 1413 | if ((CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER) & dwClsContext) {
|
|---|
| 1414 | HKEY key;
|
|---|
| 1415 | char buf[200];
|
|---|
| 1416 |
|
|---|
| 1417 | memset(ProviderName,0,sizeof(ProviderName));
|
|---|
| 1418 | sprintf(buf,"CLSID\\%s\\InprocServer32",xclsid);
|
|---|
| 1419 | if (((hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key)) != ERROR_SUCCESS) ||
|
|---|
| 1420 | ((hres = RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)ProviderName,&ProviderNameLen)),
|
|---|
| 1421 | RegCloseKey (key),
|
|---|
| 1422 | hres != ERROR_SUCCESS))
|
|---|
| 1423 | {
|
|---|
| 1424 | hres = REGDB_E_CLASSNOTREG;
|
|---|
| 1425 | }
|
|---|
| 1426 | /* Don't ask me. MSDN says that CoGetClassObject does NOT call CoLoadLibrary */
|
|---|
| 1427 | else if ((hLibrary = CoLoadLibrary(ProviderName, TRUE)) == 0)
|
|---|
| 1428 | {
|
|---|
| 1429 | FIXME("couldn't load InprocServer32 dll %s\n", debugstr_w(ProviderName));
|
|---|
| 1430 | hres = E_ACCESSDENIED; /* or should this be CO_E_DLLNOTFOUND? */
|
|---|
| 1431 | }
|
|---|
| 1432 | else if (!(DllGetClassObject = (DllGetClassObjectFunc)GetProcAddress(hLibrary, "DllGetClassObject")))
|
|---|
| 1433 | {
|
|---|
| 1434 | /* not sure if this should be called here CoFreeLibrary(hLibrary);*/
|
|---|
| 1435 | FIXME("couldn't find function DllGetClassObject in %s\n", debugstr_w(ProviderName));
|
|---|
| 1436 | hres = E_ACCESSDENIED;
|
|---|
| 1437 | }
|
|---|
| 1438 | else
|
|---|
| 1439 | {
|
|---|
| 1440 | /* Ask the DLL for its class object. (there was a note here about
|
|---|
| 1441 | * class factories but this is good.
|
|---|
| 1442 | */
|
|---|
| 1443 | return DllGetClassObject(rclsid, iid, ppv);
|
|---|
| 1444 | }
|
|---|
| 1445 | }
|
|---|
| 1446 |
|
|---|
| 1447 |
|
|---|
| 1448 | /* Finally try out of process */
|
|---|
| 1449 | /* out of process and remote servers not supported yet */
|
|---|
| 1450 | if (CLSCTX_LOCAL_SERVER & dwClsContext)
|
|---|
| 1451 | {
|
|---|
| 1452 | memset(ProviderName,0,sizeof(ProviderName));
|
|---|
| 1453 | sprintf(buf,"CLSID\\%s\\LocalServer32",xclsid);
|
|---|
| 1454 | if (((hres = RegOpenKeyExA(HKEY_CLASSES_ROOT, buf, 0, KEY_READ, &key)) != ERROR_SUCCESS) ||
|
|---|
| 1455 | ((hres = RegQueryValueExW(key,NULL,NULL,NULL,(LPBYTE)ProviderName,&ProviderNameLen)),
|
|---|
| 1456 | RegCloseKey (key),
|
|---|
| 1457 | hres != ERROR_SUCCESS))
|
|---|
| 1458 | {
|
|---|
| 1459 | hres = REGDB_E_CLASSNOTREG;
|
|---|
| 1460 | }
|
|---|
| 1461 | else
|
|---|
| 1462 | {
|
|---|
| 1463 | /* CO_E_APPNOTFOUND if no exe */
|
|---|
| 1464 | FIXME("CLSCTX_LOCAL_SERVER %s registered but not yet supported!\n",debugstr_w(ProviderName));
|
|---|
| 1465 | hres = E_ACCESSDENIED;
|
|---|
| 1466 | }
|
|---|
| 1467 | }
|
|---|
| 1468 |
|
|---|
| 1469 | if (CLSCTX_REMOTE_SERVER & dwClsContext)
|
|---|
| 1470 | {
|
|---|
| 1471 | FIXME ("CLSCTX_REMOTE_SERVER not supported\n");
|
|---|
| 1472 | hres = E_ACCESSDENIED;
|
|---|
| 1473 | }
|
|---|
| 1474 |
|
|---|
| 1475 | return hres;
|
|---|
| 1476 | }
|
|---|
| 1477 | /***********************************************************************
|
|---|
| 1478 | * CoResumeClassObjects (OLE32.173)
|
|---|
| 1479 | *
|
|---|
| 1480 | * Resumes classobjects registered with REGCLS suspended
|
|---|
| 1481 | */
|
|---|
| 1482 | HRESULT WINAPI CoResumeClassObjects(void)
|
|---|
| 1483 | {
|
|---|
| 1484 | FIXME("\n");
|
|---|
| 1485 | return S_OK;
|
|---|
| 1486 | }
|
|---|
| 1487 |
|
|---|
| 1488 | /***********************************************************************
|
|---|
| 1489 | * GetClassFile (OLE32.67)
|
|---|
| 1490 | *
|
|---|
| 1491 | * This function supplies the CLSID associated with the given filename.
|
|---|
| 1492 | */
|
|---|
| 1493 | HRESULT WINAPI GetClassFile(LPCOLESTR filePathName,CLSID *pclsid)
|
|---|
| 1494 | {
|
|---|
| 1495 | IStorage *pstg=0;
|
|---|
| 1496 | HRESULT res;
|
|---|
| 1497 | int nbElm=0,length=0,i=0;
|
|---|
| 1498 | LONG sizeProgId=20;
|
|---|
| 1499 | LPOLESTR *pathDec=0,absFile=0,progId=0;
|
|---|
| 1500 | WCHAR extention[100]={0};
|
|---|
| 1501 |
|
|---|
| 1502 | TRACE("()\n");
|
|---|
| 1503 |
|
|---|
| 1504 | /* if the file contain a storage object the return the CLSID writen by IStorage_SetClass method*/
|
|---|
| 1505 | if((StgIsStorageFile(filePathName))==S_OK){
|
|---|
| 1506 |
|
|---|
| 1507 | res=StgOpenStorage(filePathName,NULL,STGM_READ | STGM_SHARE_DENY_WRITE,NULL,0,&pstg);
|
|---|
| 1508 |
|
|---|
| 1509 | if (SUCCEEDED(res))
|
|---|
| 1510 | res=ReadClassStg(pstg,pclsid);
|
|---|
| 1511 |
|
|---|
| 1512 | IStorage_Release(pstg);
|
|---|
| 1513 |
|
|---|
| 1514 | return res;
|
|---|
| 1515 | }
|
|---|
| 1516 | /* if the file is not a storage object then attemps to match various bits in the file against a
|
|---|
| 1517 | pattern in the registry. this case is not frequently used ! so I present only the psodocode for
|
|---|
| 1518 | this case
|
|---|
| 1519 |
|
|---|
| 1520 | for(i=0;i<nFileTypes;i++)
|
|---|
| 1521 |
|
|---|
| 1522 | for(i=0;j<nPatternsForType;j++){
|
|---|
| 1523 |
|
|---|
| 1524 | PATTERN pat;
|
|---|
| 1525 | HANDLE hFile;
|
|---|
| 1526 |
|
|---|
| 1527 | pat=ReadPatternFromRegistry(i,j);
|
|---|
| 1528 | hFile=CreateFileW(filePathName,,,,,,hFile);
|
|---|
| 1529 | SetFilePosition(hFile,pat.offset);
|
|---|
| 1530 | ReadFile(hFile,buf,pat.size,NULL,NULL);
|
|---|
| 1531 | if (memcmp(buf&pat.mask,pat.pattern.pat.size)==0){
|
|---|
| 1532 |
|
|---|
| 1533 | *pclsid=ReadCLSIDFromRegistry(i);
|
|---|
| 1534 | return S_OK;
|
|---|
| 1535 | }
|
|---|
| 1536 | }
|
|---|
| 1537 | */
|
|---|
| 1538 |
|
|---|
| 1539 | /* if the obove strategies fail then search for the extension key in the registry */
|
|---|
| 1540 |
|
|---|
| 1541 | /* get the last element (absolute file) in the path name */
|
|---|
| 1542 | nbElm=FileMonikerImpl_DecomposePath(filePathName,&pathDec);
|
|---|
| 1543 | absFile=pathDec[nbElm-1];
|
|---|
| 1544 |
|
|---|
| 1545 | /* failed if the path represente a directory and not an absolute file name*/
|
|---|
| 1546 | if (lstrcmpW(absFile,(LPOLESTR)"\\"))
|
|---|
| 1547 | return MK_E_INVALIDEXTENSION;
|
|---|
| 1548 |
|
|---|
| 1549 | /* get the extension of the file */
|
|---|
| 1550 | length=lstrlenW(absFile);
|
|---|
| 1551 | for(i=length-1; ( (i>=0) && (extention[i]=absFile[i]) );i--);
|
|---|
| 1552 |
|
|---|
| 1553 | /* get the progId associated to the extension */
|
|---|
| 1554 | progId=CoTaskMemAlloc(sizeProgId);
|
|---|
| 1555 |
|
|---|
| 1556 | res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
|
|---|
| 1557 |
|
|---|
| 1558 | if (res==ERROR_MORE_DATA){
|
|---|
| 1559 |
|
|---|
| 1560 | progId = CoTaskMemRealloc(progId,sizeProgId);
|
|---|
| 1561 | res=RegQueryValueW(HKEY_CLASSES_ROOT,extention,progId,&sizeProgId);
|
|---|
| 1562 | }
|
|---|
| 1563 | if (res==ERROR_SUCCESS)
|
|---|
| 1564 | /* return the clsid associated to the progId */
|
|---|
| 1565 | res= CLSIDFromProgID(progId,pclsid);
|
|---|
| 1566 |
|
|---|
| 1567 | for(i=0; pathDec[i]!=NULL;i++)
|
|---|
| 1568 | CoTaskMemFree(pathDec[i]);
|
|---|
| 1569 | CoTaskMemFree(pathDec);
|
|---|
| 1570 |
|
|---|
| 1571 | CoTaskMemFree(progId);
|
|---|
| 1572 |
|
|---|
| 1573 | if (res==ERROR_SUCCESS)
|
|---|
| 1574 | return res;
|
|---|
| 1575 |
|
|---|
| 1576 | return MK_E_INVALIDEXTENSION;
|
|---|
| 1577 | }
|
|---|
| 1578 | #ifndef __WIN32OS2__
|
|---|
| 1579 | /******************************************************************************
|
|---|
| 1580 | * CoRegisterMessageFilter [COMPOBJ.27]
|
|---|
| 1581 | */
|
|---|
| 1582 | HRESULT WINAPI CoRegisterMessageFilter16(
|
|---|
| 1583 | LPMESSAGEFILTER lpMessageFilter,
|
|---|
| 1584 | LPMESSAGEFILTER *lplpMessageFilter
|
|---|
| 1585 | ) {
|
|---|
| 1586 | FIXME("(%p,%p),stub!\n",lpMessageFilter,lplpMessageFilter);
|
|---|
| 1587 | return 0;
|
|---|
| 1588 | }
|
|---|
| 1589 | #endif
|
|---|
| 1590 | /***********************************************************************
|
|---|
| 1591 | * CoCreateInstance [COMPOBJ.13]
|
|---|
| 1592 | * CoCreateInstance [OLE32.7]
|
|---|
| 1593 | */
|
|---|
| 1594 | HRESULT WINAPI CoCreateInstance(
|
|---|
| 1595 | REFCLSID rclsid,
|
|---|
| 1596 | LPUNKNOWN pUnkOuter,
|
|---|
| 1597 | DWORD dwClsContext,
|
|---|
| 1598 | REFIID iid,
|
|---|
| 1599 | LPVOID *ppv)
|
|---|
| 1600 | {
|
|---|
| 1601 | HRESULT hres;
|
|---|
| 1602 | LPCLASSFACTORY lpclf = 0;
|
|---|
| 1603 |
|
|---|
| 1604 | /*
|
|---|
| 1605 | * Sanity check
|
|---|
| 1606 | */
|
|---|
| 1607 | if (ppv==0)
|
|---|
| 1608 | return E_POINTER;
|
|---|
| 1609 |
|
|---|
| 1610 | /*
|
|---|
| 1611 | * Initialize the "out" parameter
|
|---|
| 1612 | */
|
|---|
| 1613 | *ppv = 0;
|
|---|
| 1614 |
|
|---|
| 1615 | /*
|
|---|
| 1616 | * Get a class factory to construct the object we want.
|
|---|
| 1617 | */
|
|---|
| 1618 | hres = CoGetClassObject(rclsid,
|
|---|
| 1619 | dwClsContext,
|
|---|
| 1620 | NULL,
|
|---|
| 1621 | &IID_IClassFactory,
|
|---|
| 1622 | (LPVOID)&lpclf);
|
|---|
| 1623 |
|
|---|
| 1624 | if (FAILED(hres)) {
|
|---|
| 1625 | FIXME("no classfactory created for CLSID %s, hres is 0x%08lx\n",
|
|---|
| 1626 | debugstr_guid(rclsid),hres);
|
|---|
| 1627 | return hres;
|
|---|
| 1628 | }
|
|---|
| 1629 |
|
|---|
| 1630 | /*
|
|---|
| 1631 | * Create the object and don't forget to release the factory
|
|---|
| 1632 | */
|
|---|
| 1633 | hres = IClassFactory_CreateInstance(lpclf, pUnkOuter, iid, ppv);
|
|---|
| 1634 | IClassFactory_Release(lpclf);
|
|---|
| 1635 | if(FAILED(hres))
|
|---|
| 1636 | FIXME("no instance created for interface %s of class %s, hres is 0x%08lx\n",
|
|---|
| 1637 | debugstr_guid(iid), debugstr_guid(rclsid),hres);
|
|---|
| 1638 |
|
|---|
| 1639 | return hres;
|
|---|
| 1640 | }
|
|---|
| 1641 |
|
|---|
| 1642 | /***********************************************************************
|
|---|
| 1643 | * CoCreateInstanceEx [OLE32.165]
|
|---|
| 1644 | */
|
|---|
| 1645 | HRESULT WINAPI CoCreateInstanceEx(
|
|---|
| 1646 | REFCLSID rclsid,
|
|---|
| 1647 | LPUNKNOWN pUnkOuter,
|
|---|
| 1648 | DWORD dwClsContext,
|
|---|
| 1649 | COSERVERINFO* pServerInfo,
|
|---|
| 1650 | ULONG cmq,
|
|---|
| 1651 | MULTI_QI* pResults)
|
|---|
| 1652 | {
|
|---|
| 1653 | IUnknown* pUnk = NULL;
|
|---|
| 1654 | HRESULT hr;
|
|---|
| 1655 | ULONG index;
|
|---|
| 1656 | int successCount = 0;
|
|---|
| 1657 |
|
|---|
| 1658 | /*
|
|---|
| 1659 | * Sanity check
|
|---|
| 1660 | */
|
|---|
| 1661 | if ( (cmq==0) || (pResults==NULL))
|
|---|
| 1662 | return E_INVALIDARG;
|
|---|
| 1663 |
|
|---|
| 1664 | if (pServerInfo!=NULL)
|
|---|
| 1665 | FIXME("() non-NULL pServerInfo not supported!\n");
|
|---|
| 1666 |
|
|---|
| 1667 | /*
|
|---|
| 1668 | * Initialize all the "out" parameters.
|
|---|
| 1669 | */
|
|---|
| 1670 | for (index = 0; index < cmq; index++)
|
|---|
| 1671 | {
|
|---|
| 1672 | pResults[index].pItf = NULL;
|
|---|
| 1673 | pResults[index].hr = E_NOINTERFACE;
|
|---|
| 1674 | }
|
|---|
| 1675 |
|
|---|
| 1676 | /*
|
|---|
| 1677 | * Get the object and get its IUnknown pointer.
|
|---|
| 1678 | */
|
|---|
| 1679 | hr = CoCreateInstance(rclsid,
|
|---|
| 1680 | pUnkOuter,
|
|---|
| 1681 | dwClsContext,
|
|---|
| 1682 | &IID_IUnknown,
|
|---|
| 1683 | (VOID**)&pUnk);
|
|---|
| 1684 |
|
|---|
| 1685 | if (hr)
|
|---|
| 1686 | return hr;
|
|---|
| 1687 |
|
|---|
| 1688 | /*
|
|---|
| 1689 | * Then, query for all the interfaces requested.
|
|---|
| 1690 | */
|
|---|
| 1691 | for (index = 0; index < cmq; index++)
|
|---|
| 1692 | {
|
|---|
| 1693 | pResults[index].hr = IUnknown_QueryInterface(pUnk,
|
|---|
| 1694 | pResults[index].pIID,
|
|---|
| 1695 | (VOID**)&(pResults[index].pItf));
|
|---|
| 1696 |
|
|---|
| 1697 | if (pResults[index].hr == S_OK)
|
|---|
| 1698 | successCount++;
|
|---|
| 1699 | }
|
|---|
| 1700 |
|
|---|
| 1701 | /*
|
|---|
| 1702 | * Release our temporary unknown pointer.
|
|---|
| 1703 | */
|
|---|
| 1704 | IUnknown_Release(pUnk);
|
|---|
| 1705 |
|
|---|
| 1706 | if (successCount == 0)
|
|---|
| 1707 | return E_NOINTERFACE;
|
|---|
| 1708 |
|
|---|
| 1709 | if (successCount!=cmq)
|
|---|
| 1710 | return CO_S_NOTALLINTERFACES;
|
|---|
| 1711 |
|
|---|
| 1712 | return S_OK;
|
|---|
| 1713 | }
|
|---|
| 1714 |
|
|---|
| 1715 | /***********************************************************************
|
|---|
| 1716 | * CoFreeLibrary [OLE32.13]
|
|---|
| 1717 | */
|
|---|
| 1718 | void WINAPI CoFreeLibrary(HINSTANCE hLibrary)
|
|---|
| 1719 | {
|
|---|
| 1720 | OpenDll *ptr, *prev;
|
|---|
| 1721 | OpenDll *tmp;
|
|---|
| 1722 |
|
|---|
| 1723 | EnterCriticalSection( &csOpenDllList );
|
|---|
| 1724 |
|
|---|
| 1725 | /* lookup library in linked list */
|
|---|
| 1726 | prev = NULL;
|
|---|
| 1727 | for (ptr = openDllList; ptr != NULL; ptr=ptr->next) {
|
|---|
| 1728 | if (ptr->hLibrary == hLibrary) {
|
|---|
| 1729 | break;
|
|---|
| 1730 | }
|
|---|
| 1731 | prev = ptr;
|
|---|
| 1732 | }
|
|---|
| 1733 |
|
|---|
| 1734 | if (ptr == NULL) {
|
|---|
| 1735 | /* shouldn't happen if user passed in a valid hLibrary */
|
|---|
| 1736 | goto end;
|
|---|
| 1737 | }
|
|---|
| 1738 | /* assert: ptr points to the library entry to free */
|
|---|
| 1739 |
|
|---|
| 1740 | /* free library and remove node from list */
|
|---|
| 1741 | FreeLibrary(hLibrary);
|
|---|
| 1742 | if (ptr == openDllList) {
|
|---|
| 1743 | tmp = openDllList->next;
|
|---|
| 1744 | HeapFree(GetProcessHeap(), 0, openDllList);
|
|---|
| 1745 | openDllList = tmp;
|
|---|
| 1746 | } else {
|
|---|
| 1747 | tmp = ptr->next;
|
|---|
| 1748 | HeapFree(GetProcessHeap(), 0, ptr);
|
|---|
| 1749 | prev->next = tmp;
|
|---|
| 1750 | }
|
|---|
| 1751 | end:
|
|---|
| 1752 | LeaveCriticalSection( &csOpenDllList );
|
|---|
| 1753 | }
|
|---|
| 1754 |
|
|---|
| 1755 |
|
|---|
| 1756 | /***********************************************************************
|
|---|
| 1757 | * CoFreeAllLibraries [OLE32.12]
|
|---|
| 1758 | */
|
|---|
| 1759 | void WINAPI CoFreeAllLibraries(void)
|
|---|
| 1760 | {
|
|---|
| 1761 | OpenDll *ptr, *tmp;
|
|---|
| 1762 |
|
|---|
| 1763 | EnterCriticalSection( &csOpenDllList );
|
|---|
| 1764 |
|
|---|
| 1765 | for (ptr = openDllList; ptr != NULL; ) {
|
|---|
| 1766 | tmp=ptr->next;
|
|---|
| 1767 | CoFreeLibrary(ptr->hLibrary);
|
|---|
| 1768 | ptr = tmp;
|
|---|
| 1769 | }
|
|---|
| 1770 |
|
|---|
| 1771 | LeaveCriticalSection( &csOpenDllList );
|
|---|
| 1772 | }
|
|---|
| 1773 |
|
|---|
| 1774 |
|
|---|
| 1775 |
|
|---|
| 1776 | /***********************************************************************
|
|---|
| 1777 | * CoFreeUnusedLibraries [COMPOBJ.17]
|
|---|
| 1778 | * CoFreeUnusedLibraries [OLE32.14]
|
|---|
| 1779 | */
|
|---|
| 1780 | void WINAPI CoFreeUnusedLibraries(void)
|
|---|
| 1781 | {
|
|---|
| 1782 | OpenDll *ptr, *tmp;
|
|---|
| 1783 | typedef HRESULT(*DllCanUnloadNowFunc)(void);
|
|---|
| 1784 | DllCanUnloadNowFunc DllCanUnloadNow;
|
|---|
| 1785 |
|
|---|
| 1786 | EnterCriticalSection( &csOpenDllList );
|
|---|
| 1787 |
|
|---|
| 1788 | for (ptr = openDllList; ptr != NULL; ) {
|
|---|
| 1789 | DllCanUnloadNow = (DllCanUnloadNowFunc)
|
|---|
| 1790 | GetProcAddress(ptr->hLibrary, "DllCanUnloadNow");
|
|---|
| 1791 |
|
|---|
| 1792 | if ( (DllCanUnloadNow != NULL) &&
|
|---|
| 1793 | (DllCanUnloadNow() == S_OK) ) {
|
|---|
| 1794 | tmp=ptr->next;
|
|---|
| 1795 | CoFreeLibrary(ptr->hLibrary);
|
|---|
| 1796 | ptr = tmp;
|
|---|
| 1797 | } else {
|
|---|
| 1798 | ptr=ptr->next;
|
|---|
| 1799 | }
|
|---|
| 1800 | }
|
|---|
| 1801 |
|
|---|
| 1802 | LeaveCriticalSection( &csOpenDllList );
|
|---|
| 1803 | }
|
|---|
| 1804 |
|
|---|
| 1805 | /***********************************************************************
|
|---|
| 1806 | * CoFileTimeNow [COMPOBJ.82]
|
|---|
| 1807 | * CoFileTimeNow [OLE32.10]
|
|---|
| 1808 | *
|
|---|
| 1809 | * RETURNS
|
|---|
| 1810 | * the current system time in lpFileTime
|
|---|
| 1811 | */
|
|---|
| 1812 | HRESULT WINAPI CoFileTimeNow( FILETIME *lpFileTime ) /* [out] the current time */
|
|---|
| 1813 | {
|
|---|
| 1814 | GetSystemTimeAsFileTime( lpFileTime );
|
|---|
| 1815 | return S_OK;
|
|---|
| 1816 | }
|
|---|
| 1817 |
|
|---|
| 1818 | /***********************************************************************
|
|---|
| 1819 | * CoTaskMemAlloc (OLE32.43)
|
|---|
| 1820 | * RETURNS
|
|---|
| 1821 | * pointer to newly allocated block
|
|---|
| 1822 | */
|
|---|
| 1823 | LPVOID WINAPI CoTaskMemAlloc(
|
|---|
| 1824 | ULONG size /* [in] size of memoryblock to be allocated */
|
|---|
| 1825 | ) {
|
|---|
| 1826 | LPMALLOC lpmalloc;
|
|---|
| 1827 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
|---|
| 1828 |
|
|---|
| 1829 | if (FAILED(ret))
|
|---|
| 1830 | return NULL;
|
|---|
| 1831 |
|
|---|
| 1832 | return IMalloc_Alloc(lpmalloc,size);
|
|---|
| 1833 | }
|
|---|
| 1834 | /***********************************************************************
|
|---|
| 1835 | * CoTaskMemFree (OLE32.44)
|
|---|
| 1836 | */
|
|---|
| 1837 | VOID WINAPI CoTaskMemFree(
|
|---|
| 1838 | LPVOID ptr /* [in] pointer to be freed */
|
|---|
| 1839 | ) {
|
|---|
| 1840 | LPMALLOC lpmalloc;
|
|---|
| 1841 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
|---|
| 1842 |
|
|---|
| 1843 | if (FAILED(ret))
|
|---|
| 1844 | return;
|
|---|
| 1845 |
|
|---|
| 1846 | IMalloc_Free(lpmalloc, ptr);
|
|---|
| 1847 | }
|
|---|
| 1848 |
|
|---|
| 1849 | /***********************************************************************
|
|---|
| 1850 | * CoTaskMemRealloc (OLE32.45)
|
|---|
| 1851 | * RETURNS
|
|---|
| 1852 | * pointer to newly allocated block
|
|---|
| 1853 | */
|
|---|
| 1854 | LPVOID WINAPI CoTaskMemRealloc(
|
|---|
| 1855 | LPVOID pvOld,
|
|---|
| 1856 | ULONG size) /* [in] size of memoryblock to be allocated */
|
|---|
| 1857 | {
|
|---|
| 1858 | LPMALLOC lpmalloc;
|
|---|
| 1859 | HRESULT ret = CoGetMalloc(0,&lpmalloc);
|
|---|
| 1860 |
|
|---|
| 1861 | if (FAILED(ret))
|
|---|
| 1862 | return NULL;
|
|---|
| 1863 |
|
|---|
| 1864 | return IMalloc_Realloc(lpmalloc, pvOld, size);
|
|---|
| 1865 | }
|
|---|
| 1866 |
|
|---|
| 1867 | /***********************************************************************
|
|---|
| 1868 | * CoLoadLibrary (OLE32.30)
|
|---|
| 1869 | */
|
|---|
| 1870 | HINSTANCE WINAPI CoLoadLibrary(LPOLESTR lpszLibName, BOOL bAutoFree)
|
|---|
| 1871 | {
|
|---|
| 1872 | HINSTANCE hLibrary;
|
|---|
| 1873 | OpenDll *ptr;
|
|---|
| 1874 | OpenDll *tmp;
|
|---|
| 1875 |
|
|---|
| 1876 | TRACE("(%s, %d)\n", debugstr_w(lpszLibName), bAutoFree);
|
|---|
| 1877 |
|
|---|
| 1878 | hLibrary = LoadLibraryExW(lpszLibName, 0, LOAD_WITH_ALTERED_SEARCH_PATH);
|
|---|
| 1879 |
|
|---|
| 1880 | if (!bAutoFree)
|
|---|
| 1881 | return hLibrary;
|
|---|
| 1882 |
|
|---|
| 1883 | EnterCriticalSection( &csOpenDllList );
|
|---|
| 1884 |
|
|---|
| 1885 | if (openDllList == NULL) {
|
|---|
| 1886 | /* empty list -- add first node */
|
|---|
| 1887 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
|---|
| 1888 | openDllList->hLibrary=hLibrary;
|
|---|
| 1889 | openDllList->next = NULL;
|
|---|
| 1890 | } else {
|
|---|
| 1891 | /* search for this dll */
|
|---|
| 1892 | int found = FALSE;
|
|---|
| 1893 | for (ptr = openDllList; ptr->next != NULL; ptr=ptr->next) {
|
|---|
| 1894 | if (ptr->hLibrary == hLibrary) {
|
|---|
| 1895 | found = TRUE;
|
|---|
| 1896 | break;
|
|---|
| 1897 | }
|
|---|
| 1898 | }
|
|---|
| 1899 | if (!found) {
|
|---|
| 1900 | /* dll not found, add it */
|
|---|
| 1901 | tmp = openDllList;
|
|---|
| 1902 | openDllList = (OpenDll*)HeapAlloc(GetProcessHeap(),0, sizeof(OpenDll));
|
|---|
| 1903 | openDllList->hLibrary = hLibrary;
|
|---|
| 1904 | openDllList->next = tmp;
|
|---|
| 1905 | }
|
|---|
| 1906 | }
|
|---|
| 1907 |
|
|---|
| 1908 | LeaveCriticalSection( &csOpenDllList );
|
|---|
| 1909 |
|
|---|
| 1910 | return hLibrary;
|
|---|
| 1911 | }
|
|---|
| 1912 |
|
|---|
| 1913 | /***********************************************************************
|
|---|
| 1914 | * CoInitializeWOW (OLE32.27)
|
|---|
| 1915 | */
|
|---|
| 1916 | HRESULT WINAPI CoInitializeWOW(DWORD x,DWORD y) {
|
|---|
| 1917 | FIXME("(0x%08lx,0x%08lx),stub!\n",x,y);
|
|---|
| 1918 | return 0;
|
|---|
| 1919 | }
|
|---|
| 1920 |
|
|---|
| 1921 | /******************************************************************************
|
|---|
| 1922 | * CoLockObjectExternal [COMPOBJ.63]
|
|---|
| 1923 | */
|
|---|
| 1924 | HRESULT WINAPI CoLockObjectExternal16(
|
|---|
| 1925 | LPUNKNOWN pUnk, /* [in] object to be locked */
|
|---|
| 1926 | BOOL16 fLock, /* [in] do lock */
|
|---|
| 1927 | BOOL16 fLastUnlockReleases /* [in] ? */
|
|---|
| 1928 | ) {
|
|---|
| 1929 | FIXME("(%p,%d,%d),stub!\n",pUnk,fLock,fLastUnlockReleases);
|
|---|
| 1930 | return S_OK;
|
|---|
| 1931 | }
|
|---|
| 1932 |
|
|---|
| 1933 | /******************************************************************************
|
|---|
| 1934 | * CoLockObjectExternal [OLE32.31]
|
|---|
| 1935 | */
|
|---|
| 1936 | HRESULT WINAPI CoLockObjectExternal(
|
|---|
| 1937 | LPUNKNOWN pUnk, /* [in] object to be locked */
|
|---|
| 1938 | BOOL fLock, /* [in] do lock */
|
|---|
| 1939 | BOOL fLastUnlockReleases) /* [in] unlock all */
|
|---|
| 1940 | {
|
|---|
| 1941 |
|
|---|
| 1942 | if (fLock)
|
|---|
| 1943 | {
|
|---|
| 1944 | /*
|
|---|
| 1945 | * Increment the external lock coutner, COM_ExternalLockAddRef also
|
|---|
| 1946 | * increment the object's internal lock counter.
|
|---|
| 1947 | */
|
|---|
| 1948 | COM_ExternalLockAddRef( pUnk);
|
|---|
| 1949 | }
|
|---|
| 1950 | else
|
|---|
| 1951 | {
|
|---|
| 1952 | /*
|
|---|
| 1953 | * Decrement the external lock coutner, COM_ExternalLockRelease also
|
|---|
| 1954 | * decrement the object's internal lock counter.
|
|---|
| 1955 | */
|
|---|
| 1956 | COM_ExternalLockRelease( pUnk, fLastUnlockReleases);
|
|---|
| 1957 | }
|
|---|
| 1958 |
|
|---|
| 1959 | return S_OK;
|
|---|
| 1960 | }
|
|---|
| 1961 |
|
|---|
| 1962 | /***********************************************************************
|
|---|
| 1963 | * CoGetState [COMPOBJ.115]
|
|---|
| 1964 | */
|
|---|
| 1965 | HRESULT WINAPI CoGetState16(LPDWORD state)
|
|---|
| 1966 | {
|
|---|
| 1967 | FIXME("(%p),stub!\n", state);
|
|---|
| 1968 | *state = 0;
|
|---|
| 1969 | return S_OK;
|
|---|
| 1970 | }
|
|---|
| 1971 | /***********************************************************************
|
|---|
| 1972 | * CoSetState [OLE32.42]
|
|---|
| 1973 | */
|
|---|
| 1974 | HRESULT WINAPI CoSetState(LPDWORD state)
|
|---|
| 1975 | {
|
|---|
| 1976 | FIXME("(%p),stub!\n", state);
|
|---|
| 1977 | if (state) *state = 0;
|
|---|
| 1978 | return S_OK;
|
|---|
| 1979 | }
|
|---|
| 1980 | /***********************************************************************
|
|---|
| 1981 | * CoCreateFreeThreadedMarshaler [OLE32.5]
|
|---|
| 1982 | */
|
|---|
| 1983 | HRESULT WINAPI CoCreateFreeThreadedMarshaler (LPUNKNOWN punkOuter, LPUNKNOWN* ppunkMarshal)
|
|---|
| 1984 | {
|
|---|
| 1985 | FIXME ("(%p %p): stub\n", punkOuter, ppunkMarshal);
|
|---|
| 1986 |
|
|---|
| 1987 | return S_OK;
|
|---|
| 1988 | }
|
|---|
| 1989 |
|
|---|
| 1990 | /***
|
|---|
| 1991 | * COM_RevokeAllClasses
|
|---|
| 1992 | *
|
|---|
| 1993 | * This method is called when the COM libraries are uninitialized to
|
|---|
| 1994 | * release all the references to the class objects registered with
|
|---|
| 1995 | * the library
|
|---|
| 1996 | */
|
|---|
| 1997 | static void COM_RevokeAllClasses()
|
|---|
| 1998 | {
|
|---|
| 1999 | EnterCriticalSection( &csRegisteredClassList );
|
|---|
| 2000 |
|
|---|
| 2001 | while (firstRegisteredClass!=0)
|
|---|
| 2002 | {
|
|---|
| 2003 | CoRevokeClassObject(firstRegisteredClass->dwCookie);
|
|---|
| 2004 | }
|
|---|
| 2005 |
|
|---|
| 2006 | LeaveCriticalSection( &csRegisteredClassList );
|
|---|
| 2007 | }
|
|---|
| 2008 |
|
|---|
| 2009 | /****************************************************************************
|
|---|
| 2010 | * COM External Lock methods implementation
|
|---|
| 2011 | */
|
|---|
| 2012 |
|
|---|
| 2013 | /****************************************************************************
|
|---|
| 2014 | * Public - Method that increments the count for a IUnknown* in the linked
|
|---|
| 2015 | * list. The item is inserted if not already in the list.
|
|---|
| 2016 | */
|
|---|
| 2017 | static void COM_ExternalLockAddRef(
|
|---|
| 2018 | IUnknown *pUnk)
|
|---|
| 2019 | {
|
|---|
| 2020 | COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
|
|---|
| 2021 |
|
|---|
| 2022 | /*
|
|---|
| 2023 | * Add an external lock to the object. If it was already externally
|
|---|
| 2024 | * locked, just increase the reference count. If it was not.
|
|---|
| 2025 | * add the item to the list.
|
|---|
| 2026 | */
|
|---|
| 2027 | if ( externalLock == EL_NOT_FOUND )
|
|---|
| 2028 | COM_ExternalLockInsert(pUnk);
|
|---|
| 2029 | else
|
|---|
| 2030 | externalLock->uRefCount++;
|
|---|
| 2031 |
|
|---|
| 2032 | /*
|
|---|
| 2033 | * Add an internal lock to the object
|
|---|
| 2034 | */
|
|---|
| 2035 | IUnknown_AddRef(pUnk);
|
|---|
| 2036 | }
|
|---|
| 2037 |
|
|---|
| 2038 | /****************************************************************************
|
|---|
| 2039 | * Public - Method that decrements the count for a IUnknown* in the linked
|
|---|
| 2040 | * list. The item is removed from the list if its count end up at zero or if
|
|---|
| 2041 | * bRelAll is TRUE.
|
|---|
| 2042 | */
|
|---|
| 2043 | static void COM_ExternalLockRelease(
|
|---|
| 2044 | IUnknown *pUnk,
|
|---|
| 2045 | BOOL bRelAll)
|
|---|
| 2046 | {
|
|---|
| 2047 | COM_ExternalLock *externalLock = COM_ExternalLockFind(pUnk);
|
|---|
| 2048 |
|
|---|
| 2049 | if ( externalLock != EL_NOT_FOUND )
|
|---|
| 2050 | {
|
|---|
| 2051 | do
|
|---|
| 2052 | {
|
|---|
| 2053 | externalLock->uRefCount--; /* release external locks */
|
|---|
| 2054 | IUnknown_Release(pUnk); /* release local locks as well */
|
|---|
| 2055 |
|
|---|
| 2056 | if ( bRelAll == FALSE )
|
|---|
| 2057 | break; /* perform single release */
|
|---|
| 2058 |
|
|---|
| 2059 | } while ( externalLock->uRefCount > 0 );
|
|---|
| 2060 |
|
|---|
| 2061 | if ( externalLock->uRefCount == 0 ) /* get rid of the list entry */
|
|---|
| 2062 | COM_ExternalLockDelete(externalLock);
|
|---|
| 2063 | }
|
|---|
| 2064 | }
|
|---|
| 2065 | /****************************************************************************
|
|---|
| 2066 | * Public - Method that frees the content of the list.
|
|---|
| 2067 | */
|
|---|
| 2068 | static void COM_ExternalLockFreeList()
|
|---|
| 2069 | {
|
|---|
| 2070 | COM_ExternalLock *head;
|
|---|
| 2071 |
|
|---|
| 2072 | head = elList.head; /* grab it by the head */
|
|---|
| 2073 | while ( head != EL_END_OF_LIST )
|
|---|
| 2074 | {
|
|---|
| 2075 | COM_ExternalLockDelete(head); /* get rid of the head stuff */
|
|---|
| 2076 |
|
|---|
| 2077 | head = elList.head; /* get the new head... */
|
|---|
| 2078 | }
|
|---|
| 2079 | }
|
|---|
| 2080 |
|
|---|
| 2081 | /****************************************************************************
|
|---|
| 2082 | * Public - Method that dump the content of the list.
|
|---|
| 2083 | */
|
|---|
| 2084 | void COM_ExternalLockDump()
|
|---|
| 2085 | {
|
|---|
| 2086 | COM_ExternalLock *current = elList.head;
|
|---|
| 2087 |
|
|---|
| 2088 | DPRINTF("\nExternal lock list contains:\n");
|
|---|
| 2089 |
|
|---|
| 2090 | while ( current != EL_END_OF_LIST )
|
|---|
| 2091 | {
|
|---|
| 2092 | DPRINTF( "\t%p with %lu references count.\n", current->pUnk, current->uRefCount);
|
|---|
| 2093 |
|
|---|
| 2094 | /* Skip to the next item */
|
|---|
| 2095 | current = current->next;
|
|---|
| 2096 | }
|
|---|
| 2097 |
|
|---|
| 2098 | }
|
|---|
| 2099 |
|
|---|
| 2100 | /****************************************************************************
|
|---|
| 2101 | * Internal - Find a IUnknown* in the linked list
|
|---|
| 2102 | */
|
|---|
| 2103 | static COM_ExternalLock* COM_ExternalLockFind(
|
|---|
| 2104 | IUnknown *pUnk)
|
|---|
| 2105 | {
|
|---|
| 2106 | return COM_ExternalLockLocate(elList.head, pUnk);
|
|---|
| 2107 | }
|
|---|
| 2108 |
|
|---|
| 2109 | /****************************************************************************
|
|---|
| 2110 | * Internal - Recursivity agent for IUnknownExternalLockList_Find
|
|---|
| 2111 | */
|
|---|
| 2112 | static COM_ExternalLock* COM_ExternalLockLocate(
|
|---|
| 2113 | COM_ExternalLock *element,
|
|---|
| 2114 | IUnknown *pUnk)
|
|---|
| 2115 | {
|
|---|
| 2116 | if ( element == EL_END_OF_LIST )
|
|---|
| 2117 | return EL_NOT_FOUND;
|
|---|
| 2118 |
|
|---|
| 2119 | else if ( element->pUnk == pUnk ) /* We found it */
|
|---|
| 2120 | return element;
|
|---|
| 2121 |
|
|---|
| 2122 | else /* Not the right guy, keep on looking */
|
|---|
| 2123 | return COM_ExternalLockLocate( element->next, pUnk);
|
|---|
| 2124 | }
|
|---|
| 2125 |
|
|---|
| 2126 | /****************************************************************************
|
|---|
| 2127 | * Internal - Insert a new IUnknown* to the linked list
|
|---|
| 2128 | */
|
|---|
| 2129 | static BOOL COM_ExternalLockInsert(
|
|---|
| 2130 | IUnknown *pUnk)
|
|---|
| 2131 | {
|
|---|
| 2132 | COM_ExternalLock *newLock = NULL;
|
|---|
| 2133 | COM_ExternalLock *previousHead = NULL;
|
|---|
| 2134 |
|
|---|
| 2135 | /*
|
|---|
| 2136 | * Allocate space for the new storage object
|
|---|
| 2137 | */
|
|---|
| 2138 | newLock = HeapAlloc(GetProcessHeap(), 0, sizeof(COM_ExternalLock));
|
|---|
| 2139 |
|
|---|
| 2140 | if (newLock!=NULL)
|
|---|
| 2141 | {
|
|---|
| 2142 | if ( elList.head == EL_END_OF_LIST )
|
|---|
| 2143 | {
|
|---|
| 2144 | elList.head = newLock; /* The list is empty */
|
|---|
| 2145 | }
|
|---|
| 2146 | else
|
|---|
| 2147 | {
|
|---|
| 2148 | /*
|
|---|
| 2149 | * insert does it at the head
|
|---|
| 2150 | */
|
|---|
| 2151 | previousHead = elList.head;
|
|---|
| 2152 | elList.head = newLock;
|
|---|
| 2153 | }
|
|---|
| 2154 |
|
|---|
| 2155 | /*
|
|---|
| 2156 | * Set new list item data member
|
|---|
| 2157 | */
|
|---|
| 2158 | newLock->pUnk = pUnk;
|
|---|
| 2159 | newLock->uRefCount = 1;
|
|---|
| 2160 | newLock->next = previousHead;
|
|---|
| 2161 |
|
|---|
| 2162 | return TRUE;
|
|---|
| 2163 | }
|
|---|
| 2164 | else
|
|---|
| 2165 | return FALSE;
|
|---|
| 2166 | }
|
|---|
| 2167 |
|
|---|
| 2168 | /****************************************************************************
|
|---|
| 2169 | * Internal - Method that removes an item from the linked list.
|
|---|
| 2170 | */
|
|---|
| 2171 | static void COM_ExternalLockDelete(
|
|---|
| 2172 | COM_ExternalLock *itemList)
|
|---|
| 2173 | {
|
|---|
| 2174 | COM_ExternalLock *current = elList.head;
|
|---|
| 2175 |
|
|---|
| 2176 | if ( current == itemList )
|
|---|
| 2177 | {
|
|---|
| 2178 | /*
|
|---|
| 2179 | * this section handles the deletion of the first node
|
|---|
| 2180 | */
|
|---|
| 2181 | elList.head = itemList->next;
|
|---|
| 2182 | HeapFree( GetProcessHeap(), 0, itemList);
|
|---|
| 2183 | }
|
|---|
| 2184 | else
|
|---|
| 2185 | {
|
|---|
| 2186 | do
|
|---|
| 2187 | {
|
|---|
| 2188 | if ( current->next == itemList ) /* We found the item to free */
|
|---|
| 2189 | {
|
|---|
| 2190 | current->next = itemList->next; /* readjust the list pointers */
|
|---|
| 2191 |
|
|---|
| 2192 | HeapFree( GetProcessHeap(), 0, itemList);
|
|---|
| 2193 | break;
|
|---|
| 2194 | }
|
|---|
| 2195 |
|
|---|
| 2196 | /* Skip to the next item */
|
|---|
| 2197 | current = current->next;
|
|---|
| 2198 |
|
|---|
| 2199 | } while ( current != EL_END_OF_LIST );
|
|---|
| 2200 | }
|
|---|
| 2201 | }
|
|---|
| 2202 |
|
|---|
| 2203 | /***********************************************************************
|
|---|
| 2204 | * DllEntryPoint [COMPOBJ.116]
|
|---|
| 2205 | *
|
|---|
| 2206 | * Initialization code for the COMPOBJ DLL
|
|---|
| 2207 | *
|
|---|
| 2208 | * RETURNS:
|
|---|
| 2209 | */
|
|---|
| 2210 | BOOL WINAPI COMPOBJ_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst, WORD ds, WORD HeapSize, DWORD res1, WORD res2)
|
|---|
| 2211 | {
|
|---|
| 2212 | TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n", Reason, hInst, ds, HeapSize,
|
|---|
| 2213 | res1, res2);
|
|---|
| 2214 | switch(Reason)
|
|---|
| 2215 | {
|
|---|
| 2216 | case DLL_PROCESS_ATTACH:
|
|---|
| 2217 | if (!COMPOBJ_Attach++) COMPOBJ_hInstance = hInst;
|
|---|
| 2218 | break;
|
|---|
| 2219 |
|
|---|
| 2220 | case DLL_PROCESS_DETACH:
|
|---|
| 2221 | if(!--COMPOBJ_Attach)
|
|---|
| 2222 | COMPOBJ_hInstance = 0;
|
|---|
| 2223 | break;
|
|---|
| 2224 | }
|
|---|
| 2225 | return TRUE;
|
|---|
| 2226 | }
|
|---|
| 2227 |
|
|---|
| 2228 | /******************************************************************************
|
|---|
| 2229 | * OleGetAutoConvert [OLE32.104]
|
|---|
| 2230 | */
|
|---|
| 2231 | HRESULT WINAPI OleGetAutoConvert(REFCLSID clsidOld, LPCLSID pClsidNew)
|
|---|
| 2232 | {
|
|---|
| 2233 | HKEY hkey = 0;
|
|---|
| 2234 | char buf[200];
|
|---|
| 2235 | WCHAR wbuf[200];
|
|---|
| 2236 | DWORD len;
|
|---|
| 2237 | HRESULT res = S_OK;
|
|---|
| 2238 |
|
|---|
| 2239 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
|---|
| 2240 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
|---|
| 2241 | {
|
|---|
| 2242 | res = REGDB_E_CLASSNOTREG;
|
|---|
| 2243 | goto done;
|
|---|
| 2244 | }
|
|---|
| 2245 | len = 200;
|
|---|
| 2246 | /* we can just query for the default value of AutoConvertTo key like that,
|
|---|
| 2247 | without opening the AutoConvertTo key and querying for NULL (default) */
|
|---|
| 2248 | if (RegQueryValueA(hkey,"AutoConvertTo",buf,&len))
|
|---|
| 2249 | {
|
|---|
| 2250 | res = REGDB_E_KEYMISSING;
|
|---|
| 2251 | goto done;
|
|---|
| 2252 | }
|
|---|
| 2253 | MultiByteToWideChar( CP_ACP, 0, buf, -1, wbuf, sizeof(wbuf)/sizeof(WCHAR) );
|
|---|
| 2254 | CLSIDFromString(wbuf,pClsidNew);
|
|---|
| 2255 | done:
|
|---|
| 2256 | if (hkey) RegCloseKey(hkey);
|
|---|
| 2257 |
|
|---|
| 2258 | return res;
|
|---|
| 2259 | }
|
|---|
| 2260 |
|
|---|
| 2261 | /******************************************************************************
|
|---|
| 2262 | * OleSetAutoConvert [OLE32.126]
|
|---|
| 2263 | */
|
|---|
| 2264 | HRESULT WINAPI OleSetAutoConvert(REFCLSID clsidOld, REFCLSID clsidNew)
|
|---|
| 2265 | {
|
|---|
| 2266 | HKEY hkey = 0;
|
|---|
| 2267 | char buf[200], szClsidNew[200];
|
|---|
| 2268 | HRESULT res = S_OK;
|
|---|
| 2269 |
|
|---|
| 2270 | TRACE("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
|---|
| 2271 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
|---|
| 2272 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
|---|
| 2273 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
|---|
| 2274 | {
|
|---|
| 2275 | res = REGDB_E_CLASSNOTREG;
|
|---|
| 2276 | goto done;
|
|---|
| 2277 | }
|
|---|
| 2278 | if (RegSetValueA(hkey, "AutoConvertTo", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
|---|
| 2279 | {
|
|---|
| 2280 | res = REGDB_E_WRITEREGDB;
|
|---|
| 2281 | goto done;
|
|---|
| 2282 | }
|
|---|
| 2283 |
|
|---|
| 2284 | done:
|
|---|
| 2285 | if (hkey) RegCloseKey(hkey);
|
|---|
| 2286 | return res;
|
|---|
| 2287 | }
|
|---|
| 2288 |
|
|---|
| 2289 | /******************************************************************************
|
|---|
| 2290 | * CoTreatAsClass [OLE32.46]
|
|---|
| 2291 | */
|
|---|
| 2292 | HRESULT WINAPI CoTreatAsClass(REFCLSID clsidOld, REFCLSID clsidNew)
|
|---|
| 2293 | {
|
|---|
| 2294 | HKEY hkey = 0;
|
|---|
| 2295 | char buf[200], szClsidNew[200];
|
|---|
| 2296 | HRESULT res = S_OK;
|
|---|
| 2297 |
|
|---|
| 2298 | FIXME("(%s,%s)\n", debugstr_guid(clsidOld), debugstr_guid(clsidNew));
|
|---|
| 2299 | sprintf(buf,"CLSID\\");WINE_StringFromCLSID(clsidOld,&buf[6]);
|
|---|
| 2300 | WINE_StringFromCLSID(clsidNew, szClsidNew);
|
|---|
| 2301 | if (RegOpenKeyA(HKEY_CLASSES_ROOT,buf,&hkey))
|
|---|
| 2302 | {
|
|---|
| 2303 | res = REGDB_E_CLASSNOTREG;
|
|---|
| 2304 | goto done;
|
|---|
| 2305 | }
|
|---|
| 2306 | if (RegSetValueA(hkey, "AutoTreatAs", REG_SZ, szClsidNew, strlen(szClsidNew)+1))
|
|---|
| 2307 | {
|
|---|
| 2308 | res = REGDB_E_WRITEREGDB;
|
|---|
| 2309 | goto done;
|
|---|
| 2310 | }
|
|---|
| 2311 |
|
|---|
| 2312 | done:
|
|---|
| 2313 | if (hkey) RegCloseKey(hkey);
|
|---|
| 2314 | return res;
|
|---|
| 2315 | }
|
|---|
| 2316 |
|
|---|
| 2317 |
|
|---|
| 2318 | /***********************************************************************
|
|---|
| 2319 | * IsEqualGUID [OLE32.76]
|
|---|
| 2320 | *
|
|---|
| 2321 | * Compares two Unique Identifiers.
|
|---|
| 2322 | *
|
|---|
| 2323 | * RETURNS
|
|---|
| 2324 | * TRUE if equal
|
|---|
| 2325 | */
|
|---|
| 2326 | #undef IsEqualGUID
|
|---|
| 2327 | BOOL WINAPI IsEqualGUID(
|
|---|
| 2328 | REFGUID rguid1, /* [in] unique id 1 */
|
|---|
| 2329 | REFGUID rguid2 /* [in] unique id 2 */
|
|---|
| 2330 | )
|
|---|
| 2331 | {
|
|---|
| 2332 | return !memcmp(rguid1,rguid2,sizeof(GUID));
|
|---|
| 2333 | }
|
|---|