Click here to Skip to main content
12,623,027 members (36,740 online)
Click here to Skip to main content
Articles » Languages » C++ / CLI » General » Downloads

Stats

552.3K views
7.1K downloads
134 bookmarked
Posted

Enhanced .NET Bootstrap Setup

, 24 Nov 2005
Modified Microsoft Setup program to install required IE6, MSI 2.0 and .NET.
// 
//   Copyright (c) Microsoft Corporation.  All rights reserved.
//
/// ==========================================================================
// Name    :    CError.cpp
// Purpose :    simple wrapper class for displaying (error) msgs

// includes
#include <windows.h>
#include <stdio.h>

#include "CError.h"
#include "CSettings.h"
#include "resource.h"

TCHAR CError::s_szProductName[MAX_PATH+1] = { END_OF_STRING }; // _T('\0')

// Constructors
//
// ==========================================================================
// CError::CError()
//
// Purpose:
//  parameterless CError object construction
// ==========================================================================
CError::
CError()

: m_nRetCode(ERROR_SUCCESS),
  m_nMessage(0), 
  m_nCaption(0), 
  m_nIconType(0),
  m_pszArg(NULL)
{
    
}

// ==========================================================================
// CError::CError()
//
// Inputs:
//  UINT nMsg: resourceId for the message to display
//  UINT nCap: resourceId for the caption to display
//  UINT nIcon: icon to use
//  int nRetCode: return code to be returned to the caller of the wrapper
// Purpose:
//  constructs CError object with initial values
// ==========================================================================
CError::CError( UINT nMsg, UINT nCap, UINT nIcon, int nRetCode, LPCTSTR pszArg)
: m_nMessage(nMsg), 
  m_nCaption(nCap), 
  m_nIconType(nIcon),
  m_nRetCode(nRetCode),
  m_pszArg(pszArg)
{

}

// Operations
// ==========================================================================
// CError::ShowMessage()
//
// Purpose:
//  displays messagebox w/resource-based content
// ==========================================================================
int CError::ShowMessage()
{
    TCHAR szCapFmt[MAX_PATH]  = EMPTY_BUFFER;
    TCHAR szMsgFmt[MAX_MSG]   = EMPTY_BUFFER;
    TCHAR szCaption[MAX_PATH] = EMPTY_BUFFER;
    TCHAR szMessage[MAX_MSG]  = EMPTY_BUFFER;

    int nResponse = IDCANCEL;

    // if a caption resource id has been specified, load it
    if (m_nCaption > 0)
    {
        ::LoadString( g_settings.GetHInstance(), 
                      m_nCaption, 
                      szCapFmt, 
                      LENGTH(szCapFmt) );

        _sntprintf( szCaption, 
                    LENGTH(szCaption) - 1, 
                    szCapFmt, 
                    g_settings.GetProductName() );
    }
    // otherwise use the global caption string
    else
    {
        _sntprintf( szCaption, 
                    LENGTH(szCaption) - 1, 
                    g_settings.GetErrorCaptionText(), 
                    g_settings.GetProductName() );
    }

    ::LoadString( g_settings.GetHInstance(), 
                  m_nMessage, 
                  szMsgFmt, 
                  LENGTH(szMsgFmt) );

    if ( NULL != m_pszArg )
    {
        _sntprintf( szMessage, 
                    LENGTH(szMessage) - 1, 
                    szMsgFmt, 
                    m_pszArg);
    }
    else
    {
        _sntprintf( szMessage, 
                    LENGTH(szMessage) - 1, 
                    szMsgFmt, 
                    g_settings.GetProductName() );
    }

    // this sample does not currently support setting quiet
    // mode via a cmd-line switch or another mechanism, 
    // but it could easily be modified to do so.
    if ( !g_settings.GetQuietMode() )
    {
        nResponse = ::MessageBox( NULL, 
                                  (LPCTSTR)szMessage, 
                                  szCaption, 
                                  MB_OK | m_nIconType ) ;
    }
    // else print message to stderr
    else
    {
        _ftprintf ( stderr, (LPCTSTR)szMessage ) ;
    }

    // for quiet mode, we assume 'yes' as response
    if (g_settings.GetQuietMode())
    {
        nResponse = IDOK;
    }

    return nResponse;
}

// Operations
// ==========================================================================
// CError::ShowMessage()
//
// Inputs: none
// Purpose:
//  displays messagebox w/argument-supplied content
// ==========================================================================
int CError::ShowMessage(LPCTSTR szMsg, 
                        LPCTSTR szCaption, 
                        UINT nIcon, 
                        LPCTSTR szArg )
{
    TCHAR szMessage[MAX_MSG]  = EMPTY_BUFFER;

    int nResponse = IDCANCEL;

    _sntprintf( szMessage, 
                LENGTH(szMessage) - 1, 
                szMsg, 
                szArg != NULL ? szArg : _T(""));

    // this sample does not currently support setting quiet
    // mode via a cmd-line switch or another mechanism, 
    // but it could easily be modified to do so.
    if ( !g_settings.GetQuietMode() )
    {
        nResponse = ::MessageBox( NULL, 
                                  (LPCTSTR)szMessage, 
                                  szCaption, 
                                  nIcon ) ;
    }
    // else print message to stderr
    else
    {
        _ftprintf ( stderr, (LPCTSTR)szMessage ) ;
    }

    // for quiet mode, we assume 'yes' as response
    if (g_settings.GetQuietMode())
    {
        nResponse = IDOK;
    }

    return nResponse;
}

// ==========================================================================
// CError::ShowFormattedMessage()
//
// Inputs: none
// Purpose:
//  displays messagebox w/content created via FormatMessage
// ==========================================================================
int CError::ShowFormattedMessage(LPCTSTR szMsgFmt, 
                                 LPCTSTR szCaption, 
                                 UINT nIcon, 
                                 LPCTSTR szArg )
{
    LPVOID pMessage = NULL;

    int nResponse = IDCANCEL;

    LPCTSTR args[1] = {szArg};

    FormatMessage( 
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_STRING |
        FORMAT_MESSAGE_ARGUMENT_ARRAY,
        szMsgFmt,
        0,
        0,
        (LPTSTR)&pMessage,
        0,
        (va_list*)args
    );

    
    // this sample does not currently support setting quiet
    // mode via a cmd-line switch or another mechanism, 
    // but it could easily be modified to do so.
    if ( !g_settings.GetQuietMode() )
    {
        nResponse = ::MessageBox( NULL, 
                                  (LPCTSTR)pMessage, 
                                  szCaption, 
                                  nIcon ) ;
    }
    // else print message to stderr
    else
    {
        _ftprintf ( stderr, (LPCTSTR)pMessage ) ;
    }

    // for quiet mode, we assume 'yes' as response
    if (g_settings.GetQuietMode())
    {
        nResponse = IDOK;
    }
    
    LocalFree(pMessage);

    return nResponse;
}

// ==========================================================================
// CError::ShowHResultMessage()
//
// Inputs: none
// Purpose:
//  displays messagebox w/formatted content, including HRESULT text
// ==========================================================================
int CError::ShowHResultMessage(UINT nMsg, 
                               UINT nCaption, 
                               UINT nIcon, 
                               HRESULT hr, 
                               LPCTSTR pszArg)
{
    TCHAR szCapFmt[MAX_PATH]  = EMPTY_BUFFER;
    TCHAR szMsgFmt[MAX_MSG]   = EMPTY_BUFFER;
    TCHAR szCaption[MAX_PATH] = EMPTY_BUFFER;
    TCHAR szMessage[MAX_MSG]  = EMPTY_BUFFER;
    TCHAR szHResult[1024]     = EMPTY_BUFFER;

    LPVOID pMessage = NULL;

    UINT nResponse = IDCANCEL;

    // if a caption resource id has been specified, load it
    if (nCaption > 0)
    {
        ::LoadString( g_settings.GetHInstance(), 
                      nCaption, 
                      szCapFmt, 
                      LENGTH(szCapFmt) );

        _sntprintf( szCaption, 
                    LENGTH(szCaption) - 1, 
                    szCapFmt, 
                    g_settings.GetProductName() );
    }
    // otherwise use the global caption string
    else
    {
        _sntprintf( szCaption, 
                    LENGTH(szCaption) - 1, 
                    g_settings.GetErrorCaptionText(), 
                    g_settings.GetProductName() );
    }

    ::LoadString( g_settings.GetHInstance(), 
                  nMsg, 
                  szMsgFmt, 
                  LENGTH(szMsgFmt));

   FormatMessage( 
      FORMAT_MESSAGE_FROM_SYSTEM, 
      NULL,
      hr,
      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
      szHResult,
      LENGTH(szHResult),
      NULL 
      );

    if (NULL == pszArg)
    {
        LPCTSTR args[1] = {szHResult};

        FormatMessage( 
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_STRING |
            FORMAT_MESSAGE_ARGUMENT_ARRAY,
            szMsgFmt,
            0,
            0,
            (LPTSTR)&pMessage,
            0,
            (va_list*)args
        );
    }
    else
    {
        LPCTSTR args[2] = {pszArg, szHResult};

        FormatMessage( 
            FORMAT_MESSAGE_ALLOCATE_BUFFER | 
            FORMAT_MESSAGE_FROM_STRING |
            FORMAT_MESSAGE_ARGUMENT_ARRAY,
            szMsgFmt,
            0,
            0,
            (LPTSTR)&pMessage,
            0,
            (va_list*)args
        );
    }

    if ( !g_settings.GetQuietMode() )
    {
        nResponse = MessageBox( NULL, (
                                LPCTSTR)pMessage, 
                                szCaption, 
                                nIcon ) ;
    }
    // else print message to stderr
    else
    {
        _ftprintf ( stderr, (LPCTSTR)szMessage ) ;
    }

    // for quiet mode, we assume 'yes' as response
    if (g_settings.GetQuietMode())
    {
        nResponse = IDOK;
    }

    LocalFree(pMessage);
 
    return nResponse;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Kevin Moore
Web Developer
United States United States
No Biography provided

You may also be interested in...

Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 24 Nov 2005
Article Copyright 2003 by Kevin Moore
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid