home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / DLLUSER / DLLUSER.CPP next >
C/C++ Source or Header  |  1996-12-29  |  22KB  |  623 lines

  1. /*+==========================================================================
  2.   File:      DLLUSER.CPP
  3.  
  4.   Summary:   Based largely on the EXESKEL.EXE application code, this
  5.              module is meant to implicitly link to the DLLSKEL.DLL
  6.              and illustrate the use (by this DLLUSER app) of the two
  7.              exported calls from that DLL: DllHelloBox and DllAboutBox.
  8.              To this end, DLLUSER provides a Test menu with two menu
  9.              selections that exercise each of those calls.
  10.  
  11.              Since it is only a slight augmentation over the EXESKEL code
  12.              sample, DLLUSER in turn can be considered as another
  13.              application skeleton in a graduated sequence of skeletal
  14.              evolution.  Each capable of serving as a point of departure
  15.              in building more sophisticated applications.
  16.  
  17.              For a comprehensive tutorial code tour of DLLUSER's
  18.              contents and offerings see the tutorial DLLUSER.HTM file.
  19.              For more specific technical details on the internal workings
  20.              see the comments dispersed throughout the DLLUSER source code.
  21.              For more details on the DLLSKEL.DLL that DLLUSER works with
  22.              see the DLLSKEL.HTM file in the main tutorial directory.
  23.  
  24.   Classes:   CMainWindow
  25.  
  26.   Functions: InitApplication, WinMain
  27.  
  28.   Origin:    8-3-95: atrent - Editor-inheritance from the EXESKEL source.
  29.  
  30. ----------------------------------------------------------------------------
  31.   This file is part of the Microsoft ActiveX Tutorial Code Samples.
  32.  
  33.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  34.  
  35.   This source code is intended only as a supplement to Microsoft
  36.   Development Tools and/or on-line documentation.  See these other
  37.   materials for detailed information regarding Microsoft code samples.
  38.  
  39.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  40.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  41.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  42.   PARTICULAR PURPOSE.
  43. ==========================================================================+*/
  44.  
  45. /*---------------------------------------------------------------------------
  46.   We include WINDOWS.H for all Win32 applications.
  47.   We include OLE2.H because we will be calling the COM
  48.     Library's CoInitialize and CoUnInitialize calls.
  49.   We include COMMDLG.H because we will be using the Open File and
  50.     potentially other Common dialogs.
  51.   We include APPUTIL.H because we will be building this application using
  52.     the convenient Virtual Window and Dialog classes and other
  53.     utility functions in the APPUTIL Library (ie, APPUTIL.LIB).
  54.   We include DLLUSER.H because it has class and resource definitions
  55.     specific to this DLLUSER application.
  56.   We include DLLSKEL.H because we will be showcasing the use of service
  57.     functions provided by DLLSKEL.DLL.
  58. ---------------------------------------------------------------------------*/
  59. #include <windows.h>
  60. #include <ole2.h>
  61. #include <commdlg.h>
  62. #include <apputil.h>
  63. #include "dlluser.h"
  64. #include "dllskel.h"
  65.  
  66.  
  67. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  68.   Method:   CMainWindow::CMainWindow
  69.  
  70.   Summary:  CMainWindow Constructor.
  71.  
  72.   Args:     .
  73.  
  74.   Modifies: .
  75.  
  76.   Returns:  .
  77. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  78. CMainWindow::CMainWindow()
  79. {
  80.   // Ensure these member variable strings are null strings.
  81.   m_szFileName[0] = 0;
  82.   m_szFileTitle[0] = 0;
  83.  
  84.   // Fill in the Common Dialog's OPENFILENAME structure.
  85.   m_ofnFile.lStructSize = sizeof(OPENFILENAME);
  86.   m_ofnFile.hwndOwner = m_hWnd;
  87.   m_ofnFile.hInstance = m_hInst;
  88.   m_ofnFile.lpstrFilter = TEXT(OFN_DEFAULTFILES_STR);
  89.   m_ofnFile.lpstrCustomFilter = NULL;
  90.   m_ofnFile.nMaxCustFilter = 0;
  91.   m_ofnFile.nFilterIndex = 1;
  92.   m_ofnFile.lpstrFile = m_szFileName;
  93.   m_ofnFile.nMaxFile = MAX_PATH;
  94.   m_ofnFile.lpstrInitialDir = TEXT(".");
  95.   m_ofnFile.lpstrFileTitle = m_szFileTitle;
  96.   m_ofnFile.nMaxFileTitle = MAX_PATH;
  97.   m_ofnFile.lpstrTitle = TEXT(OFN_DEFAULTTITLE_STR);
  98.   m_ofnFile.lpstrDefExt = NULL;
  99.   m_ofnFile.Flags = OFN_HIDEREADONLY;
  100. }
  101.  
  102.  
  103. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  104.   Method:   CMainWindow::~CMainWindow
  105.  
  106.   Summary:  CMainWindow Destructor.  Destruction of the main window
  107.             indicates that the application should quit and thus the
  108.             PostQuitMessage API is called.
  109.  
  110.   Args:     .
  111.  
  112.   Modifies: .
  113.  
  114.   Returns:  .
  115. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  116. CMainWindow::~CMainWindow()
  117. {
  118.   // CMainWindow is derived from CVirWindow which traps the WM_DESTROY
  119.   // message and causes a delete of CMainWindow which in turn causes this
  120.   // destructor to run. The WM_DESTROY results when the window is destoyed
  121.   // after a close of the window. Prior to exiting the main message loop
  122.   // we delete the CMsgBox object that was made in Initinstance.
  123.   DELETE_POINTER(m_pMsgBox);
  124.  
  125.   // We post a WM_QUIT message to cause an exit of the main thread's
  126.   // message loop and an exit of this instance of the application.
  127.   PostQuitMessage(0);
  128. }
  129.  
  130.  
  131. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  132.   Method:   CMainWindow::InitInstance
  133.  
  134.   Summary:  Instantiates an instance of the main application window.
  135.             This method must be called only once, immediately after
  136.             window class construction.  We take care to delete 'this'
  137.             CMainWindow if we must return the error condition FALSE.
  138.  
  139.   Args:     HINSTANCE hInstance,
  140.               Handle of the application instance.
  141.             int nCmdShow)
  142.               Command to pass to ShowWindow.
  143.  
  144.   Modifies: m_szHelpFile, m_pMsgBox.
  145.  
  146.   Returns:  BOOL.
  147.               TRUE if succeeded.
  148.               FALSE if failed.
  149. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  150. BOOL CMainWindow::InitInstance(
  151.        HINSTANCE hInstance,
  152.        int nCmdShow)
  153. {
  154.   BOOL bResult = FALSE;
  155.  
  156.   // Create the Message Box object.
  157.   m_pMsgBox = new CMsgBox;
  158.   HWND hWnd;
  159.  
  160.   if (NULL != m_pMsgBox)
  161.   {
  162.     // Note, the Create method sets the m_hWnd member so we don't
  163.     //   need to set it explicitly here first.
  164.  
  165.     // Here is the create of this window.  Size the window reasonably.
  166.     //   Create sets both m_hInst and m_hWnd.
  167.     hWnd = Create(
  168.              TEXT(MAIN_WINDOW_CLASS_NAME_STR),
  169.              TEXT(MAIN_WINDOW_TITLE_STR),
  170.              WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
  171.                | WS_MAXIMIZEBOX | WS_THICKFRAME,
  172.              CW_USEDEFAULT,
  173.              CW_USEDEFAULT,
  174.              ::GetSystemMetrics(SM_CXSCREEN)*2/5,
  175.              ::GetSystemMetrics(SM_CYSCREEN)*2/5,
  176.              NULL,
  177.              NULL,
  178.              hInstance);
  179.     if (hWnd)
  180.     {
  181.       // Ensure the new window is shown on screen and its content is painted.
  182.       ::ShowWindow(m_hWnd, nCmdShow);
  183.       ::UpdateWindow(m_hWnd);
  184.  
  185.       // Build a path to where the help file should be (it should be in
  186.       // the same directory as the .EXE but with the .HLP extension.
  187.       MakeFamilyPath(hInstance, m_szHelpFile, TEXT(HELP_FILE_EXT));
  188.  
  189.       // Init the Message Box object and signal we succeeded initializing
  190.       // the application.
  191.       if (m_pMsgBox->Init(m_hInst, m_hWnd))
  192.         bResult = TRUE;
  193.     }
  194.   }
  195.  
  196.   if (!bResult)
  197.   {
  198.     DELETE_POINTER(m_pMsgBox);
  199.   }
  200.  
  201.   return (bResult);
  202. }
  203.  
  204.  
  205. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  206.   Method:   CMainWindow::DoMenu
  207.  
  208.   Summary:  Dispatch and handle the main menu commands.
  209.  
  210.   Args:     WPARAM wParam,
  211.               First message parameter (word sized).
  212.             LPARAM lParam)
  213.               Second message parameter (long sized).
  214.  
  215.   Modifies: m_ofnFile, ...
  216.  
  217.   Returns:  LRESULT
  218.               Standard Windows WindowProc return value.
  219. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  220. LRESULT CMainWindow::DoMenu(
  221.           WPARAM wParam,
  222.           LPARAM lParam)
  223. {
  224.   LRESULT lResult = FALSE;
  225.  
  226.   switch (LOWORD(wParam))
  227.   {
  228.     case IDM_FILE_EXIT:
  229.       // The user commands us to exit this application so we tell the
  230.       // Main window to close itself.
  231.       ::PostMessage(m_hWnd, WM_CLOSE, 0, 0);
  232.       break;
  233.  
  234.     case IDM_TEST_DLLHELLO:
  235.       // Call the DLLSKEL DLL to say hello from it.
  236.       ::DllHelloBox(m_hWnd);
  237.       break;
  238.  
  239.     case IDM_TEST_DLLABOUT:
  240.       // Call the DLLSKEL DLL to show the DLL's About Box.
  241.       ::DllAboutBox(m_hWnd);
  242.       break;
  243.  
  244.     // Handle Help Menu Commands.
  245.     case IDM_HELP_CONTENTS:
  246.       // We have some stubbed support here for bringing up the online
  247.       //   Help for this application.
  248.       if (::FileExist(m_szHelpFile))
  249.         ::WinHelp(m_hWnd, m_szHelpFile, HELP_CONTEXT, IDH_CONTENTS);
  250.       else
  251.         m_pMsgBox->ErrorID(IDS_NOHELPFILE);
  252.       break;
  253.  
  254.     case IDM_HELP_TUTORIAL:
  255.       // Call the APPUTIL utility function, ReadTutorial, to Browse the HTML
  256.       // tutorial narrative file associated with this tutorial code sample.
  257.       ReadTutorial(m_hInst, m_hWnd, TEXT(HTML_FILE_EXT));
  258.       break;
  259.  
  260.     case IDM_HELP_TUTDLL:
  261.       // Call the APPUTIL utility function, ReadTutorial, to Browse the HTML
  262.       // tutorial narrative file associated with the DLL server.
  263.       ReadTutorial(m_hInst, m_hWnd, TEXT(DLL_TUTFILE_STR));
  264.       break;
  265.  
  266.     case IDM_HELP_READSOURCE:
  267.       // Call the APPUTIL utility function ReadSource to allow the
  268.       // user to open and read any of the source files of DLLUSER.
  269.       ReadSource(m_hWnd, &m_ofnFile);
  270.       break;
  271.  
  272.     case IDM_HELP_ABOUT:
  273.       {
  274.         CAboutBox dlgAboutBox;
  275.  
  276.         // Show the standard About Box dialog for this EXE by telling the
  277.         // dialog C++ object to show itself by invoking its ShowDialog
  278.         // method.  Pass it this EXE instance and the parent window handle.
  279.         // Use a dialog resource ID for the dialog template stored in
  280.         // this EXE module's resources.
  281.         dlgAboutBox.ShowDialog(
  282.           m_hInst,
  283.           MAKEINTRESOURCE(IDM_HELP_ABOUT),
  284.           m_hWnd);
  285.       }
  286.       break;
  287.  
  288.     default:
  289.       // Defer all messages NOT handled here to the Default Window Proc.
  290.       lResult = ::DefWindowProc(m_hWnd, WM_COMMAND, wParam, lParam);
  291.       break;
  292.   }
  293.  
  294.   return(lResult);
  295. }
  296.  
  297.  
  298. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  299.   Method:   CMainWindow::WindowProc
  300.  
  301.   Summary:  Main window procedure for this window object.  See CVirWindow
  302.             in the APPUTIL library (APPUTIL.CPP) for details on how this
  303.             method gets called by the global WindowProc.
  304.  
  305.   Args:     UINT uMsg,
  306.               Windows message that is "sent" to this window.
  307.             WPARAM wParam,
  308.               First message parameter (word sized).
  309.             LPARAM lParam)
  310.               Second message parameter (long sized).
  311.  
  312.   Modifies: ...
  313.  
  314.   Returns:  LRESULT
  315.               Standard Windows WindowProc return value.
  316. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  317. LRESULT CMainWindow::WindowProc(
  318.           UINT uMsg,
  319.           WPARAM wParam,
  320.           LPARAM lParam)
  321. {
  322.   LRESULT lResult = FALSE;
  323.  
  324.   switch (uMsg)
  325.   {
  326.     case WM_CREATE:
  327.       {
  328.         // Setup for painting text in this window.
  329.         HDC hdc = GetDC(m_hWnd);
  330.         ::GetTextMetrics(hdc, &m_tm);
  331.         ::ReleaseDC(m_hWnd, hdc);
  332.       }
  333.       break;
  334.  
  335.     case WM_MEASUREITEM:
  336.       // Get setup for painting text in this window.
  337.       {
  338.         LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT) lParam;
  339.         lpmis->itemHeight = m_tm.tmHeight + m_tm.tmExternalLeading;
  340.         lpmis->itemWidth = m_wWidth;
  341.         lResult = TRUE;
  342.       }
  343.  
  344.     case WM_SIZE:
  345.       // Handle a resize of this window.
  346.       m_wWidth = LOWORD(lParam);
  347.       m_wHeight = HIWORD(lParam);
  348.       break;
  349.  
  350.     case WM_COMMAND:
  351.       // Dispatch and handle any Menu command messages received.
  352.       lResult = DoMenu(wParam, lParam);
  353.       break;
  354.  
  355.     case WM_CLOSE:
  356.       // The user selected Close on the main window's System menu
  357.       // or Exit on the File menu.
  358.     case WM_QUIT:
  359.       // If the app is being quit then close any associated help windows.
  360.       // ::WinHelp(m_hWnd, m_szHelpFile, HELP_QUIT, 0);
  361.     default:
  362.       // Defer all messages NOT handled here to the Default Window Proc.
  363.       lResult = ::DefWindowProc(m_hWnd, uMsg, wParam, lParam);
  364.       break;
  365.   }
  366.  
  367.   return(lResult);
  368. }
  369.  
  370.  
  371. /*F+F++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  372.   Function: UnicodeOk
  373.  
  374.   Summary:  Checks if the platform will handle unicode versions of
  375.             Win32 string API calls.
  376.  
  377.   Args:     void
  378.  
  379.   Returns:  BOOL
  380.               TRUE if unicode support; FALSE if not.
  381. ------------------------------------------------------------------------F-F*/
  382. BOOL UnicodeOk(void)
  383. {
  384.   BOOL bOk = TRUE;
  385.   TCHAR szUserName[MAX_STRING_LENGTH];
  386.   DWORD dwSize = MAX_STRING_LENGTH;
  387.  
  388.   if (!GetUserName(szUserName, &dwSize))
  389.     bOk = ERROR_CALL_NOT_IMPLEMENTED == GetLastError() ? FALSE : TRUE;
  390.  
  391.   return bOk;
  392. }
  393.  
  394.  
  395. /*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  396.   Function: InitApplication
  397.  
  398.   Summary:  Initializes the application and registers its main window
  399.             class. InitApplication is called only once (in WinMain).
  400.  
  401.   Args:     HINSTANCE hInstance)
  402.               Handle to the first instance of the application.
  403.  
  404.   Returns:  BOOL.
  405.               TRUE if success.
  406.               FALSE if fail.
  407. F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
  408. BOOL InitApplication(
  409.        HINSTANCE hInstance)
  410. {
  411.   BOOL bOK;
  412.   // The window class for all instances of the main frame window.
  413.   WNDCLASSEX wcf;
  414.  
  415.   // Assign the appropriate values for this main frame window class.
  416.   wcf.cbSize        = sizeof(WNDCLASSEX);
  417.   wcf.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  418.   wcf.lpfnWndProc   = &WindowProc;             // Global Window Procedure for
  419.                                                //   all windows of this class.
  420.   wcf.cbClsExtra    = 0;                       // No per-class extra data.
  421.   wcf.cbWndExtra    = 0;                       // No per-window extra data.
  422.   wcf.hInstance     = hInstance;               // Owner of this class.
  423.   wcf.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);       // Default color.
  424.   wcf.lpszMenuName  = TEXT(MAIN_WINDOW_CLASS_MENU_STR); // Menu name from .RC.
  425.   wcf.lpszClassName = TEXT(MAIN_WINDOW_CLASS_NAME_STR); // Class name from .RC.
  426.   wcf.hCursor       = LoadCursor(NULL, IDC_ARROW);      // Cursor.
  427.   wcf.hIcon         = LoadIcon(                         // Icon name from .RC.
  428.                         hInstance,
  429.                         TEXT("AppIcon"));
  430.   wcf.hIconSm       = LoadImage(                        // Load small icon.
  431.                         hInstance,
  432.                         TEXT("AppIcon"),
  433.                         IMAGE_ICON,
  434.                         16, 16,
  435.                         0);
  436.  
  437.   // Register the window class and return FALSE if unsuccesful.
  438.   bOK = RegisterClassEx(&wcf);
  439.   if (!bOK)
  440.   {
  441.     // Assume we are running on NT where RegisterClassEx() is
  442.     // not implemented, so let's try calling RegisterClass().
  443.     bOK = RegisterClass((LPWNDCLASS)&wcf.style);
  444.   }
  445.  
  446.   return (bOK);
  447. }
  448.  
  449.  
  450. /*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
  451.   Function: WinMain
  452.  
  453.   Summary:  The Windows main entry point function for this application.
  454.             Initializes the application, the COM Libraries, and starts
  455.             the main application message loop.
  456.  
  457.   Args:     HINSTANCE hInstance,
  458.               Instance handle; a new one for each invocation of this app.
  459.             HINSTANCE hPrevInstance,
  460.               Instance handle of the previous instance. NULL in Win32.
  461.             LPSTR lpCmdLine,
  462.               Windows passes a pointer to the application's
  463.               invocation command line.
  464.             int nCmdShow)
  465.               Bits telling the show state of the application.
  466.  
  467.   Returns:  int
  468.               msg.wParam (upon exit of message loop).
  469.               FALSE if this instance couldn't initialize and run.
  470. F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
  471. extern "C" int PASCAL WinMain(
  472.                         HINSTANCE hInstance,
  473.                         HINSTANCE hPrevInstance,
  474.                         LPSTR lpCmdLine,
  475.                         int nCmdShow)
  476. {
  477.   CMainWindow* pWin;
  478.   MSG msg;
  479.   HACCEL hAccel;
  480.   int iRun = FALSE;
  481.  
  482.   // If we were compiled for UNICODE and the platform seems OK with this
  483.   // then proceed.  Else we error and exit the app.
  484.   if (UnicodeOk())
  485.   {
  486.     // Call to initialize the COM Library.  Use the SUCCEEDED macro
  487.     // to detect success.  If fail then exit app with error message.
  488.     if (SUCCEEDED(CoInitialize(NULL)))
  489.     {
  490.       // If we succeeded in initializing the COM Library we proceed to
  491.       // initialize the application.  If we can't init the application
  492.       // then we signal shut down with an error message exit.
  493.       iRun = InitApplication(hInstance);
  494.  
  495.       if (iRun)
  496.       {
  497.         // Assume we'll set iRun to TRUE when initialization is done.
  498.         iRun = FALSE;
  499.         // We are still go for running so we try to create a nifty new
  500.         // CMainWindow object for this app instance.
  501.         pWin = new CMainWindow;
  502.         if (NULL != pWin)
  503.         {
  504.           // Now we initialize an instance of the new CMainWindow.
  505.           // This includes creating the main window.  Note: if
  506.           // InitInstance fails then it would have already deleted
  507.           // pWin so we wouldn't need to delete it here.
  508.           if (pWin->InitInstance(hInstance, nCmdShow))
  509.           {
  510.             // Load the keyboard accelerators from the resources.
  511.             hAccel = LoadAccelerators(hInstance, TEXT("AppAccel"));
  512.             if (NULL != hAccel)
  513.             {
  514.               // Signal App Initialization is successfully done.
  515.               iRun = TRUE;
  516.             }
  517.             else
  518.             {
  519.               // If we couldn't load the accelerators then we delete the
  520.               // MessageBox object (made in Initinstance), delete the
  521.               // CMainWindow, and exit this failed instance of the
  522.               // application (relying on the default iRun = FALSE).
  523.               DELETE_POINTER(pWin->m_pMsgBox);
  524.               DELETE_POINTER(pWin);
  525.             }
  526.           }
  527.         }
  528.       }
  529.  
  530.       if (iRun)
  531.       {
  532.         // If we initialized the app instance properly then we are still
  533.         // go for running.  We then start up the main message pump for
  534.         // the application.
  535.         while (GetMessage(&msg, NULL, 0, 0))
  536.         {
  537.           if (!TranslateAccelerator(
  538.                  pWin->GetHwnd(),
  539.                  hAccel,
  540.                  &msg))
  541.           {
  542.             TranslateMessage(&msg);
  543.             DispatchMessage(&msg);
  544.           }
  545.         }
  546.  
  547.         // We'll pass to Windows the reason why we exited the message loop.
  548.         iRun = msg.wParam;
  549.       }
  550.       else
  551.       {
  552.         // We failed to initialize the application--issue an error
  553.         // messagebox.
  554.         TCHAR szMsg[MAX_STRING_LENGTH];
  555.  
  556.         // Load the error message string from the resources.
  557.         if (LoadString(
  558.               hInstance,
  559.               IDS_APPINITFAILED,
  560.               szMsg,
  561.               MAX_STRING_LENGTH))
  562.         {
  563.           // Put up error message box saying that application couldn't be
  564.           // initialized.  Parent window is desktop (ie, NULL).
  565.           MessageBox(
  566.             NULL,
  567.             szMsg,
  568.             TEXT(ERROR_TITLE_STR),
  569.             MB_OK | MB_ICONEXCLAMATION);
  570.         }
  571.         DELETE_POINTER(pWin);
  572.       }
  573.  
  574.       // We're exiting this app (either normally or by init failure) so
  575.       // shut down the COM Library.
  576.       CoUninitialize();
  577.     }
  578.     else
  579.     {
  580.       // We failed to Initialize the COM Library.
  581.       TCHAR szMsg[MAX_STRING_LENGTH];
  582.  
  583.       // Load the error message string from the resources.
  584.       if (LoadString(
  585.             hInstance,
  586.             IDS_COMINITFAILED,
  587.             szMsg,
  588.             MAX_STRING_LENGTH))
  589.       {
  590.         // Put up error message box saying that COM Library
  591.         // couldn't be initialized.  Parent window is desktop (ie, NULL).
  592.         // And exit the failed application.
  593.         MessageBox(
  594.           NULL,
  595.           szMsg,
  596.           TEXT(ERROR_TITLE_STR),
  597.           MB_OK | MB_ICONEXCLAMATION);
  598.       }
  599.     }
  600.   }
  601.   else
  602.   {
  603.     // If we were compiled for UNICODE but the platform has problems with
  604.     // this then indicate an error and exit the app immediately.
  605.     CHAR szMsg[MAX_STRING_LENGTH];
  606.  
  607.     if (LoadStringA(
  608.           hInstance,
  609.           IDS_UNICODEFAIL,
  610.           szMsg,
  611.           MAX_STRING_LENGTH))
  612.     {
  613.       MessageBoxA(
  614.         NULL,
  615.         szMsg,
  616.         ERROR_TITLE_STR,
  617.         MB_OK | MB_ICONEXCLAMATION);
  618.     }
  619.   }
  620.  
  621.   return iRun;
  622. }
  623.