X-Git-Url: https://git.saurik.com/apple/mdnsresponder.git/blobdiff_plain/67c8f8a10700c05d2460d60f5927f23cb5cb9241..0b74dd16dce34c1c64267ece7abda266fa586255:/mDNSWindows/ControlPanel/ControlPanelExe.cpp diff --git a/mDNSWindows/ControlPanel/ControlPanelExe.cpp b/mDNSWindows/ControlPanel/ControlPanelExe.cpp index b330074..94de794 100755 --- a/mDNSWindows/ControlPanel/ControlPanelExe.cpp +++ b/mDNSWindows/ControlPanel/ControlPanelExe.cpp @@ -13,22 +13,7 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - - Change History (most recent first): - -$Log: ControlPanelExe.cpp,v $ -Revision 1.3 2007/04/27 21:43:00 herscher -Update license info to Apache License, Version 2.0 - -Revision 1.2 2007/04/27 20:42:12 herscher - mDNS: Bonjour Control Panel for Windows doesn't work on Vista - -Revision 1.1.2.1 2007/04/27 18:13:55 herscher - mDNS: Bonjour Control Panel for Windows doesn't work on Vista - - - -*/ + */ #include "ControlPanelExe.h" @@ -37,6 +22,8 @@ Revision 1.1.2.1 2007/04/27 18:13:55 herscher #include "resource.h" #include +#include "loclibrary.h" +#include #ifdef _DEBUG @@ -45,17 +32,40 @@ Revision 1.1.2.1 2007/04/27 18:13:55 herscher static char THIS_FILE[] = __FILE__; #endif +#ifndef HeapEnableTerminationOnCorruption +# define HeapEnableTerminationOnCorruption (HEAP_INFORMATION_CLASS) 1 +#endif + + +// Stash away pointers to our resource DLLs + +static HINSTANCE g_nonLocalizedResources = NULL; +static HINSTANCE g_localizedResources = NULL; + + +HINSTANCE GetNonLocalizedResources() +{ + return g_nonLocalizedResources; +} + + +HINSTANCE GetLocalizedResources() +{ + return g_localizedResources; +} + + //--------------------------------------------------------------------------------------------------------------------------- // Static Declarations //--------------------------------------------------------------------------------------------------------------------------- -DEFINE_GUID(CLSID_ControlPanel, -0x1207552c, 0xe59, 0x4d9f, 0x85, 0x54, 0xf1, 0xf8, 0x6, 0xcd, 0x7f, 0xa9); - +DEFINE_GUID(CLSID_ControlPanel, + +0x1207552c, 0xe59, 0x4d9f, 0x85, 0x54, 0xf1, 0xf8, 0x6, 0xcd, 0x7f, 0xa9); + static LPCTSTR g_controlPanelGUID = TEXT( "{1207552C-0E59-4d9f-8554-F1F806CD7FA9}" ); -static LPCTSTR g_controlPanelName = TEXT( "Bonjour Control Panel" ); +static LPCTSTR g_controlPanelName = TEXT( "Bonjour" ); +static LPCTSTR g_controlPanelCanonicalName = TEXT( "Apple.Bonjour" ); static LPCTSTR g_controlPanelCategory = TEXT( "3,8" ); -static LPCTSTR g_controlPanelLocalizedName = g_controlPanelName; -static LPCTSTR g_controlPanelInfoTip = TEXT( "Configures Wide-Area Bonjour" ); static CCPApp theApp; @@ -158,7 +168,7 @@ CCPApp::~CCPApp() void -CCPApp::Register( LPCTSTR inClsidString, LPCTSTR inName, LPCTSTR inCategory, LPCTSTR inLocalizedName, LPCTSTR inInfoTip, LPCTSTR inIconPath, LPCTSTR inExePath ) +CCPApp::Register( LPCTSTR inClsidString, LPCTSTR inName, LPCTSTR inCanonicalName, LPCTSTR inCategory, LPCTSTR inLocalizedName, LPCTSTR inInfoTip, LPCTSTR inIconPath, LPCTSTR inExePath ) { typedef struct RegistryBuilder RegistryBuilder; @@ -180,7 +190,7 @@ CCPApp::Register( LPCTSTR inClsidString, LPCTSTR inName, LPCTSTR inCategory, LPC { { HKEY_LOCAL_MACHINE, TEXT( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\%s" ), NULL, REG_SZ, inName }, { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), NULL, NULL, NULL }, - { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), TEXT( "System.ApplicationName" ), REG_SZ, inName }, + { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), TEXT( "System.ApplicationName" ), REG_SZ, inCanonicalName }, { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), TEXT( "System.ControlPanel.Category" ), REG_SZ, inCategory }, { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), TEXT( "LocalizedString" ), REG_SZ, inLocalizedName }, { HKEY_CLASSES_ROOT, TEXT( "CLSID\\%s" ), TEXT( "InfoTip" ), REG_SZ, inInfoTip }, @@ -196,7 +206,7 @@ CCPApp::Register( LPCTSTR inClsidString, LPCTSTR inName, LPCTSTR inCategory, LPC n = sizeof_array( entries ); for( i = 0; i < n; ++i ) { - wsprintf( keyName, entries[ i ].subKey, inClsidString ); + StringCbPrintf( keyName, sizeof( keyName ), entries[ i ].subKey, inClsidString ); err = RegCreateKeyEx( entries[ i ].rootKey, keyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &key, NULL ); require_noerr( err, exit ); @@ -223,10 +233,10 @@ CCPApp::Unregister( LPCTSTR clsidString ) { TCHAR keyName[ MAX_PATH * 2 ]; - wsprintf( keyName, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\%s", clsidString ); + StringCbPrintf( keyName, sizeof( keyName ), L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ControlPanel\\NameSpace\\%s", clsidString ); MyRegDeleteKey( HKEY_LOCAL_MACHINE, keyName ); - wsprintf( keyName, L"CLSID\\%s", clsidString ); + StringCbPrintf( keyName, sizeof( keyName ), L"CLSID\\%s", clsidString ); MyRegDeleteKey( HKEY_CLASSES_ROOT, keyName ); } @@ -240,8 +250,43 @@ BOOL CCPApp::InitInstance() { CCommandLineInfo commandLine; + wchar_t resource[MAX_PATH]; + CString errorMessage; + CString errorCaption; + int res; OSStatus err = kNoErr; + HeapSetInformation( NULL, HeapEnableTerminationOnCorruption, NULL, 0 ); + + // + // initialize the debugging framework + // + debug_initialize( kDebugOutputTypeWindowsDebugger, "ControlPanel", NULL ); + debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelTrace ); + + // Before we load the resources, let's load the error string + + errorMessage.LoadString( IDS_REINSTALL ); + errorCaption.LoadString( IDS_REINSTALL_CAPTION ); + + res = PathForResource( NULL, L"ControlPanelResources.dll", resource, MAX_PATH ); + err = translate_errno( res != 0, kUnknownErr, kUnknownErr ); + require_noerr( err, exit ); + + g_nonLocalizedResources = LoadLibrary( resource ); + translate_errno( g_nonLocalizedResources, GetLastError(), kUnknownErr ); + require_noerr( err, exit ); + + res = PathForResource( NULL, L"ControlPanelLocalized.dll", resource, MAX_PATH ); + err = translate_errno( res != 0, kUnknownErr, kUnknownErr ); + require_noerr( err, exit ); + + g_localizedResources = LoadLibrary( resource ); + translate_errno( g_localizedResources, GetLastError(), kUnknownErr ); + require_noerr( err, exit ); + + AfxSetResourceHandle( g_localizedResources ); + // InitCommonControls() is required on Windows XP if an application // manifest specifies use of ComCtl32.dll version 6 or later to enable // visual styles. Otherwise, any window creation will fail. @@ -256,18 +301,25 @@ CCPApp::InitInstance() if ( commandLine.m_nShellCommand == CCommandLineInfo::AppRegister ) { + CString localizedName; + CString toolTip; TCHAR iconPath[ MAX_PATH + 12 ] = TEXT( "" ); TCHAR exePath[ MAX_PATH ] = TEXT( "" ); DWORD nChars; OSStatus err; - nChars = GetModuleFileName( NULL, exePath, sizeof_array( exePath ) ); - err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr ); + nChars = GetModuleFileName( NULL, exePath, sizeof_array( exePath ) ); + + err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr ); + require_noerr( err, exit ); - wsprintf( iconPath, L"%s,-%d", exePath, IDR_APPLET ); + StringCbPrintf( iconPath, sizeof( iconPath ), L"%s,-%d", exePath, IDR_APPLET ); - Register( g_controlPanelGUID, g_controlPanelName, g_controlPanelCategory, g_controlPanelName, g_controlPanelInfoTip, iconPath, exePath ); + localizedName.LoadString( IDS_APPLET_NAME ); + toolTip.LoadString( IDS_APPLET_TOOLTIP ); + + Register( g_controlPanelGUID, g_controlPanelName, g_controlPanelCanonicalName, g_controlPanelCategory, localizedName, toolTip, iconPath, exePath ); } else if ( commandLine.m_nShellCommand == CCommandLineInfo::AppUnregister ) { @@ -311,6 +363,11 @@ CCPApp::InitInstance() exit: + if ( err ) + { + MessageBox( NULL, errorMessage, errorCaption, MB_ICONERROR | MB_OK ); + } + // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE;