home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / oleaut / browseh / param.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-31  |  3.5 KB  |  151 lines

  1. /*************************************************************************
  2. **
  3. **  This is a part of the Microsoft Source Code Samples.
  4. **
  5. **  Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  6. **
  7. **  This source code is only intended as a supplement to Microsoft Development
  8. **  Tools and/or WinHelp documentation.  See these sources for detailed
  9. **  information regarding the Microsoft samples programs.
  10. **
  11. **  OLE Automation TypeLibrary Browse Helper Sample
  12. **
  13. **  param.cpp
  14. **
  15. **  CParameter implementation
  16. **
  17. **  Written by Microsoft Product Support Services, Windows Developer Support
  18. **
  19. *************************************************************************/
  20.  
  21. #include <windows.h>
  22. #include <windowsx.h>
  23. #ifdef WIN16   
  24.   #include <ole2.h>
  25.   #include <compobj.h>    
  26.   #include <dispatch.h> 
  27.   #include <variant.h>
  28.   #include <olenls.h>  
  29. #endif 
  30. #include "browseh.h"  
  31.  
  32. /*
  33.  * CParameter::Create
  34.  *
  35.  * Purpose:
  36.  *  Creates an instance of the Parameter automation object and initializes it.
  37.  *
  38.  * Parameters:   
  39.  *  ptinfo         TypeInfo in which the function of this parameter is contained.
  40.  *  bstrName       Name of parameter
  41.  *  ptypedesc      Type of parameter.
  42.  *  pidldesc       IDLDESC of parameter.
  43.  *  ppParameter    Returns Parameter automation object.
  44.  *
  45.  * Return Value:
  46.  *  HRESULT
  47.  *
  48.  */
  49. HRESULT 
  50. CParameter::Create(LPTYPEINFO ptinfo, BSTR bstrName, TYPEDESC FAR* ptypedesc, 
  51.      IDLDESC FAR* pidldesc, CParameter FAR* FAR* ppParameter) 
  52. {   
  53.     HRESULT hr;
  54.     CParameter FAR* pParameter = NULL; 
  55.     CTypeDesc FAR* pTypeDesc = NULL;
  56.      
  57.     *ppParameter = NULL;
  58.     
  59.     // Create object.
  60.     pParameter = new CParameter();
  61.     if (pParameter == NULL)
  62.     {
  63.         hr = E_OUTOFMEMORY; 
  64.         goto error;
  65.     }    
  66.    // Load type information for the object from type library. 
  67.     hr = pParameter->LoadTypeInfo(IID_IParameter);
  68.     if (FAILED(hr))
  69.         goto error; 
  70.  
  71.     pParameter->m_bstrName = SysAllocString(bstrName);   
  72.     
  73.     // Parameter type.     
  74.     hr = CTypeDesc::Create(ptinfo, ptypedesc, &pTypeDesc);
  75.     if (FAILED(hr))
  76.         goto error;
  77.     pTypeDesc->QueryInterface(IID_IDispatch, (LPVOID FAR*)&pParameter->m_pdispTypeDesc);
  78.     
  79.     pParameter->m_wIDLFlags = pidldesc->wIDLFlags;
  80. #ifdef _DEBUG  
  81.     lstrcpyn(pParameter->m_szClassName, TEXT("Parameter"), 100);
  82. #endif
  83.         
  84.     *ppParameter = pParameter;
  85.     return NOERROR;
  86.     
  87. error:                        
  88.     if (pParameter == NULL) return E_OUTOFMEMORY;
  89.     
  90.     delete pParameter;
  91.     return hr;
  92. }
  93.  
  94. /*
  95.  * CParameter::CParameter
  96.  *
  97.  * Purpose:
  98.  *  Constructor for CParameter object. Initializes members to NULL.
  99.  *
  100.  */
  101. CParameter::CParameter()
  102. {   
  103.     m_bstrName = NULL;  
  104.     m_pdispTypeDesc = NULL;
  105. }
  106.  
  107. /*
  108.  * CParameter::~CParameter
  109.  *
  110.  * Purpose:
  111.  *  Destructor for CParameter object. 
  112.  *
  113.  */
  114. CParameter::~CParameter()
  115. {    
  116.      if (m_bstrName) SysFreeString(m_bstrName);
  117.      if (m_pdispTypeDesc) m_pdispTypeDesc->Release();
  118. }
  119.  
  120. STDMETHODIMP_(REFCLSID)
  121. CParameter::GetInterfaceID()
  122. {
  123.     return IID_IParameter;
  124. }
  125.  
  126. STDMETHODIMP_(BSTR)
  127. CParameter::get_Name()
  128. {
  129.     return SysAllocString(m_bstrName);
  130. }
  131.  
  132.  
  133. STDMETHODIMP_(ITypeDesc FAR*)
  134. CParameter::get_Type()
  135. {
  136.     m_pdispTypeDesc->AddRef();
  137.     return (ITypeDesc FAR*)m_pdispTypeDesc;
  138.  
  139. STDMETHODIMP_(int)
  140. CParameter::get_IDLFlags()
  141. {
  142.     return (int)m_wIDLFlags;
  143. }
  144.  
  145. STDMETHODIMP_(OBJTYPE)
  146. CParameter::get_Kind()
  147. {   
  148.     return TYPE_PARAMETER;
  149. }
  150.