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

📄 chapter3_client.cpp

📁 ATL开发指南PDF格式
💻 CPP
字号:
//
// Chapter3_Client.cpp
//

#include <windows.h>
#include <tchar.h>
#include <iostream.h>

#include <initguid.h>

#include "..\Chapter3_Server\Chapter3_Server_i.c"
#include "..\Chapter3_Server\Chapter3_Server.h"

int main( int argc, char *argv[] )
{
   cout << "Initializing COM" << endl;

   if ( FAILED( CoInitialize( NULL )))
   {
      cout << "Unable to initialize COM" << endl;
      return -1;
   }

   // Use CoCreateInstance
   IMath* pMath;
   HRESULT hr = CoCreateInstance( CLSID_Math,
                                  NULL,
                                  CLSCTX_INPROC,
                                  IID_IMath,
                                  (void**) &pMath );
   if ( FAILED( hr ))
   {
      cout.setf( ios::hex, ios::basefield );
      cout << "Failed to create server instance. HR = " << hr << endl;
      return -1;
   }

   cout << "Instance created" << endl;

   long result;
   pMath->Multiply( 100, 8, &result );
   cout << "100 * 8 is " << result << endl;

   pMath->Subtract( 1000, 333, &result );
   cout << "1000 - 333 is " << result << endl;

   // Try IAdvancedMath, QI through IMath
   IAdvancedMath* pAdvMath = NULL;
   hr = pMath->QueryInterface( IID_IAdvancedMath, (LPVOID*)&pAdvMath );
   if ( FAILED( hr ))
   {
      cout << "QueryInterface() for IAdvancedMath failed" << endl;
      pMath->Release();
      CoUninitialize();
      return -1;
   }

   pAdvMath->Factorial( 10, &result );
   cout << "10! is " << result << endl;

   pAdvMath->Fibonacci( 10, &result );
   cout << "The Fibonacci of 10 is " << result << endl;

   cout << "Releasing IMath interface" << endl;
   pMath->Release();

   cout << "Releasing IAdvancedMath interface" << endl;
   pAdvMath->Release();

   cout << "Shuting down COM" << endl;
   CoUninitialize();

   return 0;
}

⌨️ 快捷键说明

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