ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

parsedisplayname.c
Go to the documentation of this file.
00001 /*
00002  *  IParseDisplayName implementation for DEVENUM.dll
00003  *
00004  * Copyright (C) 2002 Robert Shearman
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  *
00020  * NOTES ON THIS FILE:
00021  * - Implements IParseDisplayName interface which creates a moniker
00022  *   from a string in a special format
00023  */
00024 #include "devenum_private.h"
00025 
00026 #include "wine/debug.h"
00027 
00028 WINE_DEFAULT_DEBUG_CHANNEL(devenum);
00029 
00030 static HRESULT WINAPI DEVENUM_IParseDisplayName_QueryInterface(
00031     LPPARSEDISPLAYNAME iface,
00032     REFIID riid,
00033     LPVOID *ppvObj)
00034 {
00035     TRACE("\n\tIID:\t%s\n",debugstr_guid(riid));
00036 
00037     if (ppvObj == NULL) return E_POINTER;
00038 
00039     if (IsEqualGUID(riid, &IID_IUnknown) ||
00040         IsEqualGUID(riid, &IID_IParseDisplayName))
00041     {
00042         *ppvObj = iface;
00043     IParseDisplayName_AddRef(iface);
00044     return S_OK;
00045     }
00046 
00047     FIXME("- no interface IID: %s\n", debugstr_guid(riid));
00048     return E_NOINTERFACE;
00049 }
00050 
00051 /**********************************************************************
00052  * DEVENUM_IParseDisplayName_AddRef (also IUnknown)
00053  */
00054 static ULONG WINAPI DEVENUM_IParseDisplayName_AddRef(LPPARSEDISPLAYNAME iface)
00055 {
00056     TRACE("\n");
00057 
00058     DEVENUM_LockModule();
00059 
00060     return 2; /* non-heap based object */
00061 }
00062 
00063 /**********************************************************************
00064  * DEVENUM_IParseDisplayName_Release (also IUnknown)
00065  */
00066 static ULONG WINAPI DEVENUM_IParseDisplayName_Release(LPPARSEDISPLAYNAME iface)
00067 {
00068     TRACE("\n");
00069 
00070     DEVENUM_UnlockModule();
00071 
00072     return 1; /* non-heap based object */
00073 }
00074 
00075 /**********************************************************************
00076  * DEVENUM_IParseDisplayName_ParseDisplayName
00077  *
00078  *  Creates a moniker referenced to by the display string argument
00079  *
00080  * POSSIBLE BUGS:
00081  *  Might not handle more complicated strings properly (ie anything
00082  *  not in "@device:sw:{CLSID1}<filter name or CLSID>" format
00083  */
00084 static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName(
00085     LPPARSEDISPLAYNAME iface,
00086     IBindCtx *pbc,
00087     LPOLESTR pszDisplayName,
00088     ULONG *pchEaten,
00089     IMoniker **ppmkOut)
00090 {
00091     LPOLESTR pszBetween = NULL;
00092     LPOLESTR pszClass = NULL;
00093     MediaCatMoniker * pMoniker = NULL;
00094     CLSID clsidDevice;
00095     HRESULT res = S_OK;
00096     WCHAR wszRegKeyName[MAX_PATH];
00097     HKEY hbasekey;
00098     int classlen;
00099     static const WCHAR wszRegSeparator[] =   {'\\', 0 };
00100 
00101     TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
00102 
00103     *ppmkOut = NULL;
00104     if (pchEaten)
00105         *pchEaten = strlenW(pszDisplayName);
00106 
00107     pszDisplayName = strchrW(pszDisplayName, '{');
00108     pszBetween = strchrW(pszDisplayName, '}') + 2;
00109 
00110     /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID)
00111      * + 1 (for NULL character)
00112      */
00113     classlen = (int)(pszBetween - pszDisplayName - 1);
00114     pszClass = CoTaskMemAlloc((classlen + 1) * sizeof(WCHAR));
00115     if (!pszClass)
00116         return E_OUTOFMEMORY;
00117 
00118     memcpy(pszClass, pszDisplayName, classlen * sizeof(WCHAR));
00119     pszClass[classlen] = 0;
00120 
00121     TRACE("Device CLSID: %s\n", debugstr_w(pszClass));
00122 
00123     res = CLSIDFromString(pszClass, &clsidDevice);
00124 
00125     if (SUCCEEDED(res))
00126     {
00127         res = DEVENUM_GetCategoryKey(&clsidDevice, &hbasekey, wszRegKeyName, MAX_PATH);
00128     }
00129 
00130     if (SUCCEEDED(res))
00131     {
00132         pMoniker = DEVENUM_IMediaCatMoniker_Construct();
00133         if (pMoniker)
00134         {
00135             strcatW(wszRegKeyName, wszRegSeparator);
00136             strcatW(wszRegKeyName, pszBetween);
00137 
00138             if (RegCreateKeyW(hbasekey, wszRegKeyName, &pMoniker->hkey) == ERROR_SUCCESS)
00139                 *ppmkOut = (LPMONIKER)pMoniker;
00140             else
00141             {
00142                 IMoniker_Release((LPMONIKER)pMoniker);
00143                 res = MK_E_NOOBJECT;
00144             }
00145         }
00146     }
00147 
00148     CoTaskMemFree(pszClass);
00149 
00150     TRACE("-- returning: %x\n", res);
00151     return res;
00152 }
00153 
00154 /**********************************************************************
00155  * IParseDisplayName_Vtbl
00156  */
00157 static const IParseDisplayNameVtbl IParseDisplayName_Vtbl =
00158 {
00159     DEVENUM_IParseDisplayName_QueryInterface,
00160     DEVENUM_IParseDisplayName_AddRef,
00161     DEVENUM_IParseDisplayName_Release,
00162     DEVENUM_IParseDisplayName_ParseDisplayName
00163 };
00164 
00165 /* The one instance of this class */
00166 ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl };

Generated on Sat May 26 2012 04:20:01 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.