4.8.6 Retrieving Type Information

This example shows how to retrieve type information for method parameters or members of a struct, a union, or an enumeration given a TYPEDESC (section 2.2.37) structure. A TYPEDESC can be obtained from an ELEMDESC structure, which is a member of VARDESC or FUNCDESC.

 COMMENT This is a recursive procedure and is called PrintTypeDesc.
        
 INPUT: TYPEDESC pointer and reference to ITypeInfo server in the binding context
 OUTPUT: Prints type described by the TYPEDESC
  
 CASE TYPEDESC::vt OF
    VT_PTR:
              CALL PrintTypeDesc with TYPEDESC::lptdesc and ITypeInfo pointer
              PRINT *
  
    VT_SAFEARRAY:
              PRINT SAFEARRAY OF
              CALL PrintTypeDesc with TYPEDESC::lptdesc and ITypeInfo pointer
  
    VT_CARRAY:
              CALL PrintTypeDesc with TYPEDESC::lpadesc::tdescElem and ITypeInfo pointer
              COMMENT see Section 2.2.31 for more information on TYPEDESC::lpadesc
              FOR X = 0 to TYPEDESC::lpadesc::cDims -1
                  PRINT [
                  PRINT TYPEDESC::lpadesc::rgbounds[X].lLbound
                  PRINT &
                  SET Y to TYPEDESC::lpadesc::rgbounds[X].lLbound +
                           TYPEDESC::lpadesc::rgbounds[X].cElements -1
                  PRINT Y
                  PRINT ]
              END FOR
  
    VT_USERDEFINED:
              CALL ITypeInfo::GetRefTypeInfo with TYPEDESC::hreftype and OBTAIN 
                   pCustomTypeInfo which of type ITypeInfo pointer
              CALL pCustomTypeInfo::GetDocumentation(MEMBERID_NIL, 1, &BstrName, NULL,
                   NULL, NULL)
              PRINT BstrName
  
    VT_I2: PRINT short
    VT_I4: PRINT int
    VT_R4: PRINT float
    VT_R8: PRINT double
    VT_CY: PRINT CY
    VT_DATE: PRINT DATE
    VT_BSTR: PRINT BSTR
    VT_DECIMAL: PRINT DECIMAL
    VT_DISPATCH: PRINT IDispatch
    VT_ERROR: PRINT SCODE
    VT_BOOL: PRINT VARIANT_BOOL
    VT_VARIANT: PRINT VARIANT
    VT_UNKNOWN: PRINT IUnknown
    VT_UI1: PRINT BYTE
    VT_I1: PRINT char
    VT_UI2: PRINT unsigned short
    VT_UI4: PRINT unsigned long
    VT_I8: PRINT __int64
    VT_UI8: PRINT unsigned __int64
    VT_INT: PRINT int
    VT_UINT: PRINT unsigned int
    VT_HRESULT: PRINT HRESULT
    VT_VOID: PRINT void
    VT_LPSTR: PRINT char *
    VT_LPWSTR: PRINT wchar *
    OTHERS: PRINT Error 
  
 ENDCASE