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

📄 dllserv.cpp

📁 VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一看
💻 CPP
字号:
// Get needed compiler include files
#include <iostream>
using namespace std;
// Get needed system and custom include files
#include "Utility.h"
#include "Counts.h"
#include "Factory2.h"


//
// Function exported from in-process server DLL that is called by COM to
// obtain an interface pointer to a particular class factory.
//

STDAPI DllGetClassObject(REFCLSID rClsId,
                         REFIID rIID,
                         PPVOID ppvInterface)
{
   HRESULT                  hResult;
   PComFortuneTellerFactory pFactory;

   VerboseMsg("In DllGetClassObject\n");

   // Make sure we're not being asked for a class factory that we don't know about
   if (rClsId != CLSID_FortuneTeller2) {
      VerboseMsg("   COM is requesting a class other than CLSID_FortuneTeller2\n");
      return E_FAIL;
   }

   // Instantiate the new class factory
   VerboseMsg("   Creating new ComFortuneTellerFactory object\n");
   pFactory = new ComFortuneTellerFactory;

   // Out of memory?
   if (!pFactory) {
      VerboseMsg("   ComFortuneTellerFactory object creation failed.\n");
      return E_OUTOFMEMORY;
   }

   // Now obtain the requested interface
   hResult = pFactory->QueryInterface(rIID, ppvInterface);

   // Destroy the factory if the desired interface couldn't be obtained
   if (FAILED(hResult)) {
      delete pFactory;
      return hResult;
   }

   return NOERROR;
}


//
// Function exported from in-process server DLL that is called by COM to
// determine if the server can be unloaded from memory.
//

STDAPI DllCanUnloadNow()
{
   string strTemp;
   VerboseMsg("In DllGetClassObject\n");

   // Be verbose -- let people know what's going on
   strTemp = "   Server Lock Count:   ";
   strTemp += ULongToStr(Counters::GetLockCount());
   strTemp += "\n";
   VerboseMsg(strTemp);
   strTemp = "   Server Object Count:   ";
   strTemp += ULongToStr(Counters::GetObjectCount());
   strTemp += "\n";
   VerboseMsg(strTemp);

   // If the server lock count and the object count are both zero, then
   // the server can be unloaded
   return ((Counters::GetLockCount() == 0L &&
            Counters::GetObjectCount() == 0L) ? S_OK : S_FALSE);
}

⌨️ 快捷键说明

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