Condividi tramite


Classe CComBSTR

Questa classe è un wrapper per BSTRs.

Sintassi

class CComBSTR

Membri

Costruttori pubblici

Nome Descrizione
CComBSTR::CComBSTR Costruttore.
CComBSTR::~CComBSTR Distruttore.

Metodi pubblici

Nome Descrizione
CComBSTR::Append Aggiunge una stringa a m_str.
CComBSTR::AppendBSTR Aggiunge un oggetto BSTR a m_str.
CComBSTR::AppendBytes Aggiunge un numero specificato di byte a m_str.
CComBSTR::ArrayToBSTR Crea un oggetto BSTR dal primo carattere di ogni elemento nell'oggetto safearray e lo associa all'oggetto CComBSTR .
CComBSTR::AssignBSTR Assegna un oggetto BSTR a m_str.
CComBSTR::Attach Associa un oggetto BSTR all'oggetto CComBSTR .
CComBSTR::BSTRToArray Crea un safearray unidimensionale in base zero, in cui ogni elemento della matrice è un carattere dell'oggetto CComBSTR .
CComBSTR::ByteLength Restituisce la lunghezza di m_str in byte.
CComBSTR::Copy Restituisce una copia di m_str.
CComBSTR::CopyTo Restituisce una copia di m_str tramite un [out] parametro
CComBSTR::Detach m_str Scollega dall'oggetto CComBSTR .
CComBSTR::Empty m_strLibera .
CComBSTR::Length Restituisce la lunghezza di m_str.
CComBSTR::LoadString Carica una risorsa stringa.
CComBSTR::ReadFromStream Carica un BSTR oggetto da un flusso.
CComBSTR::ToLower Converte la stringa in lettere minuscole.
CComBSTR::ToUpper Converte la stringa in maiuscolo.
CComBSTR::WriteToStream Salva m_str in un flusso.

Operatori pubblici

Nome Descrizione
CComBSTR::operator BSTR Esegue il cast di un CComBSTR oggetto a un oggetto BSTR.
CComBSTR::operator ! Restituisce TRUE o FAL edizione Standard, a seconda che m_str sia NULL.
CComBSTR::operator != Confronta un oggetto CComBSTR con una stringa.
CComBSTR::operator & Restituisce l'indirizzo di m_str.
CComBSTR::operator += Aggiunge un oggetto CComBSTR all'oggetto .
CComBSTR::operator < Confronta un oggetto CComBSTR con una stringa.
CComBSTR::operator = Assegna un valore a m_str.
CComBSTR::operator == Confronta un oggetto CComBSTR con una stringa.
CComBSTR::operator > Confronta un oggetto CComBSTR con una stringa.

Membri dati pubblici

Nome Descrizione
CComBSTR::m_str Contiene l'oggetto BSTR associato all'oggetto CComBSTR .

Osservazioni:

La CComBSTR classe è un wrapper per BSTRs, ovvero stringhe con prefisso di lunghezza. La lunghezza viene archiviata come numero intero nella posizione di memoria che precede i dati nella stringa.

Un BSTR oggetto viene terminato con null dopo l'ultimo carattere contato, ma può contenere anche caratteri Null incorporati all'interno della stringa. La lunghezza della stringa è determinata dal conteggio dei caratteri, non dal primo carattere Null.

Nota

La CComBSTR classe fornisce diversi membri (costruttori, operatori di assegnazione e operatori di confronto) che accettano stringhe ANSI o Unicode come argomenti. Le versioni ANSI di queste funzioni sono meno efficienti rispetto alle rispettive controparti Unicode perché le stringhe Unicode temporanee vengono spesso create internamente. Per un'efficienza, usare le versioni Unicode laddove possibile.

Nota

A causa del comportamento di ricerca migliorato implementato in Visual Studio .NET, il codice, bstr = L"String2" + bstr;ad esempio , che potrebbe essere stato compilato nelle versioni precedenti, deve essere invece implementato come bstr = CStringW(L"String2") + bstr.

Per un elenco di avvertenze quando si usa CComBSTR, vedere Programmazione con CComBSTR.

Requisiti

Intestazione:atlbase.h

CComBSTR::Append

lpsz Aggiunge o il membro BSTR di bstrSrc a m_str.

HRESULT Append(const CComBSTR& bstrSrc) throw();
HRESULT Append(wchar_t ch) throw();
HRESULT Append(char ch) throw();
HRESULT Append(LPCOLESTR lpsz) throw();
HRESULT Append(LPCSTR lpsz) throw();
HRESULT Append(LPCOLESTR lpsz, int nLen) throw();

Parametri

bstrSrc
[in] Oggetto CComBSTR da accodare.

ch
[in] Carattere da accodare.

lpsz
[in] Stringa di caratteri con terminazione zero da aggiungere. È possibile passare una stringa Unicode tramite l'overload LPCOLESTR o una stringa ANSI tramite la LPCSTR versione.

nLen
[in] Numero di caratteri da lpsz aggiungere.

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

Osservazioni:

Una stringa ANSI verrà convertita in Unicode prima di essere accodata.

Esempio

enum { urlASP, urlHTM, urlISAPI } urlType;
urlType = urlASP;

CComBSTR bstrURL = OLESTR("http://SomeSite/");
CComBSTR bstrDEF = OLESTR("/OtherSite");
CComBSTR bstrASP = OLESTR("default.asp");

CComBSTR bstrTemp;
HRESULT hr;

switch (urlType)
{
case urlASP:
   // bstrURL is 'http://SomeSite/default.asp'
   hr = bstrURL.Append(bstrASP);
   break;

case urlHTM:
   // bstrURL is 'http://SomeSite/default.htm'
   hr = bstrURL.Append(OLESTR("default.htm"));
   break;

case urlISAPI:
   // bstrURL is 'http://SomeSite/default.dll?func'
   hr = bstrURL.Append(OLESTR("default.dll?func"));
   break;

default:
   // bstrTemp is 'http://'
   hr = bstrTemp.Append(bstrURL, 7);
   // bstrURL is 'http://OtherSite'
   if (hr == S_OK)
       hr = bstrTemp.Append(bstrDEF);
   bstrURL = bstrTemp;

   break;
}

CComBSTR::AppendBSTR

Accoda l'oggetto specificato BSTR a m_str.

HRESULT AppendBSTR(BSTR p) throw();

Parametri

p
[in] Oggetto BSTR da accodare.

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

Osservazioni:

Non passare una normale stringa di caratteri wide a questo metodo. Il compilatore non riesce a rilevare l'errore e si verificheranno errori di runtime.

Esempio

CComBSTR bstrPre(OLESTR("Hello "));
CComBSTR bstrSuf(OLESTR("World!"));
HRESULT hr;

// Appends "World!" to "Hello "
hr = bstrPre.AppendBSTR(bstrSuf);

// Displays a message box with text "Hello World!"
::MessageBox(NULL, CW2CT(bstrPre), NULL, MB_OK);   

CComBSTR::AppendBytes

Aggiunge il numero specificato di byte a m_str senza conversione.

HRESULT AppendBytes(const char* lpsz, int nLen) throw();

Parametri

lpsz
[in] Puntatore a una matrice di byte da aggiungere.

p
[in] Numero di byte da aggiungere.

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

Esempio

CComBSTR bstrPre(OLESTR("Hello "));
HRESULT hr;

// Appends "Wo" to "Hello " (4 bytes == 2 characters)
hr = bstrPre.AppendBytes(reinterpret_cast<char*>(OLESTR("World!")), 4);

// Displays a message box with text "Hello Wo"
::MessageBox(NULL, CW2CT(bstrPre), NULL, MB_OK);   

CComBSTR::ArrayToBSTR

Libera qualsiasi stringa esistente contenuta nell'oggetto CComBSTR , quindi crea un BSTR oggetto dal primo carattere di ogni elemento nell'oggetto safearray e lo collega all'oggetto CComBSTR .

HRESULT ArrayToBSTR(const SAFEARRAY* pSrc) throw();

Parametri

pSrc
[in] Safearray contenente gli elementi utilizzati per creare la stringa.

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

CComBSTR::AssignBSTR

Assegna un oggetto BSTR a m_str.

HRESULT AssignBSTR(const BSTR bstrSrc) throw();

Parametri

bstrSrc
[in] BSTR da assegnare all'oggetto corrente CComBSTR .

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

CComBSTR::Attach

Associa un oggetto all'oggetto CComBSTR impostando il m_str membro su src.BSTR

void Attach(BSTR src) throw();

Parametri

src
[in] Oggetto BSTR da associare all'oggetto .

Osservazioni:

Non passare una normale stringa di caratteri wide a questo metodo. Il compilatore non riesce a rilevare l'errore e si verificheranno errori di runtime.

Nota

Questo metodo asserisce se m_str è diverso da NULL.

Esempio

// STDMETHOD(BSTRToUpper)(/*[in, out]*/ BSTR bstrConv);
STDMETHODIMP InplaceBSTRToUpper(BSTR bstrConv)
{
   // Assign bstrConv to m_str member of CComBSTR
   CComBSTR bstrTemp;
   bstrTemp.Attach(bstrConv); 

   // Make sure BSTR is not NULL string
   if (!bstrTemp)
        return E_POINTER;

   // Make string uppercase 
   HRESULT hr;
   hr = bstrTemp.ToUpper();
   if (hr != S_OK)
       return hr;

   // Set m_str to NULL, so the BSTR is not freed
   bstrTemp.Detach(); 

   return S_OK; 
}

CComBSTR::BSTRToArray

Crea un safearray unidimensionale in base zero, in cui ogni elemento della matrice è un carattere dell'oggetto CComBSTR .

HRESULT BSTRToArray(LPSAFEARRAY* ppArray) throw();

Parametri

ppArray
[out] Puntatore all'oggetto safearray usato per contenere i risultati della funzione.

Valore restituito

S_OK in caso di esito positivo o di qualsiasi valore di errore standard HRESULT .

CComBSTR::ByteLength

Restituisce il numero di byte in m_str, escluso il carattere Null di terminazione.

unsigned int ByteLength() const throw();

Valore restituito

Lunghezza del m_str membro in byte.

Osservazioni:

Restituisce 0 se m_str è NULL.

Esempio

// string with 11 chars (22 bytes)
CComBSTR bstrTemp(OLESTR("Hello World"));

unsigned int len = bstrTemp.ByteLength();

ATLASSERT(len == 22);   

CComBSTR::CComBSTR

Costruttore. Il costruttore predefinito imposta il m_str membro su 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);
CComBSTR(CComBSTR&& src) throw(); // (Visual Studio 2017)

Parametri

nSize
[in] Numero di caratteri da copiare da sz o la dimensione iniziale in caratteri per l'oggetto CComBSTR.

sz
[in] Stringa da copiare. La versione Unicode specifica un oggetto LPCOLESTR. La versione ANSI specifica un LPCSTR.

pSrc
[in] Stringa da copiare. La versione Unicode specifica un oggetto LPCOLESTR. La versione ANSI specifica un LPCSTR.

src
[in] Oggetto CComBSTR.

guid
[in] Riferimento a una GUID struttura.

Osservazioni:

Il costruttore di copia imposta m_str su una copia del membro BSTR di src. Il REFGUID costruttore converte il GUID in una stringa utilizzando StringFromGUID2 e archivia il risultato.

L'altro costruttore imposta m_str su una copia della stringa specificata. Se si passa un valore per nSize, verranno copiati solo nSize i caratteri, seguiti da un carattere Null di terminazione.

CComBSTR supporta la semantica di spostamento. È possibile usare il costruttore di spostamento (il costruttore che accetta un riferimento rvalue (&&) per creare un nuovo oggetto che usa gli stessi dati sottostanti dell'oggetto precedente passato come argomento, senza il sovraccarico di copiare l'oggetto.

Il distruttore libera la stringa a cui punta 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'   

CComBSTR::~CComBSTR

Distruttore.

~CComBSTR();

Osservazioni:

Il distruttore libera la stringa a cui punta m_str.

CComBSTR::Copy

Alloca e restituisce una copia di m_str.

BSTR Copy() const throw();

Valore restituito

Copia del m_str membro. Se m_str è NULL, restituisce NULL.

Esempio

CComBSTR m_bstrURL;    // BSTR representing a URL

// put_URL is the put method for the URL property. 
STDMETHOD(put_URL)(BSTR strURL)
{
    ATLTRACE(_T("put_URL\n"));

    // free existing string in m_bstrURL & make a copy 
    // of strURL pointed to by m_bstrURL
    m_bstrURL = strURL;
    return S_OK;
}

// get_URL is the get method for the URL property. 
STDMETHOD(get_URL)(BSTR* pstrURL)
{
    ATLTRACE(_T("get_URL\n"));

    // make a copy of m_bstrURL pointed to by pstrURL
    *pstrURL = m_bstrURL.Copy(); // See CComBSTR::CopyTo
    return S_OK;
}

CComBSTR::CopyTo

Alloca e restituisce una copia di m_str tramite il parametro .

HRESULT CopyTo(BSTR* pbstr) throw();

HRESULT CopyTo(VARIANT* pvarDest) throw();

Parametri

pbstr
[out] Indirizzo di un oggetto BSTR in cui restituire la stringa allocata da questo metodo.

pvarDest
[out] Indirizzo di un oggetto VARIANT in cui restituire la stringa allocata da questo metodo.

Valore restituito

Valore standard HRESULT che indica l'esito positivo o negativo della copia.

Osservazioni:

Dopo aver chiamato questo metodo, l'oggetto VARIANT a cui pvarDest punta sarà di tipo VT_BSTR.

Esempio

CComBSTR m_bstrURL; // BSTR representing a URL

// get_URL is the get method for the URL property. 
STDMETHOD(get_URL)(BSTR* pstrURL)
{
   // Make a copy of m_bstrURL and return it via pstrURL
   return m_bstrURL.CopyTo(pstrURL);
}

CComBSTR::Detach

m_str Scollega dall'oggetto CComBSTR e imposta m_str su NULL.

BSTR Detach() throw();

Valore restituito

Oggetto BSTR associato all'oggetto CComBSTR.

Esempio

// Method which converts bstrIn to uppercase 
STDMETHODIMP BSTRToUpper(BSTR bstrIn, BSTR* pbstrOut)
{ 
    if (bstrIn == NULL || pbstrOut == NULL) 
        return E_POINTER; 

    // Create a temporary copy of bstrIn
    CComBSTR bstrTemp(bstrIn); 

    if (!bstrTemp) 
        return E_OUTOFMEMORY; 

    // Make string uppercase
    HRESULT hr;
    hr = bstrTemp.ToUpper();
    if (hr != S_OK)
        return hr;
    
    // Return m_str member of bstrTemp 
    *pbstrOut = bstrTemp.Detach(); 

    return S_OK; 
}

CComBSTR::Empty

Libera il m_str membro.

void Empty() throw();

Esempio

CComBSTR bstr(OLESTR("abc"));

// Calls SysFreeString to free the BSTR
bstr.Empty();
ATLASSERT(bstr.Length() == 0);   

CComBSTR::Length

Restituisce il numero di caratteri in m_str, escluso il carattere Null di terminazione.

unsigned int Length() const throw();

Valore restituito

Lunghezza del m_str membro.

Esempio

// string with 11 chars
CComBSTR bstrTemp(OLESTR("Hello World"));

unsigned int len = bstrTemp.Length();

ATLASSERT(len == 11);

CComBSTR::LoadString

Carica una risorsa stringa specificata da nID e la archivia in questo oggetto.

bool LoadString(HINSTANCE hInst, UINT nID) throw();
bool LoadString(UINT nID) throw();

Parametri

Vedere LoadString in Windows SDK.

Valore restituito

Restituisce TRUE se la stringa viene caricata correttamente; in caso contrario, restituisce FALSE.

Osservazioni:

La prima funzione carica la risorsa dal modulo identificato dall'utente tramite il hInst parametro . La seconda funzione carica la risorsa dal modulo di risorse associato all'oggetto CComModulederivato da usato in questo progetto.

Esempio

CComBSTR bstrTemp;

// IDS_PROJNAME proj name stored as resource in string table
bstrTemp.LoadString(IDS_PROJNAME);

// the above is equivalent to:
// bstrTemp.LoadString(_Module.m_hInstResource, IDS_PROJNAME);

// display message box w/ proj name as title & text
::MessageBox(NULL, CW2CT(bstrTemp), CW2CT(bstrTemp), MB_OK);   

CComBSTR::m_str

Contiene l'oggetto BSTR associato all'oggetto CComBSTR .

BSTR m_str;

Esempio

CComBSTR GuidToBSTR(REFGUID guid) 
{
    // 39 - length of string representation of GUID + 1
    CComBSTR b(39); 

    // Convert GUID to BSTR
    // m_str member of CComBSTR is of type BSTR. When BSTR param 
    // is required, pass the m_str member explicitly or use implicit 
    // BSTR cast operator.
    int nRet = StringFromGUID2(guid, b.m_str, 39); 

    // Above equivalent to:
    // int nRet = StringFromGUID2(guid, b, 39); 
    // implicit BSTR cast operator used for 2nd param

    // Both lines are equivalent to:
    // CComBSTR b(guid);
    // CComBSTR constructor can convert GUIDs

    ATLASSERT(nRet); 
    return b; 
}

CComBSTR::operator BSTR

Esegue il cast di un CComBSTR oggetto a un oggetto BSTR.

operator BSTR() const throw();

Osservazioni:

Consente di passare CComBSTR oggetti a funzioni con parametri [in]. BSTR

Esempio

Vedere l'esempio per CComBSTR::m_str.

CComBSTR::operator !

Controlla se BSTR la stringa è NULL.

bool operator!() const throw();

Valore restituito

Restituisce TRUE se il m_str membro è NULL; in caso contrario, FALSE.

Osservazioni:

Questo operatore controlla solo la presenza di un NULL valore, non di una stringa vuota.

Esempio

// STDMETHOD(BSTRToUpper)(/*[in, out]*/ BSTR bstrConv);
STDMETHODIMP InplaceBSTRToUpper(BSTR bstrConv)
{
   // Assign bstrConv to m_str member of CComBSTR
   CComBSTR bstrTemp;
   bstrTemp.Attach(bstrConv); 

   // Make sure BSTR is not NULL string
   if (!bstrTemp)
        return E_POINTER;

   // Make string uppercase 
   HRESULT hr;
   hr = bstrTemp.ToUpper();
   if (hr != S_OK)
       return hr;

   // Set m_str to NULL, so the BSTR is not freed
   bstrTemp.Detach(); 

   return S_OK; 
}

CComBSTR::operator !=

Restituisce l'opposto logico di operator ==.

bool operator!= (const CComBSTR& bstrSrc) const throw();
bool operator!= (LPCOLESTR pszSrc) const;
bool operator!= (LPCSTR pszSrc) const;
bool operator!= (int nNull) const throw();

Parametri

bstrSrc
[in] Oggetto CComBSTR.

pszSrc
[in] Stringa con terminazione zero.

nNull
[in] Deve essere NULL.

Valore restituito

Restituisce TRUE se l'elemento confrontato non è uguale all'oggetto CComBSTR ; in caso contrario, restituisce FALSE.

Osservazioni:

CComBSTRs vengono confrontati in modo testuale nel contesto delle impostazioni locali predefinite dell'utente. L'operatore di confronto finale confronta semplicemente la stringa contenuta con NULL.

CComBSTR::operator &

Restituisce l'indirizzo dell'oggetto BSTR archiviato nel m_str membro.

BSTR* operator&() throw();

Osservazioni:

CComBstr operator & dispone di un'asserzione speciale associata a tale asserzione per identificare le perdite di memoria. Il programma asserisce quando il m_str membro viene inizializzato. Questa asserzione è stata creata per identificare le situazioni in cui un programmatore usa per & operator assegnare un nuovo valore al m_str membro senza liberare la prima allocazione di m_str. Se m_str è uguale NULLa , il programma presuppone che m_str non sia ancora stato allocato. In questo caso, il programma non asserisce.

Questa asserzione non è abilitata per impostazione predefinita. Definire ATL_CCOMBSTR_ADDRESS_OF_ASSERT per abilitare questa asserzione.

Esempio

#define ATL_NO_CCOMBSTR_ADDRESS_OF_ASSERT

void MyInitFunction(BSTR* pbstr)
{
   ::SysReAllocString(pbstr, OLESTR("Hello World"));
   return;
}
CComBSTR bstrStr ;
// bstrStr is not initialized so this call will not assert.
MyInitFunction(&bstrStr); 

CComBSTR bstrStr2(OLESTR("Hello World"));
// bstrStr2 is initialized so this call will assert.
::SysReAllocString(&bstrStr2, OLESTR("Bye"));

CComBSTR::operator +=

Aggiunge una stringa all'oggetto CComBSTR .

CComBSTR& operator+= (const CComBSTR& bstrSrc);
CComBSTR& operator+= (const LPCOLESTR pszSrc);

Parametri

bstrSrc
[in] Oggetto CComBSTR da accodare.

pszSrc
[in] Stringa con terminazione zero da aggiungere.

Osservazioni:

CComBSTRs vengono confrontati in modo testuale nel contesto delle impostazioni locali predefinite dell'utente. Il LPCOLESTR confronto viene eseguito usando memcmp i dati non elaborati in ogni stringa. Il LPCSTR confronto viene eseguito nello stesso modo dopo la creazione di una copia Unicode temporanea di pszSrc . L'operatore di confronto finale confronta semplicemente la stringa contenuta con NULL.

Esempio

CComBSTR bstrPre(OLESTR("Hello "));
CComBSTR bstrSuf(OLESTR("World!"));

// Appends "World!" to "Hello "
bstrPre += bstrSuf;

// Displays a message box with text "Hello World!"
::MessageBox(NULL, CW2CT(bstrPre), NULL, MB_OK);   

CComBSTR::operator <

Confronta un oggetto CComBSTR con una stringa.

bool operator<(const CComBSTR& bstrSrc) const throw();
bool operator<(LPCOLESTR pszSrc) const throw();
bool operator<(LPCSTR pszSrc) const throw();

Valore restituito

Restituisce TRUE se l'elemento confrontato è minore dell'oggetto CComBSTR ; in caso contrario, restituisce FALSE.

Osservazioni:

Il confronto viene eseguito usando le impostazioni locali predefinite dell'utente.

CComBSTR::operator =

Imposta il m_str membro su una copia di pSrc o su una copia del BSTR membro di src. L'operatore di assegnazione di spostamento viene spostato src senza copiarlo.

CComBSTR& operator= (const CComBSTR& src);
CComBSTR& operator= (LPCOLESTR pSrc);
CComBSTR& operator= (LPCSTR pSrc);
CComBSTR& operator= (CComBSTR&& src) throw(); // (Visual Studio 2017)

Osservazioni:

Il pSrc parametro specifica un oggetto LPCOLESTR per le versioni Unicode o LPCSTR per le versioni ANSI.

Esempio

Vedere l'esempio per CComBSTR::Copy.

CComBSTR::operator ==

Confronta un oggetto CComBSTR con una stringa. CComBSTRs vengono confrontati in modo testuale nel contesto delle impostazioni locali predefinite dell'utente.

bool operator== (const CComBSTR& bstrSrc) const throw();
bool operator== (LPCOLESTR pszSrc) const;
bool operator== (LPCSTR pszSrc) const;
bool operator== (int nNull) const throw();

Parametri

bstrSrc
[in] Oggetto CComBSTR.

pszSrc
[in] Stringa con terminazione zero.

nNull
[in] Deve essere NULL.

Valore restituito

Restituisce TRUE se l'elemento confrontato è uguale all'oggetto CComBSTR ; in caso contrario, restituisce FALSE.

Osservazioni:

L'operatore di confronto finale confronta semplicemente la stringa contenuta con NULL.

CComBSTR::operator >

Confronta un oggetto CComBSTR con una stringa.

bool operator>(const CComBSTR& bstrSrc) const throw();

Valore restituito

Restituisce TRUE se l'elemento confrontato è maggiore dell'oggetto CComBSTR ; in caso contrario, restituisce FALSE.

Osservazioni:

Il confronto viene eseguito usando le impostazioni locali predefinite dell'utente.

CComBSTR::ReadFromStream

Imposta il m_str membro sull'oggetto BSTR contenuto nel flusso specificato.

HRESULT ReadFromStream(IStream* pStream) throw();

Parametri

pStream
[in] Puntatore all'interfaccia IStream nel flusso contenente i dati.

Valore restituito

Un valore HRESULT standard.

Osservazioni:

ReadToStream richiede che il contenuto del flusso nella posizione corrente sia compatibile con il formato di dati scritto da una chiamata a WriteToStream.

Esempio

IDataObject* pDataObj;

// Fill in the FORMATETC struct to retrieve desired format 
// from clipboard
FORMATETC formatetcIn = {CF_TEXT, NULL, DVASPECT_CONTENT, -1, TYMED_ISTREAM};
STGMEDIUM medium;
ZeroMemory(&medium, sizeof(STGMEDIUM));

// Get IDataObject from clipboard
HRESULT hr = ::OleGetClipboard(&pDataObj);

// Retrieve data from clipboard
hr = pDataObj->GetData(&formatetcIn, &medium);

if (SUCCEEDED(hr) && medium.tymed == TYMED_ISTREAM)
{
   CComBSTR bstrStr;
   // Get BSTR out of the stream
   hr = bstrStr.ReadFromStream(medium.pstm);

   //release the stream
   ::ReleaseStgMedium(&medium);
}

CComBSTR::ToLower

Converte la stringa contenuta in lettere minuscole.

HRESULT ToLower() throw();

Valore restituito

Un valore HRESULT standard.

Osservazioni:

Per altre informazioni sull'esecuzione della conversione, vedere CharLowerBuff .

CComBSTR::ToUpper

Converte la stringa contenuta in maiuscolo.

HRESULT ToUpper() throw();

Valore restituito

Un valore HRESULT standard.

Osservazioni:

Per altre informazioni sull'esecuzione della conversione, vedere CharUpperBuff .

CComBSTR::WriteToStream

Salva il m_str membro in un flusso.

HRESULT WriteToStream(IStream* pStream) throw();

Parametri

pStream
[in] Puntatore all'interfaccia IStream in un flusso.

Valore restituito

Un valore HRESULT standard.

Osservazioni:

È possibile ricreare un oggetto BSTR dal contenuto del flusso usando la ReadFromStream funzione .

Esempio

//implementation of IDataObject::GetData()
STDMETHODIMP CMyDataObj::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
{
    HRESULT hr = S_OK;
    if (pformatetcIn->cfFormat == CF_TEXT && pformatetcIn->tymed == TYMED_ISTREAM)
    {
        IStream *pStm;
        // Create an IStream from global memory
        hr = CreateStreamOnHGlobal(NULL, TRUE, &pStm);
        if (FAILED(hr))
            return hr;

        // Initialize CComBSTR
        CComBSTR bstrStr = OLESTR("Hello World");

        // Serialize string into stream
        // the length followed by actual string is serialized into stream
        hr = bstrStr.WriteToStream(pStm);

        // Pass the IStream pointer back through STGMEDIUM struct
        pmedium->tymed = TYMED_ISTREAM;
        pmedium->pstm = pStm;
        pmedium->pUnkForRelease = NULL; 
    }

    return hr;
}

Vedi anche

Cenni preliminari sulla classe
Macro di conversione di stringhe ATL e MFC