source: trunk/DirectShowSpy/Configuration.h @ 148

Last change on this file since 148 was 147, checked in by roman, 11 years ago

COM registration UI

  • Property svn:keywords set to Id
File size: 18.3 KB
Line 
1////////////////////////////////////////////////////////////
2// Copyright (C) Roman Ryltsov, 2008-2011
3// Created by Roman Ryltsov roman@alax.info
4//
5// $Id: Configuration.h 147 2012-11-22 22:49:34Z roman $
6
7#pragma once
8
9#include <atlctrlx.h>
10#include <atlsplit.h>
11#include "rofiles.h"
12#include "AboutDialog.h"
13
14////////////////////////////////////////////////////////////
15// CRegistrationPropertySheet
16
17class CRegistrationPropertySheet :
18        public CPropertySheetT<CRegistrationPropertySheet>
19{
20public:
21
22BEGIN_MSG_MAP_EX(CRegistrationPropertySheet)
23        CHAIN_MSG_MAP(CPropertySheet)
24        MSG_WM_SYSCOMMAND(OnSysCommand)
25END_MSG_MAP()
26
27public:
28
29        ////////////////////////////////////////////////////////
30        // CRegistrationPropertyPage
31
32        class CRegistrationPropertyPage :
33                public CPropertyPageT<CRegistrationPropertyPage>,
34                //public CDialogResize<CRegistrationPropertyPage>,
35                public CWindowWithPrivateMessagesT<CRegistrationPropertyPage>
36        {
37        public:
38                enum { IDD = IDD_REGISTRATION_REGISTRATION_PROPERTYPAGE };
39
40        BEGIN_MSG_MAP_EX(CRegistrationPropertyPage)
41                CHAIN_MSG_MAP(CPropertyPage)
42                //CHAIN_MSG_MAP(CDialogResize<CRegistrationPropertyPage>)
43                CHAIN_MSG_MAP(CWindowWithPrivateMessages)
44                MSG_WM_INITDIALOG(OnInitDialog)
45                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_REGISTER, OnRegister)
46                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_UNREGISTER, OnUnregister)
47                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERREGISTER, OnUserRegister)
48                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER, OnUserUnregister)
49                REFLECT_NOTIFICATIONS()
50        END_MSG_MAP()
51
52        private:
53                CRegistrationPropertySheet& m_PropertySheet;
54                CRoEdit m_StatusEdit;
55                CRoEdit m_PathEdit;
56                CButton m_RegisterButton;
57                CButton m_UnregisterButton;
58                CRoEdit m_UserStatusEdit;
59                CRoEdit m_UserPathEdit;
60                CButton m_UserRegisterButton;
61                CButton m_UserUnregisterButton;
62                //CRoIconStatic m_UserNoteStatic;
63                CRoArrayT<CString> m_StatusArray;
64                CPath m_sPath;
65                CPath m_sUserPath;
66
67                static BOOL IsAdministrator()
68                {
69                        bool bIsMember = FALSE;
70                        return CAccessToken().CheckTokenMembership(Sids::Admins(), &bIsMember) && bIsMember;
71                }
72
73        public:
74        // CRegistrationPropertyPage
75                CRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() :
76                        m_PropertySheet(*pPropertySheet)
77                {
78                }
79                VOID UpdateControls()
80                {
81                        _A(_pAtlModule);
82                        #pragma region System
83                        CPath sPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE);
84                        const BOOL bPathEmpty = _tcslen(sPath) == 0;
85                        m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]);
86                        m_PathEdit.SetValue(sPath);
87                        m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty);
88                        m_PathEdit.EnableWindow(!bPathEmpty);
89                        m_RegisterButton.EnableWindow(bPathEmpty);
90                        m_UnregisterButton.EnableWindow(!bPathEmpty);
91                        m_sPath = sPath;
92                        #pragma endregion
93                        #pragma region Per-User
94                        CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER);
95                        const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0;
96                        m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]);
97                        m_UserPathEdit.SetValue(sUserPath);
98                        m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty);
99                        m_UserPathEdit.EnableWindow(!bUserPathEmpty);
100                        m_UserRegisterButton.EnableWindow(bUserPathEmpty);
101                        m_UserUnregisterButton.EnableWindow(!bUserPathEmpty);
102                        m_sUserPath = sUserPath;
103                        #pragma endregion
104                }
105
106        // CDialogResize                               
107                       
108        // Window message handlers
109                LRESULT OnInitDialog(HWND, LPARAM)
110                {
111                        _ATLTRY
112                        {
113                                CWaitCursor WaitCursor;
114                                m_StatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_STATUS);
115                                m_PathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_PATH);
116                                m_RegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_REGISTER);
117                                m_UnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_UNREGISTER);
118                                m_UserStatusEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERSTATUS);
119                                m_UserPathEdit = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERPATH);
120                                m_UserRegisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERREGISTER);
121                                m_UserUnregisterButton = GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERUNREGISTER);
122                                //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(IDC_REGISTRATION_REGISTRATION_USERNOTE)));
123                                //m_UserNoteStatic.SetIdealHeight();
124                                if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008
125                                {
126                                        if(!IsAdministrator())
127                                        {
128                                                m_RegisterButton.SetElevationRequiredState(TRUE);
129                                                m_UnregisterButton.SetElevationRequiredState(TRUE);
130                                        }
131                                }
132                                _StringHelper::GetCommaSeparatedItems(AtlLoadString(IDC_REGISTRATION_REGISTRATION_STATUS), m_StatusArray);
133                                _A(m_StatusArray.GetCount() == 2);
134                                UpdateControls();
135                        }
136                        _ATLCATCHALL()
137                        {
138                                for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT))
139                                        Window.EnableWindow(FALSE);
140                                _ATLRETHROW;
141                        }
142                        return TRUE;
143                }
144                LRESULT OnDestroy()
145                {
146                        return 0;
147                }
148                INT OnSetActive() throw()
149                {
150                        _ATLTRY
151                        {
152                                CWaitCursor WaitCursor;
153                                UpdateControls();
154                        }
155                        _ATLCATCHALL()
156                        {
157                                _Z_EXCEPTION();
158                                return -1;
159                        }
160                        return 0;
161                }
162                LRESULT OnRegister(UINT, INT, HWND)
163                {
164                        _ATLTRY
165                        {
166                                CWaitCursor WaitCursor;
167                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
168                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE);
169                                if(bSilent)
170                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
171                        }
172                        _ATLCATCH(Exception)
173                        {
174                                AtlExceptionMessageBox(m_hWnd, Exception);
175                        }
176                        UpdateControls();
177                        return 0;
178                }
179                LRESULT OnUnregister(UINT, INT, HWND)
180                {
181                        _ATLTRY
182                        {
183                                CWaitCursor WaitCursor;
184                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
185                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()), TRUE);
186                                if(bSilent)
187                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
188                        }
189                        _ATLCATCH(Exception)
190                        {
191                                AtlExceptionMessageBox(m_hWnd, Exception);
192                        }
193                        UpdateControls();
194                        return 0;
195                }
196                LRESULT OnUserRegister(UINT, INT, HWND)
197                {
198                        _ATLTRY
199                        {
200                                CWaitCursor WaitCursor;
201                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
202                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()));
203                                if(bSilent)
204                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
205                        }
206                        _ATLCATCH(Exception)
207                        {
208                                AtlExceptionMessageBox(m_hWnd, Exception);
209                        }
210                        UpdateControls();
211                        return 0;
212                }
213                LRESULT OnUserUnregister(UINT, INT, HWND)
214                {
215                        _ATLTRY
216                        {
217                                CWaitCursor WaitCursor;
218                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
219                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), GetPath()));
220                                if(bSilent)
221                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
222                        }
223                        _ATLCATCH(Exception)
224                        {
225                                AtlExceptionMessageBox(m_hWnd, Exception);
226                        }
227                        UpdateControls();
228                        return 0;
229                }
230        };
231
232        ////////////////////////////////////////////////////////
233        // CProppageRegistrationPropertyPage
234
235        class CProppageRegistrationPropertyPage :
236                public CPropertyPageT<CProppageRegistrationPropertyPage>,
237                //public CDialogResize<CProppageRegistrationPropertyPage>,
238                public CWindowWithPrivateMessagesT<CProppageRegistrationPropertyPage>
239        {
240        public:
241                enum { IDD = IDD_REGISTRATION_PROPPAGEREGISTRATION_PROPERTYPAGE };
242
243        BEGIN_MSG_MAP_EX(CProppageRegistrationPropertyPage)
244                CHAIN_MSG_MAP(CPropertyPage)
245                //CHAIN_MSG_MAP(CDialogResize<CProppageRegistrationPropertyPage>)
246                CHAIN_MSG_MAP(CWindowWithPrivateMessages)
247                MSG_WM_INITDIALOG(OnInitDialog)
248                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_REGISTER, OnRegister)
249                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_UNREGISTER, OnUnregister)
250                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERREGISTER, OnUserRegister)
251                COMMAND_ID_HANDLER_EX(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERUNREGISTER, OnUserUnregister)
252                REFLECT_NOTIFICATIONS()
253        END_MSG_MAP()
254
255        private:
256                CRegistrationPropertySheet& m_PropertySheet;
257                CRoEdit m_StatusEdit;
258                CRoEdit m_PathEdit;
259                CButton m_RegisterButton;
260                CButton m_UnregisterButton;
261                CRoEdit m_UserStatusEdit;
262                CRoEdit m_UserPathEdit;
263                CButton m_UserRegisterButton;
264                CButton m_UserUnregisterButton;
265                //CRoIconStatic m_UserNoteStatic;
266                CRoArrayT<CString> m_StatusArray;
267                CPath m_sPath;
268                CPath m_sUserPath;
269
270                static BOOL IsAdministrator()
271                {
272                        bool bIsMember = FALSE;
273                        return CAccessToken().CheckTokenMembership(Sids::Admins(), &bIsMember) && bIsMember;
274                }
275
276        public:
277        // CProppageRegistrationPropertyPage
278                CProppageRegistrationPropertyPage(CRegistrationPropertySheet* pPropertySheet) throw() :
279                        m_PropertySheet(*pPropertySheet)
280                {
281                }
282                VOID UpdateControls()
283                {
284                        class __declspec(uuid("92A3A302-DA7C-4A1F-BA7E-1802BB5D2D02")) PSFactoryBuffer;
285                        _A(_pAtlModule);
286                        #pragma region System
287                        //CPath sUserPath = FindTypeLibraryPath(HKEY_LOCAL_MACHINE);
288                        CPath sPath = FindClassPath(HKEY_LOCAL_MACHINE, __uuidof(PSFactoryBuffer));
289                        const BOOL bPathEmpty = _tcslen(sPath) == 0;
290                        m_StatusEdit.SetValue(m_StatusArray[bPathEmpty ? 0 : 1]);
291                        m_PathEdit.SetValue(sPath);
292                        m_PathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bPathEmpty);
293                        m_PathEdit.EnableWindow(!bPathEmpty);
294                        m_RegisterButton.EnableWindow(bPathEmpty);
295                        m_UnregisterButton.EnableWindow(!bPathEmpty);
296                        m_sPath = sPath;
297                        #pragma endregion
298                        #pragma region Per-User
299                        //CPath sUserPath = FindTypeLibraryPath(HKEY_CURRENT_USER);
300                        //const BOOL bUserPathEmpty = _tcslen(sUserPath) == 0;
301                        //m_UserStatusEdit.SetValue(m_StatusArray[bUserPathEmpty ? 0 : 1]);
302                        //m_UserPathEdit.SetValue(sUserPath);
303                        //m_UserPathEdit.GetWindow(GW_HWNDPREV).EnableWindow(!bUserPathEmpty);
304                        //m_UserPathEdit.EnableWindow(!bUserPathEmpty);
305                        //m_UserRegisterButton.EnableWindow(bUserPathEmpty);
306                        //m_UserUnregisterButton.EnableWindow(!bUserPathEmpty);
307                        //m_sUserPath = sUserPath;
308                        #pragma endregion
309                }
310
311        // CDialogResize                               
312                       
313        // Window message handlers
314                LRESULT OnInitDialog(HWND, LPARAM)
315                {
316                        _ATLTRY
317                        {
318                                CWaitCursor WaitCursor;
319                                m_StatusEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_STATUS);
320                                m_PathEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_PATH);
321                                m_RegisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_REGISTER);
322                                m_UnregisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_UNREGISTER);
323                                m_UserStatusEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERSTATUS);
324                                m_UserPathEdit = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERPATH);
325                                m_UserRegisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERREGISTER);
326                                m_UserUnregisterButton = GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERUNREGISTER);
327                                //_W(m_UserNoteStatic.SubclassWindow(GetDlgItem(IDC_REGISTRATION_PROPPAGEREGISTRATION_USERNOTE)));
328                                //m_UserNoteStatic.SetIdealHeight();
329                                if(GetOsVersion() >= 0x00060000) // Windows Vista or Windows Server 2008
330                                {
331                                        if(!IsAdministrator())
332                                        {
333                                                m_RegisterButton.SetElevationRequiredState(TRUE);
334                                                m_UnregisterButton.SetElevationRequiredState(TRUE);
335                                        }
336                                }
337                                _StringHelper::GetCommaSeparatedItems(AtlLoadString(IDC_REGISTRATION_PROPPAGEREGISTRATION_STATUS), m_StatusArray);
338                                _A(m_StatusArray.GetCount() == 2);
339                                UpdateControls();
340                        }
341                        _ATLCATCHALL()
342                        {
343                                for(CWindow Window = GetWindow(GW_CHILD); Window.IsWindow(); Window = Window.GetWindow(GW_HWNDNEXT))
344                                        Window.EnableWindow(FALSE);
345                                _ATLRETHROW;
346                        }
347                        return TRUE;
348                }
349                LRESULT OnDestroy()
350                {
351                        return 0;
352                }
353                INT OnSetActive() throw()
354                {
355                        _ATLTRY
356                        {
357                                CWaitCursor WaitCursor;
358                                UpdateControls();
359                        }
360                        _ATLCATCHALL()
361                        {
362                                _Z_EXCEPTION();
363                                return -1;
364                        }
365                        return 0;
366                }
367                LRESULT OnRegister(UINT, INT, HWND)
368                {
369                        _ATLTRY
370                        {
371                                CWaitCursor WaitCursor;
372                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
373                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath), TRUE);
374                                if(bSilent)
375                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
376                        }
377                        _ATLCATCH(Exception)
378                        {
379                                AtlExceptionMessageBox(m_hWnd, Exception);
380                        }
381                        UpdateControls();
382                        return 0;
383                }
384                LRESULT OnUnregister(UINT, INT, HWND)
385                {
386                        _ATLTRY
387                        {
388                                CWaitCursor WaitCursor;
389                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
390                                const CPath& sPath = m_sPath; //m_PropertySheet.m_sPropPagePath
391                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /u \"%s\""), bSilent ? _T("/s") : _T(""), sPath), TRUE);
392                                if(bSilent)
393                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
394                        }
395                        _ATLCATCH(Exception)
396                        {
397                                AtlExceptionMessageBox(m_hWnd, Exception);
398                        }
399                        UpdateControls();
400                        return 0;
401                }
402                LRESULT OnUserRegister(UINT, INT, HWND)
403                {
404                        _ATLTRY
405                        {
406                                CWaitCursor WaitCursor;
407                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
408                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath));
409                                if(bSilent)
410                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
411                        }
412                        _ATLCATCH(Exception)
413                        {
414                                AtlExceptionMessageBox(m_hWnd, Exception);
415                        }
416                        UpdateControls();
417                        return 0;
418                }
419                LRESULT OnUserUnregister(UINT, INT, HWND)
420                {
421                        _ATLTRY
422                        {
423                                CWaitCursor WaitCursor;
424                                const BOOL bSilent = !(GetKeyState(VK_SCROLL) & 1);
425                                const DWORD nExitCode = ExecuteWait(AtlFormatString(_T("%s /i:user /n /u \"%s\""), bSilent ? _T("/s") : _T(""), m_PropertySheet.m_sPropPagePath));
426                                if(bSilent)
427                                        MessageBeep(nExitCode ? MB_ICONERROR : MB_OK);
428                        }
429                        _ATLCATCH(Exception)
430                        {
431                                AtlExceptionMessageBox(m_hWnd, Exception);
432                        }
433                        UpdateControls();
434                        return 0;
435                }
436        };
437
438private:
439        CRegistrationPropertyPage m_RegistrationPropertyPage;
440        CProppageRegistrationPropertyPage m_ProppageRegistrationPropertyPage;
441        CPath m_sPropPagePath;
442
443public:
444// CRegistrationPropertySheet
445        CRegistrationPropertySheet() :
446                CPropertySheetT<CRegistrationPropertySheet>(IDS_REGISTRATION_PROPERTYSHEETCAPTION),
447                m_RegistrationPropertyPage(this),
448                m_ProppageRegistrationPropertyPage(this)
449        {
450                AddPage(m_RegistrationPropertyPage);
451                CPath sDirectory = GetPath();
452                sDirectory.RemoveFileSpec();
453                m_sPropPagePath.Combine(sDirectory, _T("proppage.dll"));
454                if(m_sPropPagePath.FileExists())
455                        AddPage(m_ProppageRegistrationPropertyPage);
456        }
457        BOOL SetInitialPosition()
458        {
459                if(!__super::SetInitialPosition())
460                        return FALSE;
461                SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON)), TRUE);
462                SetIcon(AtlLoadIconImage(IDI_MODULE, LR_DEFAULTCOLOR, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)), FALSE);
463                #pragma region Indication of Bitness
464                CString sCaption;
465                _W(GetWindowText(sCaption));
466                #if defined(_WIN64)
467                        sCaption.Append(_T(" (64-bit)"));
468                #else
469                        if(SafeIsWow64Process())
470                                sCaption.Append(_T(" (32-bit)"));
471                #endif // defined(_WIN64)
472                _W(SetWindowText(sCaption));
473                #pragma endregion
474                #pragma region System Menu
475                CMenuHandle Menu = GetSystemMenu(FALSE);
476                _W(Menu.AppendMenu(MF_SEPARATOR));
477                _W(Menu.AppendMenu(MF_STRING, ID_APP_ABOUT, _T("&About...")));
478                #pragma endregion
479                return TRUE;
480        }
481        static LPCTSTR GetTypeLibraryType() throw()
482        {
483                #if defined(_WIN64)
484                        static LPCTSTR g_pszTypeLibraryType = _T("win64");
485                #else
486                        static LPCTSTR g_pszTypeLibraryType = _T("win32");
487                #endif // defined(_WIN64)
488                return g_pszTypeLibraryType;
489        }
490        static CPath FindTypeLibraryPath(const GUID& Identifier = _pAtlModule->m_libid)
491        {
492                CPath sPath;
493                CRegKey Key;
494                if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(HKEY_CLASSES_ROOT, AtlFormatString(_T("TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ))))
495                        sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key);
496                return sPath;
497        }
498        static CPath FindTypeLibraryPath(HKEY hRootKey, const GUID& Identifier = _pAtlModule->m_libid)
499        {
500                CPath sPath;
501                CRegKey Key;
502                if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\TypeLib\\%ls\\1.0\\0\\%s"), _PersistHelper::StringFromIdentifier(Identifier), GetTypeLibraryType()), KEY_READ))))
503                        sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key);
504                return sPath;
505        }
506        static CPath FindClassPath(HKEY hRootKey, const GUID& Identifier)
507        {
508                CPath sPath;
509                CRegKey Key;
510                if(SUCCEEDED(HRESULT_FROM_WIN32(Key.Open(hRootKey, AtlFormatString(_T("Software\\Classes\\CLSID\\%ls\\InProcServer32"), _PersistHelper::StringFromIdentifier(Identifier)), KEY_READ))))
511                        sPath = (LPCTSTR) _RegKeyHelper::QueryStringValue(Key);
512                return sPath;
513        }
514        static HANDLE Execute(const CString& sParameters, BOOL bAsAdministrator = FALSE)
515        {
516                SHELLEXECUTEINFO Information;
517                ZeroMemory(&Information, sizeof Information);
518                Information.cbSize = sizeof Information;
519                Information.fMask = SEE_MASK_NOCLOSEPROCESS; 
520                if(bAsAdministrator)
521                        Information.lpVerb = _T("runas");
522                Information.lpFile = _T("regsvr32.exe");
523                Information.nShow = SW_SHOWNORMAL; 
524                Information.lpParameters = sParameters; 
525                __E(ShellExecuteEx(&Information));
526                _Z4(atlTraceSync, 4, _T("Information.hInstApp 0x%p, .hProcess 0x%p\n"), Information.hInstApp, Information.hProcess);
527                return Information.hProcess;
528        }
529        static DWORD ExecuteWait(const CString& sParameters, BOOL bAsAdministrator = FALSE)
530        {
531                CHandle Process;
532                Process.Attach(Execute(sParameters, bAsAdministrator));
533                const DWORD nWaitResult = WaitForSingleObject(Process, INFINITE);
534                _Z4(atlTraceSync, 4, _T("nWaitResult 0x%x\n"), nWaitResult);
535                _A(nWaitResult == WAIT_OBJECT_0);
536                DWORD nExitCode = 0;
537                _W(GetExitCodeProcess(Process, &nExitCode));
538                _Z4(atlTraceGeneral, 4, _T("nExitCode %d (0x%x)\n"), nExitCode, nExitCode);
539                return nExitCode;
540        }
541        static CPath GetPath()
542        {
543                TCHAR pszPath[MAX_PATH] = { 0 };
544                _W(GetModuleFileName(_AtlBaseModule.GetModuleInstance(), pszPath, DIM(pszPath)));
545                return pszPath;
546        }
547
548// Window message handelrs
549        LRESULT OnSysCommand(UINT nCommand, CPoint)
550        {
551                switch(nCommand)
552                {
553                case ID_APP_ABOUT:
554                        {
555                                CAboutDialog Dialog;
556                                Dialog.DoModal(m_hWnd);
557                        }
558                        break;
559                default:
560                        SetMsgHandled(FALSE);
561                }
562                return 0;
563        }
564};
565
Note: See TracBrowser for help on using the repository browser.