Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * IParseDisplayName implementation for DEVENUM.dll |
| 3 | * |
| 4 | * Copyright (C) 2002 Robert Shearman |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 19 | * |
| 20 | * NOTES ON THIS FILE: |
| 21 | * - Implements IParseDisplayName interface which creates a moniker |
| 22 | * from a string in a special format |
| 23 | */ |
| 24 | #include "devenum_private.h" |
| 25 | |
| 26 | #include "wine/debug.h" |
| 27 | |
| 28 | WINE_DEFAULT_DEBUG_CHANNEL(devenum); |
| 29 | |
| 30 | static HRESULT WINAPI DEVENUM_IParseDisplayName_QueryInterface( |
| 31 | LPPARSEDISPLAYNAME iface, |
| 32 | REFIID riid, |
| 33 | LPVOID *ppvObj) |
| 34 | { |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 35 | TRACE("\n\tIID:\t%s\n",debugstr_guid(riid)); |
| 36 | |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 37 | if (ppvObj == NULL) return E_POINTER; |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 38 | |
| 39 | if (IsEqualGUID(riid, &IID_IUnknown) || |
| 40 | IsEqualGUID(riid, &IID_IParseDisplayName)) |
| 41 | { |
| 42 | *ppvObj = (LPVOID)iface; |
| 43 | IParseDisplayName_AddRef(iface); |
| 44 | return S_OK; |
| 45 | } |
| 46 | |
| 47 | FIXME("- no interface\n\tIID:\t%s\n", debugstr_guid(riid)); |
| 48 | return E_NOINTERFACE; |
| 49 | } |
| 50 | |
| 51 | /********************************************************************** |
| 52 | * DEVENUM_IParseDisplayName_AddRef (also IUnknown) |
| 53 | */ |
| 54 | static ULONG WINAPI DEVENUM_IParseDisplayName_AddRef(LPPARSEDISPLAYNAME iface) |
| 55 | { |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 56 | TRACE("\n"); |
| 57 | |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 58 | DEVENUM_LockModule(); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 59 | |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 60 | return 2; /* non-heap based object */ |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /********************************************************************** |
| 64 | * DEVENUM_IParseDisplayName_Release (also IUnknown) |
| 65 | */ |
| 66 | static ULONG WINAPI DEVENUM_IParseDisplayName_Release(LPPARSEDISPLAYNAME iface) |
| 67 | { |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 68 | TRACE("\n"); |
| 69 | |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 70 | DEVENUM_UnlockModule(); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 71 | |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 72 | return 1; /* non-heap based object */ |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /********************************************************************** |
| 76 | * DEVENUM_IParseDisplayName_ParseDisplayName |
| 77 | * |
| 78 | * Creates a moniker referenced to by the display string argument |
| 79 | * |
| 80 | * POSSIBLE BUGS: |
Robert Shearman | e14e101 | 2003-12-30 21:52:45 +0000 | [diff] [blame] | 81 | * Might not handle more complicated strings properly (ie anything |
| 82 | * not in "@device:sw:{CLSID1}\<filter name or CLSID>" format |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 83 | */ |
| 84 | static HRESULT WINAPI DEVENUM_IParseDisplayName_ParseDisplayName( |
| 85 | LPPARSEDISPLAYNAME iface, |
| 86 | IBindCtx *pbc, |
| 87 | LPOLESTR pszDisplayName, |
| 88 | ULONG *pchEaten, |
| 89 | IMoniker **ppmkOut) |
| 90 | { |
| 91 | LPOLESTR pszBetween = NULL; |
| 92 | LPOLESTR pszClass = NULL; |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 93 | MediaCatMoniker * pMoniker = NULL; |
| 94 | CLSID clsidDevice; |
| 95 | HRESULT res = S_OK; |
Alexander Dorofeyev | de70686 | 2008-06-29 15:07:32 +0300 | [diff] [blame^] | 96 | WCHAR wszRegKeyName[MAX_PATH]; |
| 97 | HKEY hbasekey; |
Peter Berg Larsen | 6e3bcb5 | 2005-04-18 10:30:55 +0000 | [diff] [blame] | 98 | int classlen; |
Alexander Dorofeyev | de70686 | 2008-06-29 15:07:32 +0300 | [diff] [blame^] | 99 | static const WCHAR wszRegSeparator[] = {'\\', 0 }; |
Robert Shearman | e14e101 | 2003-12-30 21:52:45 +0000 | [diff] [blame] | 100 | |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 101 | TRACE("(%p, %s, %p, %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut); |
| 102 | |
| 103 | *ppmkOut = NULL; |
| 104 | if (pchEaten) |
| 105 | *pchEaten = strlenW(pszDisplayName); |
| 106 | |
| 107 | pszDisplayName = strchrW(pszDisplayName, '{'); |
| 108 | pszBetween = strchrW(pszDisplayName, '}') + 2; |
| 109 | |
| 110 | /* size = pszBetween - pszDisplayName - 1 (for '\\' after CLSID) |
| 111 | * + 1 (for NULL character) |
| 112 | */ |
Peter Berg Larsen | 6e3bcb5 | 2005-04-18 10:30:55 +0000 | [diff] [blame] | 113 | classlen = (int)(pszBetween - pszDisplayName - 1); |
| 114 | pszClass = CoTaskMemAlloc((classlen + 1) * sizeof(WCHAR)); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 115 | if (!pszClass) |
| 116 | return E_OUTOFMEMORY; |
| 117 | |
Peter Berg Larsen | 6e3bcb5 | 2005-04-18 10:30:55 +0000 | [diff] [blame] | 118 | memcpy(pszClass, pszDisplayName, classlen * sizeof(WCHAR)); |
| 119 | pszClass[classlen] = 0; |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 120 | |
| 121 | TRACE("Device CLSID: %s\n", debugstr_w(pszClass)); |
| 122 | |
| 123 | res = CLSIDFromString(pszClass, &clsidDevice); |
| 124 | |
| 125 | if (SUCCEEDED(res)) |
| 126 | { |
Alexander Dorofeyev | de70686 | 2008-06-29 15:07:32 +0300 | [diff] [blame^] | 127 | res = DEVENUM_GetCategoryKey(&clsidDevice, &hbasekey, wszRegKeyName, MAX_PATH); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | if (SUCCEEDED(res)) |
| 131 | { |
| 132 | pMoniker = DEVENUM_IMediaCatMoniker_Construct(); |
| 133 | if (pMoniker) |
| 134 | { |
Alexander Dorofeyev | de70686 | 2008-06-29 15:07:32 +0300 | [diff] [blame^] | 135 | strcatW(wszRegKeyName, wszRegSeparator); |
| 136 | strcatW(wszRegKeyName, pszBetween); |
| 137 | |
| 138 | if (RegCreateKeyW(hbasekey, wszRegKeyName, &pMoniker->hkey) == ERROR_SUCCESS) |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 139 | *ppmkOut = (LPMONIKER)pMoniker; |
| 140 | else |
| 141 | { |
| 142 | IMoniker_Release((LPMONIKER)pMoniker); |
| 143 | res = MK_E_NOOBJECT; |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | |
James Hawkins | 99e2c6d | 2006-10-06 18:05:08 -0700 | [diff] [blame] | 148 | CoTaskMemFree(pszClass); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 149 | |
Michael Stefaniuc | 36d88d9 | 2006-10-08 18:58:22 +0200 | [diff] [blame] | 150 | TRACE("-- returning: %x\n", res); |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 151 | return res; |
| 152 | } |
| 153 | |
| 154 | /********************************************************************** |
| 155 | * IParseDisplayName_Vtbl |
| 156 | */ |
Dmitry Timoshkov | 247246e | 2005-05-30 10:01:08 +0000 | [diff] [blame] | 157 | static const IParseDisplayNameVtbl IParseDisplayName_Vtbl = |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 158 | { |
Robert Shearman | d38cce8 | 2003-07-01 04:30:30 +0000 | [diff] [blame] | 159 | DEVENUM_IParseDisplayName_QueryInterface, |
| 160 | DEVENUM_IParseDisplayName_AddRef, |
| 161 | DEVENUM_IParseDisplayName_Release, |
| 162 | DEVENUM_IParseDisplayName_ParseDisplayName |
| 163 | }; |
| 164 | |
| 165 | /* The one instance of this class */ |
Robert Shearman | e7110f0 | 2004-12-07 14:37:11 +0000 | [diff] [blame] | 166 | ParseDisplayNameImpl DEVENUM_ParseDisplayName = { &IParseDisplayName_Vtbl }; |