程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> .NET實例教程 >> COM宏小結

COM宏小結

編輯:.NET實例教程

//========================================================================
//TITLE:
//    COM宏小結
//AUTHOR:
//    norains
//DATE:
//    Wednesday  24-October-2007
//Environment:
//        EVC4.0 + Windows CE 5.0 Standard SDK
//========================================================================
    COM接口用到的宏主要有六個:STDMETHOD,STDMETHODIMP,STDMETHOD_,STDMETHODIMP_,SUCCEEDED,FAILED.
   
    我們首先來看看這六個宏的定義:
   
    STDMETHOD:
  #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method
  #ifdef _WIN32 // Win32 doesn't support __export
  #define STDMETHODCALLTYPE __stdcall
  #else
  #define STDMETHODCALLTYPE __export __stdcall
  #endif

  STDMETHODIMP:
  #define STDMETHODIMP HRESULT STDMETHODCALLTYPE
  #ifdef _WIN32 // Win32 doesn't support __export
  #define STDMETHODCALLTYPE __stdcall
  #else
  #define STDMETHODCALLTYPE __export __stdcall
  #endif

  STDMETHOD_:
  #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
  #ifdef _WIN32 // Win32 doesn't support __export
  #define STDMETHODCALLTYPE __stdcall
  #else
  #define STDMETHODCALLTYPE __export __stdcall
  #endif

  STDMETHODIMP_:
  #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
  #ifdef _WIN32 // Win32 doesn't support __export
  #define STDMETHODCALLTYPE __stdcall
  #else
  #define STDMETHODCALLTYPE __export __stdcall
  #endif

  SUCCEEDED:
  #define SUCCEEDED(Status) ((HRESULT)(Status) >= 0)

  FAILED:
  #define FAILED(Status) ((HRESULT)(Status)<0)


    由定義我們可以看出兩點:
   
    1)STDMETHOD和STDMETHODIMP,STDMETHOD_和STDMETHODIMP_分別為一對,SUCCEEDED和FAILED為相反.
   
    2)STDMETHOD只是STDMETHOD_的簡化版.
      比如這兩個語句互為等價關系:
      STDMETHOD (QueryInterface) (REFIID riid, LPVOID * ppv);
      STDMETHOD_ (HRESULT,

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved