ReactOS 0.4.17-dev-784-g3812a95
CSnapin.h
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Management Console
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Retrieve / store information about a snapin
5 * COPYRIGHT: Copyright 2017-2019 Mark Jansen (mark.jansen@reactos.org)
6 * Copyright 2026 Eric Kohl (eric.kohl@reactos.org)
7 */
8
9#pragma once
10
11
12// https://web.archive.org/web/20010614160959/msdn.microsoft.com/library/psdk/mmc/mmc12apx02_8jc5.htm
13// https://msdn.microsoft.com/en-us/library/aa814846(v=vs.85).aspx
14
15
16// https://msdn.microsoft.com/en-us/library/aa815510(v=vs.85).aspx
17// MMC initializes a snap-in by calling the Initialize method of the IComponentData object.
18// During initialization, IComponentData should query the console for its IConsoleNamespace and IConsole interfaces using
19// the console's IUnknown interface pointer that is passed into the call to Initialize.
20// The snap-in should then cache the returned pointers and use them for calling IConsoleNamespace and IConsole interface methods.
21
22
24{
25private:
27 CAtlString m_DisplayName;
28
29public:
31 :m_CacheEntry(CacheEntry)
32 {
33 if (displayName)
35 else
37 }
38
40 {
41 }
42
43 const CAtlString& Name() const { return m_CacheEntry->Name(); }
44 const CAtlString& Provider() const { return m_CacheEntry->Provider(); }
45 const CAtlString& Description() const { return m_CacheEntry->Description(); }
46 const CAtlString& Version() const { return m_CacheEntry->Version(); }
47 const CAtlString& DisplayName() const { return m_DisplayName; }
48
50 {
51 return m_CacheEntry;
52 }
53
54// const CAtlString& Name() const { return m_Name; }
55// const CAtlString& Provider() const { return m_Provider; }
56// int ImageIndex() const { return m_ImageIndex; }
57// const CAtlString& Description()
58// {
59// if (m_Description.IsEmpty() && m_SnapinAbout)
60// {
61// CComHeapPtr<WCHAR> Description;
62// if (!FAILED_UNEXPECTEDLY(m_SnapinAbout->GetSnapinDescription(&Description)))
63// {
64// m_Description = Description;
65// }
66// }
67// return m_Description;
68// }
69
70
71// void SetImageIndex(int index)
72// {
73// m_ImageIndex = index;
74// }
75
76// HRESULT GetIcon(HICON* hAppIcon)
77// {
78// if (!m_SnapinAbout)
79// return E_NOINTERFACE;
80
81// return m_SnapinAbout->GetSnapinImage(hAppIcon);
82// }
83
84 void OnAdd(IConsole* console)
85 {
86#if 0
87 CComPtr<IComponentData> spComponentData;
88 HRESULT hr = CoCreateInstance(m_Guid, NULL, CLSCTX_INPROC, IID_PPV_ARG(IComponentData, &spComponentData));
89
90 if (SUCCEEDED(hr))
91 {
92 //CComPtr<IExtendPropertySheet> spPropertySheet;
93 }
94#endif
95 }
96
97
98 void OnAccept(IConsole* console)
99 {
100#if 0
101 CComPtr<IComponentData> spComponentData;
102 HRESULT hr = CoCreateInstance(m_Guid, NULL, CLSCTX_INPROC, IID_PPV_ARG(IComponentData, &spComponentData));
103
104 if (SUCCEEDED(hr))
105 {
106 hr = spComponentData->Initialize(console);
107 // CComponentData::CreatePropertyPages(
108 if (SUCCEEDED(hr))
109 {
110 SCOPEDATAITEM item = { 0 };
111 item.mask = SDI_STR | SDI_IMAGE | SDI_OPENIMAGE;
112
113 hr = spComponentData->GetDisplayInfo(&item);
114
115 printf("%S\n", item.displayname);
116
117
118 CComPtr<IDataObject> spDataObject;
119
120 hr = spComponentData->QueryDataObject(NULL, CCT_SCOPE, &spDataObject);
121
122 if (SUCCEEDED(hr))
123 {
124 //spDataObject->
125 }
126 }
127 }
128#endif
129 }
130
131#if 0
132 static CSnapin* Create(CRegKey& key, PCWSTR guidString)
133 {
134 GUID guid;
135 /* Not a guid, 'FX:' ?? */
136 if (!SUCCEEDED(::CLSIDFromString(guidString, &guid)))
137 return NULL;
138
139 CRegKey snapin;
140 if (ERROR_SUCCESS != snapin.Open(key, guidString, KEY_READ))
141 return NULL;
142
143 // Can we use this?
144 CRegKey NodeTypes;
145 if (ERROR_SUCCESS != NodeTypes.Open(snapin, L"StandAlone", KEY_READ))
146 return NULL;
147
148 CAtlString Name;
149 QueryString(snapin, L"NameStringIndirect", Name);
150 if (!Name.IsEmpty())
151 {
152 WCHAR IndirectBuffer[MAX_PATH];
153 if (SUCCEEDED(SHLoadIndirectString(Name.GetString(), IndirectBuffer, _countof(IndirectBuffer), NULL)))
154 {
155 Name = IndirectBuffer;
156 }
157 else
158 {
159 Name.Empty();
160 }
161 }
162 if (Name.IsEmpty())
163 QueryString(snapin, L"NameString", Name);
164
165 if (Name.IsEmpty())
166 return NULL;
167
169 QueryString(snapin, L"Provider", Provider);
170
172 QueryString(snapin, L"About", About);
173
174 return new CSnapin(guid, Name, Provider, About);
175 }
176
177 static void QueryString(CRegKey& key, PCWSTR Name, CAtlString& Value)
178 {
180 ULONG nChars = _countof(Buffer);
181
182 Value.Empty();
183 // FIXME: if too short, allocate
184 if (ERROR_SUCCESS == key.QueryStringValue(Name, Buffer, &nChars))
185 {
186 Value = Buffer;
187 }
188 }
189#endif
190};
191
#define IID_PPV_ARG(Itype, ppType)
static BOOL QueryString(HKEY hKey, LPCTSTR pszValueName, LPTSTR pszResult, DWORD dwResultLength)
Definition: settings.c:90
@ Create
Definition: registry.c:563
Definition: bufpool.h:45
const CAtlString & Description() const
const CAtlString & Version() const
const CAtlString & Provider() const
const CAtlString & Name() const
void OnAccept(IConsole *console)
Definition: CSnapin.h:98
~CSnapin()
Definition: CSnapin.h:39
void OnAdd(IConsole *console)
Definition: CSnapin.h:84
CAtlString m_DisplayName
Definition: CSnapin.h:27
const CAtlString & Name() const
Definition: CSnapin.h:43
const CAtlString & Provider() const
Definition: CSnapin.h:44
const CAtlString & DisplayName() const
Definition: CSnapin.h:47
CSnapinCacheEntry * m_CacheEntry
Definition: CSnapin.h:26
const CAtlString & Description() const
Definition: CSnapin.h:45
CSnapinCacheEntry * GetCacheEntry()
Definition: CSnapin.h:49
CSnapin(CSnapinCacheEntry *CacheEntry, PWSTR displayName=NULL)
Definition: CSnapin.h:30
const CAtlString & Version() const
Definition: CSnapin.h:46
HRESULT hr
Definition: delayimp.cpp:582
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
HRESULT WINAPI CLSIDFromString(LPCOLESTR str, LPCLSID clsid)
Definition: combase.c:1470
HRESULT WINAPI DECLSPEC_HOTPATCH CoCreateInstance(REFCLSID rclsid, IUnknown *outer, DWORD cls_context, REFIID riid, void **obj)
Definition: combase.c:1685
#define MAX_PATH
Definition: compat.h:34
HRESULT WINAPI SHLoadIndirectString(const WCHAR *src, WCHAR *dst, UINT dst_len, void **reserved)
Definition: string.c:1499
GUID guid
Definition: version.c:147
#define L(x)
Definition: resources.c:13
#define printf
Definition: freeldr.h:103
#define SUCCEEDED(hr)
Definition: intsafe.h:50
@ CCT_SCOPE
Definition: mmc.idl:88
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
Definition: msconfig.c:49
CAtlStringA CAtlString
Definition: atlstr.h:138
#define KEY_READ
Definition: nt_native.h:1026
short WCHAR
Definition: pedump.c:58
#define _countof(array)
Definition: sndvol32.h:70
Definition: copy.c:22
char displayName[]
Definition: tftpd.cpp:35
uint16_t * PWSTR
Definition: typedefs.h:56
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413