⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runreg.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
// Get needed include files
#include "StdInc.h"
#include "ATLBase.h"
#include "StatReg.h"
#include "StatReg.cpp"
#include "ATLImpl.cpp"
#include "Utility.h"


void ShowUsage()
{
   std::cout << "\nRUNREG.EXE - Executes an ATL registry script\n";
   std::cout << "Usage: runreg.exe [-s] <Register | Unregister> <Script>\n\n";
   std::cout << "  -s          Run silently (no screen output)\n";
   std::cout << "  Register    Execute the script in registration mode.\n";
   std::cout << "  Unregister  Execute the script in unregistration mode.\n";
   std::cout << "  <Script>    ATL registry script. Filename can be in UNC.\n\n";
   std::cout << "From \"Insert Title Here\" by Chris Corry\n";
   std::cout << "Copyright 1997 Que Corporation\n";
}


INT main(INT iArgc, PCHAR pArgv[])
{
   HRESULT          hResult;
   bool             boolSilentMode = false;
   bool             boolRegister = true;
   bool             boolRegTypeFound = false;
   PCHAR            pszRegFilename = NULL;

   // We use a few ATL string conversion macros
   USES_CONVERSION;

   // Are their any command-line arguments?
   if (iArgc < 3 || iArgc > 4) {
      ShowUsage();
      return S_FALSE;
   }

   // Process our arguments
   for (INT iLoop = 1; iLoop < iArgc; iLoop++) {

      // Blast the argument into uppercase
      _strupr(pArgv[iLoop]);

      // Silent mode?
      if (!strcmp(pArgv[iLoop], "-S") || !strcmp(pArgv[iLoop], "/S"))
         boolSilentMode = true;

      // Register?
      else if (!strcmp(pArgv[iLoop], "REGISTER")) {
         if (boolRegTypeFound) {
            ShowUsage();
            return S_FALSE;
         }
         boolRegTypeFound = true;
      }

      // Unregister?
      else if (!strcmp(pArgv[iLoop], "UNREGISTER")) {
         if (boolRegTypeFound) {
            ShowUsage();
            return S_FALSE;
         }
         boolRegTypeFound = true;
         boolRegister = false;
      }

      // Assume script filename
      else if (!pszRegFilename)
         pszRegFilename = pArgv[iLoop];

      // Bad args
      else {
         ShowUsage();
         return S_FALSE;
      }
   }

   // Did the user specify REGISTER or UNREGISTER?
   if (!boolRegTypeFound) {
      ShowUsage();
      return S_FALSE;
   }

   // Let the user know what's going on
   if (!boolSilentMode) {
      std::cout << "\nRUNREG.EXE - Executes an ATL registry script\n";
      std::cout << "From \"Insert Title Here\" by Chris Corry\n";
      std::cout << "Copyright 1997 Que Corporation\n\n";
      std::cout << (boolRegister ? "Registering " : "Unregistering ");
      std::cout << "script \"" << pszRegFilename << "\"... " << std::flush;
   }

   // Create our ATL Registrar object and register the script
   CRegObject  Registrar;
   hResult = (boolRegister ? Registrar.FileRegister(A2OLE(pszRegFilename))
                           : Registrar.FileUnregister(A2OLE(pszRegFilename)));

   // What happened?
   if (FAILED(hResult)) {
      if (!boolSilentMode) {
         std::cout << "FAILED!\n\n";

         // Try and give some hint as to what went wrong
         switch(hResult)
         {
            // Is this a bad filename?
            case E_INVALIDARG:
               ReportError("Invalid script filename.", hResult);
               break;

            // Was the file not found?
            case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND):
               ReportError("The script file could not be found.", hResult);
               break;

            // Is someone else using this script?
            case HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION):
               ReportError("The script file is in use by another process "
                           "(perhaps an editor\n        or word-processor?).",
                           hResult);
               break;

            // Was there an exception thrown?
            case DISP_E_EXCEPTION:
               ReportError("Exception thrown. Probably a script syntax error.",
                           hResult);
               break;

            default:
               // Generic error
               ReportError("Could not register/unregister script.", hResult);
         }
      }
   }

   // Everything went fine
   else {
      if (!boolSilentMode)
         std::cout << "Complete.\n\n";
   }

   return hResult;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -