queryint.cpp

来自「VC++串口通信设。本书详细说明讲解了在VC++环境下编写串口通信得过程。值得一」· C++ 代码 · 共 40 行

CPP
40
字号
//... IUnknown interface pointer is in variable pIUnknown ...

HRESULT hResult = E_FAIL;
IChihuahua *pIChihuahua = NULL;

// Query the component抯 IChihuahua interface
hResult = pIUnknown->QueryInterface(IID_IChihuahua,
                                    (void**) &pIChihuahua);

// Were we successful?
if (FAILED(hResult)) 
{

   // Determine what went wrong
   switch (hResult) 
   {

      // Does the component even support this interface?
      case E_NOINTERFACE:
         cout << "Component does not expose IChihuahua.\n";
         break;

      // Has COM been initialized for this thread
      case CO_E_NOTINITIALIZED:
         cout << "COM not initialized.\n";
         break;

      // Has the component run out of memory?
      case E_OUTOFMEMORY:
         cout << "Out of memory!\n";
         break;

      // Some other error
      default:
         cout << "Unrecognized error.\n";
   }

   return hResult;
}

⌨️ 快捷键说明

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