CComBSTR::CComBSTR

Il costruttore.Il costruttore predefinito imposta il membro di m_str a NULL.

CComBSTR( ) throw( ); 
CComBSTR(
   const CComBSTR& src 
);
CComBSTR(
   REFGUID guid 
);
CComBSTR(
   int nSize 
);
CComBSTR(
   int nSize,
   LPCOLESTR sz 
);
CComBSTR(
   int nSize,
   LPCSTR sz 
);
CComBSTR(
   LPCOLESTR pSrc 
);
CComBSTR(
   LPCSTR pSrc 
);

Parametri

  • nSize
    [in] numero di caratteri da copiare da sz o dalla dimensione iniziale in caratteri per CComBSTR.

  • sz
    [in] stringa di un oggetto da copiare.La versione Unicode specifica LPCOLESTR; nella versione ANSI specifica LPCSTR.

  • pSrc
    [in] stringa di un oggetto da copiare.La versione Unicode specifica LPCOLESTR; nella versione ANSI specifica LPCSTR.

  • src
    [in] oggetto A CComBSTR.

  • guid
    [in] riferimento A una struttura GUID.

Note

Il costruttore di copia imposta m_str a una copia del membro di BSTRdi src.Il costruttore REFGUIDGUID converte in una stringa mediante StringFromGUID2 e archiviare il risultato.

Gli altri costruttori specifici m_str a una copia della stringa specificata.Se si passa un valore per nSize, quindi solo caratteri di nSize verranno copiati, seguito da un carattere di terminazione null.

Il distruttore libera la stringa indicata da m_str.

Esempio

CComBSTR bstr1;   // BSTR points to NULL
bstr1 = "Bye";    // initialize with assignment operator
                  // ANSI string is converted to wide char

OLECHAR* str = OLESTR("Bye bye!");  // wide char string of length 5
int len = (int)wcslen(str);
CComBSTR bstr2(len + 1);// unintialized BSTR of length 6
wcsncpy_s(bstr2.m_str, bstr2.Length(), str, len); // copy wide char string to BSTR

CComBSTR bstr3(5, OLESTR("Hello World")); // BSTR containing 'Hello', 
                                          // input string is wide char
CComBSTR bstr4(5, "Hello World");         // same as above, input string 
                                          // is ANSI

CComBSTR bstr5(OLESTR("Hey there")); // BSTR containing 'Hey there', 
                                     // input string is wide char
CComBSTR bstr6("Hey there");         // same as above, input string 
                                     // is ANSI

CComBSTR bstr7(bstr6);     // copy constructor, bstr7 contains 'Hey there'   

Requisiti

Header: atlbase.h

Vedere anche

Riferimenti

CComBSTR (classe)

Altre risorse

ATL and MFC String Conversion Macros