천객만래 [千客萬來] (It has an interminable succession of visitors)

출처 :  http://msdn.microsoft.com/en-us/library/e305240e-9e11-4006-98cc-26f4932d2118(VS.85) 


VARIANT, BSTR & SAFEARRAY C++ Tutorial...

Introduction

Frustrated by the lack of good articles on the VARIANT data type, I decided to write this short introduction.

The VARIANT type is an all purpose data type used by IDispatch::Invoke both to transmit and receive parameters. It can hold numbers, strings, arrays, error values and IDispatch pointers. An XLL developer could consider the variant to be the Automation equivalent of the do everything Excel XLOPER data type.

Structure

Here is a simplified version of the VARIANT definition. For the full definition see this link.

struct tagVARIANT {
    VARTYPE vt; // unsigned short integer type code
    WORD wReserved1;
    WORD wReserved2;
    WORD wReserved3;
    union {
    //  C++ Type      Union Name   Type Tag                Basic Type
    //  --------      ----------   --------                ----------

        long          lVal;        // VT_I4                ByVal Long
        unsigned char bVal;        // VT_UI1               ByVal Byte
        short         iVal;        // VT_I2                ByVal Integer
        double        dblVal;      // VT_R8                ByVal Double
        VARIANT_BOOL  boolVal;     // VT_BOOL              ByVal Boolean
        SCODE         scode;       // VT_ERROR
        DATE          date;        // VT_DATE              ByVal Date
        BSTR          bstrVal;     // VT_BSTR              ByVal String
        IUnknown      *punkVal;    // VT_UNKNOWN 
        IDispatch     *pdispVal;   // VT_DISPATCH          ByVal Object
        SAFEARRAY     *parray;     // VT_ARRAY|*           ByVal array
        // A bunch of other types that don't matter here...
        VARIANT       *pvarVal;    // VT_BYREF|VT_VARIANT  ByRef Variant
        void          * byref;     // Generic ByRef        
    };
};

The variant type is 16 bytes in size.

[출처] variant|작성자 najira00

Posted by SB패밀리
소백촌닭
이제 문자열 변환 헤매이지 말고 여기에서 다 찾자.
이 문자열 변수 변환은 아주 유용하게 사용될 것이당.

[개발/MFC] BSTR to CString 문자열 변환 http://sbrich.tistory.com/1047
[개발/MFC} CString to char  http://sbrich.tistory.com/842
[VC++] 문자열변환 CString LPSTR WCHAR* LPCWSTR  http://sbrich.tistory.com/383

Variant To CString , CString to Variant


CString str="abc";
COleVariant strVar(str);
VARIANT var=strVar.Detach();

 
CString VariantToString(VARIANT * va)
   {
    CString s;
    switch(va->vt)
      { /* vt */
       case VT_BSTR:
          return CString(vaData->bstrVal);
       case VT_BSTR | VT_BYREF:
          return CString(*vaData->pbstrVal);
       case VT_I4:
          s.Format(_T("%d"), va->lVal);
          return s;
       case VT_I4 | VT_BYREF:
          s.Format(_T("%d"), *va->plVal);
       case VT_R8:
          s.Format(_T("%f"), va->dblVal);
          return s;
       ... remaining cases left as an Exercise For The Reader
       default:
          ASSERT(FALSE); // unknown VARIANT type (this ASSERT is optional)
          return CString("");
      } /* vt */
   }

Posted by SB패밀리