]> git.saurik.com Git - apple/mdnsresponder.git/blobdiff - mDNSWindows/ControlPanel/ControlPanelExe.cpp
mDNSResponder-544.tar.gz
[apple/mdnsresponder.git] / mDNSWindows / ControlPanel / ControlPanelExe.cpp
index b3300745ebad1934714f60a3af36f5bd39075845..36447d11ddc2f2b5718c00c52e33b207c856db52 100755 (executable)
  * 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
-<rdar://problem/5078828> mDNS: Bonjour Control Panel for Windows doesn't work on Vista
-
-Revision 1.1.2.1  2007/04/27 18:13:55  herscher
-<rdar://problem/5078828> mDNS: Bonjour Control Panel for Windows doesn't work on Vista
-
-
-
-*/
+ */
 
     
 #include "ControlPanelExe.h"
@@ -37,6 +22,7 @@ Revision 1.1.2.1  2007/04/27 18:13:55  herscher
 #include "resource.h"
 
 #include <DebugServices.h>
+#include "loclibrary.h"
 
 
 #ifdef _DEBUG
@@ -45,17 +31,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, \r
-0x1207552c, 0xe59, 0x4d9f, 0x85, 0x54, 0xf1, 0xf8, 0x6, 0xcd, 0x7f, 0xa9);\r
-\r
+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 +167,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 +189,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 },
@@ -240,8 +249,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 +300,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 ) );\r
-               err = translate_errno( nChars > 0, (OSStatus) GetLastError(), kUnknownErr );\r
+               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 );
 
-               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 +362,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;