source: Daodan/MSYS2/mingw32/i686-w64-mingw32/include/sphelper.h@ 1186

Last change on this file since 1186 was 1166, checked in by rossy, 3 years ago

Daodan: Replace MinGW build env with an up-to-date MSYS2 env

File size: 2.1 KB
Line 
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6
7#ifndef SPHelper_h
8#define SPHelper_h
9
10#include <winapifamily.h>
11
12#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
13
14#include <malloc.h>
15#include <sapi.h>
16/* #include <sapiddk.h> */
17#include <sperror.h>
18#include <limits.h>
19#include <mmsystem.h>
20#include <comcat.h>
21#include <mmreg.h>
22/* #include <atlbase.h> */
23#include <wchar.h>
24#include <tchar.h>
25#include <strsafe.h>
26#include <intsafe.h>
27
28inline HRESULT SpGetCategoryFromId(const WCHAR *category_id, ISpObjectTokenCategory **ret, BOOL fCreateIfNotExist = FALSE) {
29 ISpObjectTokenCategory *obj_token_cat;
30 HRESULT hres;
31
32 hres = ::CoCreateInstance(CLSID_SpObjectTokenCategory, NULL, CLSCTX_ALL, __uuidof(ISpObjectTokenCategory),
33 (void**)&obj_token_cat);
34 if(FAILED(hres))
35 return hres;
36
37 hres = obj_token_cat->SetId(category_id, fCreateIfNotExist);
38 if(FAILED(hres)) {
39 obj_token_cat->Release();
40 return hres;
41 }
42
43 *ret = obj_token_cat;
44 return S_OK;
45}
46
47inline HRESULT SpEnumTokens(const WCHAR *category_id, const WCHAR *req_attrs, const WCHAR *opt_attrs, IEnumSpObjectTokens **ret) {
48 ISpObjectTokenCategory *category;
49 HRESULT hres;
50
51 hres = SpGetCategoryFromId(category_id, &category);
52 if(SUCCEEDED(hres)) {
53 hres = category->EnumTokens(req_attrs, opt_attrs, ret);
54 category->Release();
55 }
56
57 return hres;
58}
59
60/* str must be at least 9 chars (8 for 32-bit integer in hex + one for '\0'). */
61inline void SpHexFromUlong(WCHAR *str, ULONG ul) {
62 ::_ultow(ul, str, 16);
63}
64
65inline HRESULT SpGetDescription(ISpObjectToken *obj_token, WCHAR **description, LANGID language = GetUserDefaultUILanguage()) {
66 WCHAR lang_id[9];
67 HRESULT hres;
68
69 SpHexFromUlong(lang_id, language);
70 hres = obj_token->GetStringValue(lang_id, description);
71 if(hres == SPERR_NOT_FOUND)
72 hres = obj_token->GetStringValue(NULL, description);
73
74 return hres;
75}
76
77#endif
78#endif
Note: See TracBrowser for help on using the repository browser.