FreeCAD

Форк
0
215 строк · 6.3 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2011 Werner Mayer <wmayer@users.sourceforge.net>        *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This library is free software; you can redistribute it and/or         *
7
 *   modify it under the terms of the GNU Library General Public           *
8
 *   License as published by the Free Software Foundation; either          *
9
 *   version 2 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         *
14
 *   GNU Library General Public License for more details.                  *
15
 *                                                                         *
16
 *   You should have received a copy of the GNU Library General Public     *
17
 *   License along with this library; see the file COPYING.LIB. If not,    *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                *
20
 *                                                                         *
21
 ***************************************************************************/
22

23

24
#define INITGUID
25
#include "Common.h"
26

27
HINSTANCE g_hinstDll = NULL;
28
LONG g_cRef = 0;
29

30

31
typedef struct _REGKEY_DELETEKEY
32
{
33
    HKEY hKey;
34
    LPCWSTR lpszSubKey;
35
} REGKEY_DELETEKEY;
36

37

38
typedef struct _REGKEY_SUBKEY_AND_VALUE
39
{
40
    HKEY hKey;
41
    LPCWSTR lpszSubKey;
42
    LPCWSTR lpszValue;
43
    DWORD dwType;
44
    DWORD_PTR dwData;
45
    ;
46
} REGKEY_SUBKEY_AND_VALUE;
47

48
STDAPI CreateRegistryKeys(REGKEY_SUBKEY_AND_VALUE* aKeys, ULONG cKeys);
49
STDAPI DeleteRegistryKeys(REGKEY_DELETEKEY* aKeys, ULONG cKeys);
50

51

52
BOOL APIENTRY DllMain(HINSTANCE hinstDll, DWORD dwReason, LPVOID pvReserved)
53
{
54
    switch (dwReason) {
55
        case DLL_PROCESS_ATTACH:
56
            g_hinstDll = hinstDll;
57
            break;
58
    }
59
    return TRUE;
60
}
61

62
STDAPI_(HINSTANCE) DllInstance()
63
{
64
    return g_hinstDll;
65
}
66

67
STDAPI DllCanUnloadNow()
68
{
69
    return g_cRef ? S_FALSE : S_OK;
70
}
71

72
STDAPI_(ULONG) DllAddRef()
73
{
74
    LONG cRef = InterlockedIncrement(&g_cRef);
75
    return cRef;
76
}
77

78
STDAPI_(ULONG) DllRelease()
79
{
80
    LONG cRef = InterlockedDecrement(&g_cRef);
81
    if (0 > cRef) {
82
        cRef = 0;
83
    }
84
    return cRef;
85
}
86

87
STDAPI DllRegisterServer()
88
{
89
    // This tells the shell to invalidate the thumbnail cache.  This is important because any
90
    // .recipe files viewed before registering this handler would otherwise show cached blank
91
    // thumbnails.
92
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
93

94
    WCHAR szModule[MAX_PATH];
95

96
    ZeroMemory(szModule, sizeof(szModule));
97
    GetModuleFileName(g_hinstDll, szModule, ARRAYSIZE(szModule));
98

99
    // uncomment the following
100
    REGKEY_SUBKEY_AND_VALUE keys[] = {
101
        {HKEY_CLASSES_ROOT,
102
         L"CLSID\\" szCLSID_SampleThumbnailProvider,
103
         NULL,
104
         REG_SZ,
105
         (DWORD_PTR)L"FCStd Thumbnail Provider"},
106
#if 1
107
        //{HKEY_CLASSES_ROOT, L"CLSID\\DisableProcessIsolation", NULL, REG_DWORD, (DWORD) 1},
108
        {HKEY_CLASSES_ROOT,
109
         L"CLSID\\" szCLSID_SampleThumbnailProvider,
110
         L"DisableProcessIsolation",
111
         REG_DWORD,
112
         (DWORD)1},
113
#endif
114
        {HKEY_CLASSES_ROOT,
115
         L"CLSID\\" szCLSID_SampleThumbnailProvider L"\\InprocServer32",
116
         NULL,
117
         REG_SZ,
118
         (DWORD_PTR)szModule},
119
        {HKEY_CLASSES_ROOT,
120
         L"CLSID\\" szCLSID_SampleThumbnailProvider L"\\InprocServer32",
121
         L"ThreadingModel",
122
         REG_SZ,
123
         (DWORD_PTR)L"Apartment"},
124
        //{HKEY_CLASSES_ROOT, L".FCStd\\shellex", L"Trick only here to create shellex when not
125
        // existing",REG_DWORD, 1},
126
        {HKEY_CLASSES_ROOT,
127
         L".FCStd\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}",
128
         NULL,
129
         REG_SZ,
130
         (DWORD_PTR)szCLSID_SampleThumbnailProvider},
131
        {HKEY_CLASSES_ROOT,
132
         L".FCBak\\shellex\\{E357FCCD-A995-4576-B01F-234630154E96}",
133
         NULL,
134
         REG_SZ,
135
         (DWORD_PTR)szCLSID_SampleThumbnailProvider}
136
    };
137

138
    return CreateRegistryKeys(keys, ARRAYSIZE(keys));
139
}
140

141
STDAPI DllUnregisterServer()
142
{
143
    REGKEY_DELETEKEY keys[] = {{HKEY_CLASSES_ROOT, L"CLSID\\" szCLSID_SampleThumbnailProvider}};
144
    return DeleteRegistryKeys(keys, ARRAYSIZE(keys));
145
}
146

147

148
STDAPI CreateRegistryKey(REGKEY_SUBKEY_AND_VALUE* pKey)
149
{
150
    size_t cbData;
151
    LPVOID pvData = NULL;
152
    HRESULT hr = S_OK;
153

154
    switch (pKey->dwType) {
155
        case REG_DWORD:
156
            pvData = (LPVOID)(LPDWORD)&pKey->dwData;
157
            cbData = sizeof(DWORD);
158
            break;
159

160
        case REG_SZ:
161
        case REG_EXPAND_SZ:
162
            hr = StringCbLength((LPCWSTR)pKey->dwData, STRSAFE_MAX_CCH, &cbData);
163
            if (SUCCEEDED(hr)) {
164
                pvData = (LPVOID)(LPCWSTR)pKey->dwData;
165
                cbData += sizeof(WCHAR);
166
            }
167
            break;
168

169
        default:
170
            hr = E_INVALIDARG;
171
    }
172

173
    if (SUCCEEDED(hr)) {
174
        LSTATUS status = SHSetValue(pKey->hKey,
175
                                    pKey->lpszSubKey,
176
                                    pKey->lpszValue,
177
                                    pKey->dwType,
178
                                    pvData,
179
                                    (DWORD)cbData);
180
        if (NOERROR != status) {
181
            hr = HRESULT_FROM_WIN32(status);
182
        }
183
    }
184

185
    return hr;
186
}
187

188

189
STDAPI CreateRegistryKeys(REGKEY_SUBKEY_AND_VALUE* aKeys, ULONG cKeys)
190
{
191
    HRESULT hr = S_OK;
192

193
    for (ULONG iKey = 0; iKey < cKeys; iKey++) {
194
        HRESULT hrTemp = CreateRegistryKey(&aKeys[iKey]);
195
        if (FAILED(hrTemp)) {
196
            hr = hrTemp;
197
        }
198
    }
199
    return hr;
200
}
201

202

203
STDAPI DeleteRegistryKeys(REGKEY_DELETEKEY* aKeys, ULONG cKeys)
204
{
205
    HRESULT hr = S_OK;
206
    LSTATUS status;
207

208
    for (ULONG iKey = 0; iKey < cKeys; iKey++) {
209
        status = RegDeleteTree(aKeys[iKey].hKey, aKeys[iKey].lpszSubKey);
210
        if (NOERROR != status) {
211
            hr = HRESULT_FROM_WIN32(status);
212
        }
213
    }
214
    return hr;
215
}
216

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.