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

📄 localsrv.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
// Get needed includes
#include "RegDlg.h"
#include "Resource.h"
#include "CommLine.h"


//
// Main application/server class
//

class CLocalServerApp : public CWinApp
{
public:

   // Public methods inherited from CWinApp
   virtual BOOL InitInstance();

   // New public methods
   VOID RegisterComponent  (const CString& strProgID,
                            BOOL  boolShowConfirmation = TRUE);
   VOID UnregisterComponent(const CString& strClassID,
                            const CString& strProgID,
                            BOOL  boolShowConfirmation = TRUE);
};

// Our one-and-only application object
CLocalServerApp TheApp;


//
// The entire program is run out of this method
//

BOOL CLocalServerApp::InitInstance()
{
   // Initialize OLE libraries
   if (!AfxOleInit()) {
	   AfxMessageBox("Could not initialize OLE subsystem.");
	   return FALSE;
   }

   // Parse command line for standard OLE commands
   CSrvCommandLineInfo CmdInfo;
   ParseCommandLine(CmdInfo);

   // Check to see if launched as OLE server
   if (CmdInfo.m_bRunEmbedded || CmdInfo.m_bRunAutomated)
   {
      // Application was run with /Embedding or /Automation.

      // Register all OLE server (factories) as running.  This enables the
      //  OLE libraries to create objects from other applications.
      COleObjectFactory::RegisterAll();
      return TRUE;
   }

   // Load up various strings
   CString strClassID, strProgID;
   strClassID.LoadString(IDS_CLASSID);
   strProgID.LoadString(IDS_PROGID);

   // Did the user request registration on the command-line?
   if (CmdInfo.m_bRegister) {
      RegisterComponent(strProgID, FALSE);
      return FALSE;
   }

   // Did the user request unregistration on the command-line?
   if (CmdInfo.m_bUnregister) {
      UnregisterComponent(strClassID, strProgID, FALSE);
      return FALSE;
   }

   // Ask the user if they want to register or unregister the server
   CRegisterDialog   dlgRegister(strProgID);

   switch(dlgRegister.DoModal())
   {
      case ID_REGISTER:
         RegisterComponent(strProgID);
         break;

      case ID_UNREGISTER:
         UnregisterComponent(strClassID, strProgID);
         break;
   }

   return FALSE;
}


VOID CLocalServerApp::RegisterComponent(const CString& strProgID,
                                        BOOL  boolShowConfirmation)
{
   // Place the server into the system registry
   COleObjectFactory::UpdateRegistryAll();

   // Are we operating silently?
   if (!boolShowConfirmation)
      return;

   // Let the user know that registration is complete
   CString strMsg = "The ";
   strMsg += strProgID;
   strMsg += " server has been registered.";
   AfxMessageBox(strMsg, MB_ICONINFORMATION);
}


VOID CLocalServerApp::UnregisterComponent(const CString& strClassID,
                                          const CString& strProgID,
                                          BOOL  boolShowConfirmation)
{
   // Transform the string-format CLASSID into a real CLSID
   CLSID CLSID_Component;
   BSTR bstrClassID = strClassID.AllocSysString();
   CLSIDFromString(bstrClassID, &CLSID_Component);
   SysFreeString(bstrClassID);

   // Unregister the class
   AfxOleUnregisterClass(CLSID_Component, strProgID);

   // Are we operating silently?
   if (!boolShowConfirmation)
      return;

   // Let the user know that unregistration is complete
   CString strMsg = "The ";
   strMsg += strProgID;
   strMsg += " server has been unregistered.";
   AfxMessageBox(strMsg, MB_ICONINFORMATION);
}

⌨️ 快捷键说明

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