home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / sshwbemhelpers.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  20.2 KB  |  772 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////
  2. //  SshWbemHelpers.h                                                                      //
  3. //                                                                                        //
  4. //  The follwing classes are defined:                                                     //
  5. //                                                                                        //
  6. //       CWbemServices - threadsafe wrapper class for IWbemServices                       //
  7. //       CWbemClassObject - wrapper class for IWbemClassObject                            //
  8. //       CWbemException - wrapper for IErrorInfo, assists with WBEM error reporting       //
  9. //                                                                                        //
  10. //  These classes provide a convenient way to use the three most common WBEM interfaces:  //
  11. //  IWbemLocator, IWbemServices, and IWbemClassObject. The also make it easy to           //
  12. //  the WBEM __ExtendedStatus error object and interpret the HRESULT. The use of these    //
  13. //  classes along with the smart pointers and the COM helper classes _bstr_t and          //
  14. //  _variant_t can greatly reduce the chances of memory leaks in your code.               //
  15. //                                                                                        //
  16. //  See T_SafeVector.h for help with safe arrays and arrays of embedded objects.          //
  17. //                                                                                        //
  18. //  Copyright (c)1997-99 Microsoft Corporation, All Rights Reserved                       //
  19. ////////////////////////////////////////////////////////////////////////////////////////////
  20.  
  21.  
  22. #if !defined(__SdkWbemHelpers_H)
  23. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  24. #define      __SdkWbemHelpers_H
  25. #pragma once
  26.  
  27. #pragma warning( disable : 4290) // C++ Exception Specification Ignored
  28.  
  29. #include <wbemidl.h>
  30.  
  31.  
  32. class CWbemClassObject;
  33. class CWbemServices;
  34.  
  35. //---------------------------------------------------------------------------------------
  36. //
  37. // Smart pointers for the WBEM interfaces. The _COM_SMARTPTR_TYPEDEF creates smart pointer types
  38. // named XXXPtr where XXX is the interface pointer, these types are actually classes derived from
  39. // the COM helper class _com_ptr_t. Use these types just as you would the interface pointer, only
  40. // AddRef and Release are called for you at the appropriate times.
  41. // 
  42.  
  43. _COM_SMARTPTR_TYPEDEF(IUnsecuredApartment,          IID_IUnsecuredApartment);  // IUnsecuredApartmentPtr
  44. _COM_SMARTPTR_TYPEDEF(IWbemObjectSink,              IID_IWbemObjectSink);      // IWbemObjectSinkPtr
  45. _COM_SMARTPTR_TYPEDEF(IWbemClassObject,             IID_IWbemClassObject);     // IWbemClassObjectPtr
  46. _COM_SMARTPTR_TYPEDEF(IWbemServices,                IID_IWbemServices);        // IWbemServicesPtr
  47. _COM_SMARTPTR_TYPEDEF(IWbemContext,                 IID_IWbemContext );        // IWbemContextPtr
  48. _COM_SMARTPTR_TYPEDEF(IWbemCallResult,              IID_IWbemCallResult);      // IWbemCallResultPtr
  49. _COM_SMARTPTR_TYPEDEF(IWbemQualifierSet,            IID_IWbemQualifierSet);    // IWbemQualifierSetPtr
  50. _COM_SMARTPTR_TYPEDEF(IWbemLocator,                 IID_IWbemLocator);         // IWbemLocatorPtr
  51. _COM_SMARTPTR_TYPEDEF(IWbemObjectAccess,            IID_IWbemObjectAccess);    // IWbemObjectAccessPtr
  52. _COM_SMARTPTR_TYPEDEF(IEnumWbemClassObject,         IID_IEnumWbemClassObject); // IEnumWbemClassObjectPtr
  53.  
  54.  
  55. //---------------------------------------------------------------------------------------
  56. // CWbemException
  57. //
  58. //  This class assists with WBEM error handling and the WBEM __ExtendedStatus error object
  59. // 
  60. //  Create an instance of this class immediately after a WBEM call failure, and pass
  61. //  in to the constructor the HRESULT from the failed COM call and a descriptive message.
  62. //
  63. //  Call the GetWbemError() method to retrieve the __ExtendedStatus object.
  64. // 
  65. //  This object inherits from _com_error, see _com_error documentation for information on
  66. //  how to access the encapsulated IErrorInfo interface.
  67. //
  68.  
  69. class CWbemException : public _com_error
  70. {
  71. private:
  72.     CWbemClassObject *  m_pWbemError;
  73.     HRESULT             m_hr;
  74.     _bstr_t             m_sDescription;
  75.     
  76.     static IErrorInfo * GetErrorObject();
  77.     static IErrorInfo * MakeErrorObject(_bstr_t);
  78.     void GetWbemStatusObject();
  79.     
  80. public:
  81.     // use this constructor to capture the WBEM error object
  82.     // pass in the HRESULT from the failed COM call and a descriptive message
  83.     CWbemException(HRESULT hr,_bstr_t sMessage);
  84.     
  85.     // use this constructor to create a generic error, does not return WBEM error
  86.     CWbemException(_bstr_t sMessage);
  87.     
  88.     // returns the WBEM __ExtendedStatus object if one exists
  89.     CWbemClassObject GetWbemError();
  90.     
  91.     // returns the description passed to the constructor
  92.     _bstr_t GetDescription() { return m_sDescription;  }
  93.     
  94.     // returns the HRESULT passed to the constructor, WBEM_E_FAILED if none passed
  95.     HRESULT GetErrorCode()   { return m_hr;            }
  96.     
  97.     // returns the string representation of the error code for the supplied HRESULT
  98.     static _bstr_t GetWbemErrorText(HRESULT hr);
  99. };
  100.  
  101.  
  102.  
  103.  
  104.  
  105. //-----------------------------------------------------------------------------------
  106. // CWbemClassObject
  107. //
  108. //  This class encapsulates a WBEM object, it transparently handles AddRef and Release.
  109. //  It also provides access to the objects methods.
  110. //
  111. //  Assigning an instance of this object or passing it by value does not copy the 
  112. //  object, only the pointer. Use Clone to make a new object. Use one of the casting
  113. //  operators to extract the underlying pointer.
  114. //
  115. //  See IWbemClassObject for more information on the WBEM methods.
  116. //
  117.  
  118. class CWbemClassObject
  119. {
  120. private:
  121.     IWbemClassObjectPtr     m_pWbemObject;
  122.  
  123.     // global object count for WBEM objects encapsulated by this class
  124.     // helpful for debugging
  125.     static DWORD s_dwObjectCount;
  126.     
  127. public:
  128.  
  129.     // these constructors will addref the pointer
  130.     CWbemClassObject(const CWbemClassObject&  _in);
  131.     CWbemClassObject(IWbemClassObject * const _in);
  132.     CWbemClassObject(IWbemClassObjectPtr& _in);
  133.     CWbemClassObject(IUnknown * _in);
  134.     CWbemClassObject(IUnknownPtr& _in);
  135.  
  136.     CWbemClassObject();
  137.     ~CWbemClassObject();
  138.     
  139.     void Attach(IWbemClassObject * pWbemObject)
  140.     {
  141.         m_pWbemObject.Attach(pWbemObject);
  142.     }
  143.     
  144.     void Attach(IWbemClassObject * pWbemObject,bool bAddRef)
  145.     {
  146.         m_pWbemObject.Attach(pWbemObject,bAddRef);
  147.     }
  148.     
  149.     // this operator allows you to use the object as a pointer to 
  150.     // call other IWbemClassObject methods without casting
  151.     IWbemClassObject * operator->()
  152.     {
  153.         return m_pWbemObject;
  154.     }
  155.     
  156.     unsigned long GetObjectSize();
  157.     
  158.     // Retrives the MOF description
  159.     _bstr_t GetObjectText()
  160.     {
  161.         _bstr_t bRet;
  162.         
  163.         BSTR bstr;
  164.         
  165.         if( !FAILED(m_pWbemObject->GetObjectText(0,&bstr)) )
  166.         {
  167.             bRet = _bstr_t(bstr,false);
  168.         }
  169.         
  170.         return bRet;
  171.     }
  172.     
  173.     IWbemClassObject * Detach()
  174.     {
  175.         return m_pWbemObject.Detach();
  176.     }
  177.     
  178.     // various casting operators
  179.  
  180.     operator IWbemClassObject*()
  181.     {
  182.         return m_pWbemObject;
  183.     }
  184.     
  185.     operator IWbemClassObject**()
  186.     {
  187.         return &m_pWbemObject;
  188.     }
  189.     
  190.     operator IWbemClassObjectPtr()
  191.     {
  192.         return m_pWbemObject;
  193.     }
  194.     
  195.     
  196.     operator IUnknown *()
  197.     {
  198.         return (IUnknown *)(IWbemClassObject *)m_pWbemObject;
  199.     }
  200.     
  201.     
  202.     // address of operator
  203.     IWbemClassObject ** operator &()
  204.     {
  205.         return &m_pWbemObject;
  206.     }
  207.     
  208.     // these operators allow you to check if the underlying pointer is NULL in an if statement
  209.     // just like a regular pointer
  210.     bool operator !() 
  211.     {
  212.         return m_pWbemObject == NULL;
  213.     }
  214.     
  215.     operator bool() 
  216.     {
  217.         return m_pWbemObject != NULL;
  218.     }
  219.  
  220.     bool IsNull() const 
  221.     { 
  222.         return m_pWbemObject == NULL;
  223.     }
  224.  
  225.     
  226.     // AddRef and Release
  227.     ULONG AddRef()
  228.     {
  229.         return m_pWbemObject->AddRef();
  230.     }
  231.     
  232.     ULONG Release()
  233.     {
  234.         return m_pWbemObject->Release();
  235.     }
  236.     
  237.     // assignment operators
  238.     IWbemClassObject* operator=(IWbemClassObject* _p)
  239.     {
  240.         m_pWbemObject = _p;
  241.         return m_pWbemObject;
  242.     }
  243.     
  244.     IWbemClassObjectPtr operator=(IWbemClassObjectPtr& _p)
  245.     {
  246.         m_pWbemObject = _p;
  247.         return m_pWbemObject;
  248.     }
  249.     
  250.     
  251.     IWbemClassObject* operator=(IUnknown * _p)
  252.     {
  253.         m_pWbemObject = _p;
  254.         return m_pWbemObject;
  255.     }
  256.     
  257.     IWbemClassObjectPtr operator=(IUnknownPtr& _p)
  258.     {
  259.         m_pWbemObject = _p;
  260.         return m_pWbemObject;
  261.     }
  262.     
  263.     
  264.     IWbemClassObject* operator=(const CWbemClassObject& _p)
  265.     {
  266.         m_pWbemObject = _p.m_pWbemObject;
  267.         return m_pWbemObject;
  268.     }
  269.     
  270.     // make a copy of the object
  271.     HRESULT Clone(CWbemClassObject& _newObject)
  272.     {
  273.         return m_pWbemObject->Clone(_newObject);
  274.     }
  275.     
  276.     // spawn a new blank instance of the object
  277.     CWbemClassObject SpawnInstance()
  278.     {
  279.         CWbemClassObject coRet;
  280.         
  281.         m_pWbemObject->SpawnInstance(0,coRet);
  282.         
  283.         return coRet; 
  284.     }
  285.     
  286.     // get a method signatures for a class 
  287.     HRESULT GetMethod(const IN _bstr_t& _name, CWbemClassObject& coInSignature,
  288.         CWbemClassObject& coOutSignature, long _lFlags = 0)
  289.     {
  290.         return m_pWbemObject->GetMethod(_name, _lFlags, coInSignature, coOutSignature);
  291.     }
  292.     
  293.     // this operator is defined so that the object can be stored in ordered lists
  294.     // or other structures
  295.     bool operator<(const CWbemClassObject& _comp)
  296.     {
  297.         return m_pWbemObject < _comp.m_pWbemObject;
  298.     }
  299.     
  300.     /***** Get and Put property access methods */
  301.  
  302.     //*** put overloads ***
  303.     HRESULT Put(const _bstr_t& _Name,_variant_t _value,CIMTYPE vType = 0)
  304.     {
  305.         return m_pWbemObject->Put(_Name,0,&_value,vType);
  306.     }
  307.     
  308.     HRESULT Put(const _bstr_t& _Name,const _bstr_t& _value,CIMTYPE vType = 0)
  309.     {
  310.         return m_pWbemObject->Put(_Name,0,&_variant_t(_value),vType);
  311.     }
  312.     
  313.     HRESULT Put(const _bstr_t& _Name, const long _value, CIMTYPE vType = 0)
  314.     {
  315.         return m_pWbemObject->Put(_Name,0,&_variant_t(_value), vType);
  316.     }
  317.     
  318.     HRESULT Put(const _bstr_t& _Name, const bool _value,CIMTYPE vType = 0)
  319.     {
  320.         return m_pWbemObject->Put(_Name,0,&_variant_t(_value),vType);
  321.     }
  322.     
  323.     //*** get overloads ***
  324.     HRESULT Get(const _bstr_t& _Name, _bstr_t& _value)
  325.     {
  326.         _variant_t v1;
  327.         HRESULT hr = m_pWbemObject->Get (_Name, 0, &v1, NULL, NULL);
  328.         _value = v1;
  329.         return hr;
  330.     }
  331.     
  332.     HRESULT Get(const _bstr_t& _Name, long& _value)
  333.     {
  334.         _variant_t v1;
  335.         HRESULT hr = m_pWbemObject->Get (_Name, 0, &v1, NULL, NULL);
  336.         _value = v1;
  337.         return hr;
  338.         
  339.     }
  340.     
  341.     HRESULT Get(const _bstr_t& _Name, bool& _value)
  342.     {
  343.         _variant_t v1;
  344.         HRESULT hr = m_pWbemObject->Get (_Name, 0, &v1, NULL, NULL);
  345.         _value = v1;
  346.         return hr;
  347.     }
  348.     
  349.     HRESULT Get(const _bstr_t& _Name,_variant_t& _value)
  350.     {
  351.         _value.Clear();
  352.         return m_pWbemObject->Get (_Name, 0, &_value, NULL, NULL);
  353.     }
  354.     
  355.     
  356.     _variant_t Get(const _bstr_t& _Name,CIMTYPE& vType,long& lFlavor)
  357.     {
  358.         _variant_t vRet;
  359.         
  360.         m_pWbemObject->Get (_Name, 0, &vRet, &vType, &lFlavor);
  361.         
  362.         return vRet;
  363.     }
  364.     
  365.     
  366.     _bstr_t GetString   (const _bstr_t& _Name);
  367.     _int64  GetI64      (const _bstr_t& _Name);
  368.     long    GetLong     (const _bstr_t& _Name);
  369.     bool    GetBool     (const _bstr_t& _Name);
  370.     _bstr_t GetCIMTYPE  (const _bstr_t& _Name);
  371.     
  372.     // retrieves a WBEM object embedded in a property
  373.     CWbemClassObject GetEmbeddedObject(const _bstr_t& _Name);
  374.     
  375.     
  376.     // use these for property enumeration
  377.     HRESULT BeginEnumeration(long _lFlags = WBEM_FLAG_LOCAL_ONLY)
  378.     {
  379.         return m_pWbemObject->BeginEnumeration(_lFlags);
  380.     }
  381.     
  382.     
  383.     HRESULT Next(_bstr_t& _sName,_variant_t& _value)
  384.     {
  385.         HRESULT     hr;
  386.         BSTR        bstr = NULL;
  387.         
  388.         hr = m_pWbemObject->Next(0,&bstr,&_value,NULL,NULL);
  389.         
  390.         if(hr == S_OK)
  391.         {
  392.             _sName = _bstr_t(bstr,false);
  393.         }
  394.         
  395.         return hr;
  396.     }
  397.     
  398.     HRESULT Next(_bstr_t& _sName,_variant_t& _value,CIMTYPE& _vartype)
  399.     {
  400.         HRESULT     hr;
  401.         BSTR        bstr = NULL;
  402.         
  403.         _value.Clear();
  404.         hr = m_pWbemObject->Next(0,&bstr,&_value,&_vartype,NULL);
  405.         
  406.         if(hr == S_OK)
  407.         {
  408.             _sName = _bstr_t(bstr,false);
  409.         }
  410.         
  411.         return hr;
  412.     }
  413.     
  414.     HRESULT Next(_bstr_t& _sName,_variant_t& _value,CIMTYPE& _vartype,long& _flavor)
  415.     {
  416.         HRESULT     hr;
  417.         BSTR        bstr = NULL;
  418.         
  419.         _value.Clear();
  420.         hr = m_pWbemObject->Next(0,&bstr,&_value,&_vartype,&_flavor);
  421.         
  422.         if(hr == S_OK)
  423.         {
  424.             _sName = _bstr_t(bstr,false);
  425.         }
  426.         
  427.         return hr;
  428.     }
  429.     
  430.     HRESULT EndEnumeration()
  431.     {
  432.         return m_pWbemObject->EndEnumeration();
  433.     }
  434.     
  435. };
  436.  
  437.  
  438. // these operators are needed for storage in some data structures
  439. __inline bool operator<(const CWbemClassObject& _X, const CWbemClassObject& _Y) 
  440. {
  441.     return _X < _Y;
  442. }
  443.  
  444. __inline bool operator==(const CWbemClassObject& _X, const CWbemClassObject& _Y)
  445. {
  446.     return _X == _Y;
  447. }
  448.  
  449.  
  450.  
  451. //-----------------------------------------------------------------------------
  452. // CWbemServices
  453. //
  454. //  Provides thread safe encapsulation of the IWbemServices interface and provides
  455. //  access to it's methods. See the IWbemServices documentation for information 
  456. //  about the methods.
  457. //
  458. //  This clas also encapsulates IWbemLocator::ConnectServer(). When using this call, 
  459. //     provide the address of a NULL IWbemServices pointer to act as a cache. This class
  460. //  actually stores the interface pointer in an IStream. A real interface needs
  461. //  to be kept somewhere or DCOM will garbage collect the object. When the instance
  462. //  of this class is deleted, the cached pointer still needs to be released. Use a
  463. //  smart pointer (IWbemServicesPtr) and keep it in the same scope as the 
  464. //  CWbemServices instance.
  465. //
  466.  
  467. class CWbemServices 
  468. {
  469. private:
  470.     IWbemContextPtr     m_pCtx;
  471.     IStream *           m_pServicesStream; // encapsulated IWbemServices pointer
  472.     IUnknownPtr         m_pUnkCache;
  473.     CRITICAL_SECTION    m_cs;
  474.     
  475.     bool GetInterfacePtr(IWbemServicesPtr & pServices,bool bThrowException = true);
  476.     void CommonInit(IWbemServicesPtr& pServ);
  477.     
  478. public:
  479.     // constructors will AddRef the pointer
  480.     CWbemServices(IWbemContext * _pContext = NULL);
  481.     CWbemServices(const CWbemServices& _p);
  482.     CWbemServices(const IWbemServicesPtr& _in);
  483.     CWbemServices(const IUnknownPtr& _in);
  484.     CWbemServices(IUnknown * _in);
  485.     CWbemServices(IWbemServices *_in,IWbemContext * _pContext = NULL);
  486.     ~CWbemServices();
  487.     
  488.     CWbemServices& operator=(IUnknown * _p);
  489.     CWbemServices& operator=(IUnknownPtr& _p);
  490.     CWbemServices& operator=(IWbemServices *_p);
  491.     CWbemServices& operator=(const CWbemServices& _p);
  492.     
  493.     // when logging in, capture the IWbemServices pointer and keep it somewhere
  494.     // this pointer is stored internaly in an IStream and DCOM will garbage collect the object if
  495.     // there isn't at least one reference to it
  496.  
  497.     // Login with integrated security
  498.     void ConnectServer(_bstr_t sNetworkResource, IWbemServices **_WbemServicesCache) throw(CWbemException);
  499.     
  500.     // Login as a specific user
  501.     void ConnectServer
  502.         (
  503.         _bstr_t sNetworkResource,
  504.         _bstr_t sUser,
  505.         _bstr_t sPassword,
  506.         IWbemServices **_WbemServicesCache,
  507.         long    lSecurityFlags = 0
  508.         ) throw(CWbemException);
  509.     
  510.     
  511.     // create an instance a of a class given the class name
  512.     // encapsulates GetObject and SpawnInstance
  513.     CWbemClassObject CreateInstance
  514.         (
  515.         _bstr_t             _sClassName,
  516.         IWbemCallResultPtr& _cr
  517.         )
  518.     {
  519.         CWbemClassObject coClassDef = GetObject(_sClassName,_cr);
  520.         CWbemClassObject coRet;
  521.         
  522.         if(!coClassDef.IsNull())
  523.         {
  524.             coRet = coClassDef.SpawnInstance();
  525.         }
  526.         
  527.         return coRet;
  528.     }
  529.     
  530.     CWbemClassObject CreateInstance(_bstr_t _sClassName)
  531.     {
  532.         IWbemCallResultPtr crUnused;
  533.         return CreateInstance(_sClassName,crUnused);
  534.     }
  535.     
  536.     HRESULT DeleteInstance
  537.         (
  538.         _bstr_t             _sClass, 
  539.         IWbemCallResultPtr& _cr
  540.         )
  541.     {
  542.         IWbemServicesPtr pServices;
  543.         GetInterfacePtr(pServices);
  544.         HRESULT hr = pServices->DeleteInstance(_sClass, 0, m_pCtx, &_cr);
  545.         return hr;
  546.     }
  547.     
  548.     HRESULT DeleteInstance(_bstr_t _sClass)
  549.     {
  550.         IWbemCallResultPtr crUnused;
  551.         return DeleteInstance(_sClass, crUnused);
  552.     }
  553.     
  554.     CWbemClassObject GetObject
  555.         (
  556.         _bstr_t                 _sName,
  557.         IWbemCallResultPtr&     _cr,
  558.         bool                    _bThrowOnError = false
  559.         );
  560.     
  561.     CWbemClassObject GetObject(_bstr_t _sName,bool _bThrowOnError = false)
  562.     {
  563.         IWbemCallResultPtr crUnused;
  564.         return GetObject(_sName,crUnused,_bThrowOnError);
  565.     }
  566.     
  567.     
  568.     HRESULT GetMethodSignatures(const _bstr_t& _sObjectName,const _bstr_t& _sMethodName,CWbemClassObject& _in,CWbemClassObject& _out)
  569.     {
  570.         HRESULT hr = E_FAIL;
  571.         
  572.         CWbemClassObject methodClass = GetObject(_sObjectName);
  573.         
  574.         if(methodClass)
  575.         {
  576.             hr = methodClass.GetMethod(_sMethodName,_in,_out);
  577.         }
  578.         
  579.         return hr;
  580.     }
  581.     
  582.     
  583.     HRESULT PutInstance
  584.         (
  585.         CWbemClassObject&   _object,
  586.         IWbemCallResultPtr& _cr,
  587.         long                _lFlags = WBEM_FLAG_CREATE_OR_UPDATE
  588.         )
  589.     {
  590.         IWbemServicesPtr pServices;
  591.         GetInterfacePtr(pServices);
  592.         HRESULT hr = pServices->PutInstance(_object,_lFlags,m_pCtx,&_cr);
  593.         return hr;
  594.     }
  595.     
  596.     HRESULT PutInstance
  597.         (
  598.         CWbemClassObject&   _object,
  599.         long                _lFlags = WBEM_FLAG_CREATE_OR_UPDATE
  600.         )
  601.     {
  602.         IWbemCallResultPtr crUnused;
  603.         return PutInstance(_object,crUnused,_lFlags);
  604.     }
  605.     
  606.     bool IsNull() 
  607.     {  
  608.         IWbemServicesPtr pServices;
  609.         bool bRet = GetInterfacePtr(pServices,false) == NULL;
  610.         
  611.         return bRet;
  612.     }
  613.     
  614.     operator bool()
  615.     {
  616.         IWbemServicesPtr pServices;
  617.         bool bRet = GetInterfacePtr(pServices,false) != NULL;
  618.         return bRet;
  619.     }
  620.  
  621.     operator !()
  622.     {
  623.         IWbemServicesPtr pServices;
  624.         bool bRet = GetInterfacePtr(pServices,false) == NULL;
  625.         return bRet;
  626.     }
  627.  
  628.     
  629.     HRESULT CreateInstanceEnum
  630.         (
  631.         _bstr_t Class, 
  632.         long lFlags, 
  633.         IEnumWbemClassObject **ppEnum
  634.         )
  635.     {
  636.         IWbemServicesPtr pServices;
  637.         GetInterfacePtr(pServices);
  638.         HRESULT hr = pServices->CreateInstanceEnum(Class, lFlags, m_pCtx, ppEnum);
  639.         return hr;
  640.     }
  641.     
  642.     
  643.     HRESULT CreateInstanceEnumAsync
  644.         (
  645.         _bstr_t Class, 
  646.         IWbemObjectSink * ppSink,
  647.         long lFlags = 0
  648.         )
  649.     {
  650.         IWbemServicesPtr pServices;
  651.         GetInterfacePtr(pServices);
  652.         HRESULT hr = pServices->CreateInstanceEnumAsync(Class, lFlags, m_pCtx, ppSink);
  653.         return hr;
  654.     }
  655.     
  656.     
  657.     HRESULT CreateClassEnum
  658.         (
  659.         _bstr_t Class, 
  660.         long lFlags, 
  661.         IEnumWbemClassObject **ppEnum
  662.         )
  663.     {
  664.         IWbemServicesPtr pServices;
  665.         GetInterfacePtr(pServices);
  666.         HRESULT hr = pServices->CreateClassEnum(Class, lFlags, m_pCtx, ppEnum);
  667.         return hr;
  668.     }
  669.     
  670.     HRESULT ExecQuery
  671.         (
  672.         _bstr_t QueryLanguage,
  673.         _bstr_t Query,
  674.         long lFlags,
  675.         IEnumWbemClassObject **ppEnum
  676.         ) 
  677.     {
  678.         IWbemServicesPtr pServices;
  679.         GetInterfacePtr(pServices);
  680.         HRESULT hr = pServices->ExecQuery(QueryLanguage, Query,lFlags, m_pCtx, ppEnum);
  681.         return hr;
  682.     }
  683.     
  684.     HRESULT ExecQuery
  685.         (
  686.         _bstr_t Query,
  687.         long lFlags,
  688.         IEnumWbemClassObject **ppEnum
  689.         ) 
  690.     {
  691.         IWbemServicesPtr pServices;
  692.         GetInterfacePtr(pServices);
  693.         HRESULT hr = pServices->ExecQuery(_bstr_t("WQL"), Query,lFlags, m_pCtx, ppEnum);
  694.         return hr;
  695.     }
  696.     
  697.     HRESULT ExecQuery
  698.         (
  699.         _bstr_t Query,
  700.         IEnumWbemClassObject **ppEnum
  701.         ) 
  702.     {
  703.         IWbemServicesPtr pServices;
  704.         GetInterfacePtr(pServices);
  705.         HRESULT hr = pServices->ExecQuery(_bstr_t("WQL"), Query,0, m_pCtx, ppEnum);
  706.         return hr;
  707.     }
  708.     
  709.     
  710.     
  711.     HRESULT ExecQueryAsync
  712.         (
  713.         _bstr_t Query,
  714.         IWbemObjectSink * pSink,
  715.         long lFlags = 0
  716.         )
  717.     {
  718.         IWbemServicesPtr pServices;
  719.         GetInterfacePtr(pServices);
  720.         HRESULT hr = pServices->ExecQueryAsync(_bstr_t("WQL"), Query,0, m_pCtx, pSink);
  721.         return hr;
  722.     }
  723.     
  724.     
  725.     HRESULT ExecMethod
  726.         (
  727.         _bstr_t sPath,
  728.         _bstr_t sMethod,
  729.         CWbemClassObject& inParams,
  730.         CWbemClassObject& outParams
  731.         )
  732.     {
  733.         IWbemCallResultPtr crUnused;
  734.         IWbemServicesPtr pServices;
  735.         GetInterfacePtr(pServices);
  736.         HRESULT hr = pServices->ExecMethod(sPath, sMethod,0, m_pCtx, inParams,&outParams,&crUnused);
  737.         return hr;
  738.     }
  739.     
  740.     HRESULT CancelAsyncCall(IWbemObjectSink * pSink)
  741.     {
  742.         IWbemServicesPtr pServices;
  743.         GetInterfacePtr(pServices);
  744.         HRESULT hr = pServices->CancelAsyncCall(pSink);
  745.         return hr;
  746.     }
  747.     
  748.     // context values are stored and used for every call until cleared
  749.     HRESULT SetContextValue(_bstr_t sName,_variant_t value);
  750.     HRESULT GetContextValue(_bstr_t sName,_variant_t& value);
  751.     HRESULT DeleteContextValue(_bstr_t sName);
  752.     HRESULT DeleteAllContextValues();
  753.     HRESULT SetContext(IWbemContext * pWbemContext);
  754.     HRESULT GetContext(IWbemContext ** ppWbemContext);
  755.     
  756.     HRESULT GetServices(IWbemServices ** ppServices)
  757.     {
  758.         IWbemServicesPtr pServices;
  759.         GetInterfacePtr(pServices);
  760.         
  761.         *ppServices = pServices.Detach();
  762.         
  763.         return S_OK;
  764.     }
  765.     
  766. };
  767.  
  768.  
  769. #pragma option pop /*P_O_Pop*/
  770. #endif //__SdkWbemHelpers_H
  771.  
  772.