Creates an object that can query registry values
Syntax
HRESULT WINAPI QuerySourceCreateFromKeyEx (
HKEY hKey,
LPCWSTR pwszSubKey,
BOOL shouldCreate,
ACCESS_MASK amDesired,
REFIID riid,
LPVOID* ppInterface
)
Parameters
- hKey
- A handle to an open registry key or a predefined key
- pwszSubKey
- The name of a subkey to open or create
- shouldCreate
- TRUE if the function creates the registry key (uses RegCreateKeyEx) or opens it (uses RegOpenKeyEx)
- amDesired
- Desired access to registry key. This value has KEY_READ added to it
- riid
- The id of the interface pointer to return
- ppInterface
- A pointer to a pointer that receives the returned interface
Return Value
S_OK on success, standard COM error code otherwise
Remarks
riid can be either IID_IQuerySource or IID_IObjectWithRegistryKey, these interfaces are defined as follows:
MIDL_INTERFACE("D960050C-F4E1-4294-ac4b-598913605923") IObjectWithRegistryKey : public IUnknown { // sets the source registry key // can only be set if the current key is zero otherwise returns E_UNEXPECTED STDMETHODIMP SetKey(HKEY hKey) = 0; // returns a copy of the source key with the specified access STDMETHODIMP GetKey(ACCESS_MASK accessDesired, HKEY* phKey) = 0; }; // for all of these methods, NULL for the pwszSubkey parameter means the current key MIDL_INTERFACE("7bc28ac2-0d9c-4941-bb9a-72becb184fac") IQuerySource : public IUnknown { // Creates an enumerator for values in this key (pThis->hKey) STDMETHODIMP EnumValues(IEnumString** ppEnum) = 0; // reads the string at subkey\value and creates a copy in *ppString. Must be freed with // CoTaskMemFree(). If the value isn't as string // HRESULT_FROM_WIN32(ERROR_DATATYPE_MISMATCH) is returned STDMETHODIMP QueryValueString(LPCWSTR pwszSubKey, LPCWSTR pwszValue, LPWSTR* ppString) = 0; // as above but for REG_DWORD values STDMETHODIMP QueryValueDword(LPCWSTR pwszSubKey, LPCWSTR pwszValue, DWORD* pData) = 0; // as above, but for GUIDs in REG_SZ values STDMETHODIMP QueryValueGuid(LPCWSTR pwszSubkey, LPCWSTR pwszValue, GUID* pGuid) = 0; // returns S_OK if it does, error otherwise STDMETHODIMP QueryValueExists(LPCWSTR pwszSubkey, LPCWSTR pwszValue) = 0; // FLAGGED_BYTE_BLOB is defined in the SDK. The fFlags member is the registry type of the data. The returned pointer must be freed with CoTaskMemFree STDMETHODIMP QueryValueDirect(LPCWSTR pwszSubkey, LPCWSTR pwszValue, FLAGGED_BYTE_BLOB** ppBlob) = 0; // returns an enumerator that enumerates the subkeys of pThis->hKey STDMETHODIMP EnumSources(IEnumString** pppEnum) = 0; // calls QuerySourceCreateFromKey(pThis->hKey, pwszSubkey, FALSE, IID_IObjectWithRegistryKey, ppInterface) // to create an interface pointer for pwszSubKey. // This can be queried for a IQuerySource interface STDMETHODIMP OpenSource(LPCWSTR pwszSubkey, IObjectWithRegistryKey* ppInterface) = 0; };This function is also known as _QuerySourceCreateFromKeyEx@24.