CComBSTR 수업

이 클래스는 s에 대한 BSTR래퍼입니다.

구문

class CComBSTR

멤버

공용 생성자

속성 설명
CComBSTR::CComBSTR 생성자입니다.
CComBSTR::~CComBSTR 소멸자입니다.

공용 메서드

이름 설명
CComBSTR::Append 에 문자열 m_str을 추가합니다.
CComBSTR::AppendBSTR 에 추가 BSTR m_str합니다.
CComBSTR::AppendBytes 지정된 바이트 수를 에 추가합니다 m_str.
CComBSTR::ArrayToBSTR BSTR safearray에 있는 각 요소의 첫 번째 문자에서 해당 문자를 만들어 개체에 CComBSTR 연결합니다.
CComBSTR::AssignBSTR 에 할당 BSTR m_str합니다.
CComBSTR::Attach 개체에 BSTR CComBSTR 연결합니다.
CComBSTR::BSTRToArray 배열의 각 요소가 개체의 문자인 0부터 시작하는 1차원 safearray를 CComBSTR 만듭니다.
CComBSTR::ByteLength 바이트 단위의 m_str 길이를 반환합니다.
CComBSTR::Copy 의 복사본을 반환합니다 m_str.
CComBSTR::CopyTo 매개 변수를 통해 복사본을 m_str 반환합니다 [out] .
CComBSTR::Detach 개체에서 CComBSTR 분리합니다m_str.
CComBSTR::Empty 해제합니다.m_str
CComBSTR::Length 의 길이를 반환합니다 m_str.
CComBSTR::LoadString 문자열 리소스를 로드합니다.
CComBSTR::ReadFromStream BSTR 스트림에서 개체를 로드합니다.
CComBSTR::ToLower 문자열을 소문자로 변환합니다.
CComBSTR::ToUpper 문자열을 대문자로 변환합니다.
CComBSTR::WriteToStream 스트림에 저장합니다 m_str .

Public 연산자

속성 설명
CComBSTR::operator BSTR 개체를 CComBSTR BSTR로 캐스팅합니다.
CComBSTR::operator ! NULL인지 여부에 m_str 따라 TRUE 또는 FALSE를 반환합니다.
CComBSTR::operator != 문자열과 CComBSTR 비교합니다.
CComBSTR::operator & 의 주소를 반환합니다 m_str.
CComBSTR::operator += 개체에 추가합니다 CComBSTR .
CComBSTR::operator < 문자열과 CComBSTR 비교합니다.
CComBSTR::operator = 에 값을 할당합니다 m_str.
CComBSTR::operator == 문자열과 CComBSTR 비교합니다.
CComBSTR::operator > 문자열과 CComBSTR 비교합니다.

공용 데이터 멤버

속성 설명
CComBSTR::m_str BSTR 개체와 연결된 개체를 CComBSTR 포함합니다.

설명

클래스는 CComBSTR 길이 접두사 문자열인 s에 대한 BSTR래퍼입니다. 길이는 문자열의 데이터 앞에 있는 메모리 위치에 정수로 저장됩니다.

A BSTR 는 마지막으로 계산된 문자 후에 null로 종료되지만 문자열 내에 포함된 null 문자를 포함할 수도 있습니다. 문자열 길이는 첫 번째 null 문자가 아닌 문자 수에 따라 결정됩니다.

참고 항목

이 클래스는 CComBSTR ANSI 또는 유니코드 문자열을 인수로 사용하는 여러 멤버(생성자, 할당 연산자 및 비교 연산자)를 제공합니다. 임시 유니코드 문자열이 내부적으로 만들어지는 경우가 많기 때문에 이러한 함수의 ANSI 버전은 유니코드에 비해 효율성이 떨어집니다. 효율성을 위해 가능한 경우 유니코드 버전을 사용합니다.

참고 항목

Visual Studio .NET에서 구현된 향상된 조회 동작으로 인해 이전 릴리스에서 컴파일되었을 수 있는 코드 bstr = L"String2" + bstr;는 대신 다음과 같이 bstr = CStringW(L"String2") + bstr구현되어야 합니다.

사용할 때 주의 사항 목록은 다음을 사용하여 CComBSTR프로그래밍을 CComBSTR참조하세요.

요구 사항

머리글: atlbase.h

CComBSTR::Append

의 BSTR 멤버 중 하나 lpsz 또는 해당 멤버 bstrSrcm_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();

매개 변수

bstrSrc
[in] CComBSTR 추가할 개체입니다.

ch
[in] 추가할 문자입니다.

lpsz
[in] 추가할 0으로 끝나는 문자열입니다. 버전을 통해 오버로드 또는 ANSI 문자열을 통해 LPCOLESTR 유니코드 문자열을 LPCSTR 전달할 수 있습니다.

nLen
[in] 추가할 문자 lpsz 수입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

설명

ANSI 문자열은 추가되기 전에 유니코드로 변환됩니다.

예시

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

지정된 BSTR m_str값을 .에 추가합니다.

HRESULT AppendBSTR(BSTR p) throw();

매개 변수

p
[in] 추가할 A BSTR 입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

설명

일반 와이드 문자 문자열을 이 메서드에 전달하지 마세요. 컴파일러가 오류를 catch할 수 없으며 런타임 오류가 발생합니다.

예시

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

변환하지 않고 지정된 바이트 수를 추가합니다 m_str .

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

매개 변수

lpsz
[in] 추가할 바이트 배열에 대한 포인터입니다.

p
[in] 추가할 바이트 수입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

예시

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

개체에 저장된 기존 문자열을 CComBSTR 해제한 다음 BSTR safearray에 있는 각 요소의 첫 번째 문자에서 만들어 개체에 CComBSTR 연결합니다.

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

매개 변수

pSrc
[in] 문자열을 만드는 데 사용되는 요소를 포함하는 safearray입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

CComBSTR::AssignBSTR

에 할당 BSTR m_str합니다.

HRESULT AssignBSTR(const BSTR bstrSrc) throw();

매개 변수

bstrSrc
[in] 현재 CComBSTR 개체에 할당할 BSTR입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

CComBSTR::Attach

멤버srcBSTR .로 CComBSTR 설정하여 개체에 m_str 연결합니다.

void Attach(BSTR src) throw();

매개 변수

src
[in] BSTR 개체에 연결할 대상입니다.

설명

일반 와이드 문자 문자열을 이 메서드에 전달하지 마세요. 컴파일러가 오류를 catch할 수 없으며 런타임 오류가 발생합니다.

참고 항목

이 메서드는 NULL이 아닌 경우 m_str 어설션됩니다.

예시

// 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

배열의 각 요소가 개체의 문자인 0부터 시작하는 1차원 safearray를 CComBSTR 만듭니다.

HRESULT BSTRToArray(LPSAFEARRAY* ppArray) throw();

매개 변수

ppArray
[out] 함수의 결과를 보관하는 데 사용되는 safearray에 대한 포인터입니다.

Return Value

S_OK 성공 또는 표준 HRESULT 오류 값입니다.

CComBSTR::ByteLength

종료 null 문자를 제외한 바이트 m_str수를 반환합니다.

unsigned int ByteLength() const throw();

Return Value

멤버의 길이( m_str 바이트)입니다.

설명

이면 m_str 0을 반환합니다 NULL.

예시

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

unsigned int len = bstrTemp.ByteLength();

ATLASSERT(len == 22);   

CComBSTR::CComBSTR

생성자입니다. 기본 생성자는 멤버를 .로 m_str 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)

매개 변수

nSize
[in] 복사 sz 할 문자 수 또는 에 대한 초기 크기(문자 수)입니다 CComBSTR.

sz
[in] 복사할 문자열입니다. 유니코드 버전은 LPCOLESTR을 지정합니다. ANSI 버전은 LPCSTR을 지정합니다.

pSrc
[in] 복사할 문자열입니다. 유니코드 버전은 LPCOLESTR을 지정합니다. ANSI 버전은 LPCSTR을 지정합니다.

src
[in] CComBSTR 개체입니다.

guid
[in] 구조체에 대한 참조입니다 GUID .

설명

복사 생성자는 BSTR 멤버src의 복사본으로 설정합니다m_str. REFGUID 생성자는 GUID를 사용하여 StringFromGUID2 문자열로 변환하고 결과를 저장합니다.

다른 생성자는 m_str을 지정된 문자열의 복사본으로 설정합니다. 값을 nSize전달하면 문자만 nSize 복사되고 Null 문자가 종료됩니다.

CComBSTR은 이동 의미 체계를 지원합니다. 이동 생성자(rvalue 참조(&&)를 가져오는 생성자)를 사용하면 개체 복사에 대한 오버헤드 없이 인수로 전달한 이전 개체와 동일한 기본 데이터를 사용하는 새 개체를 만들 수 있습니다.

소멸자는 m_str에서 가리키는 문자열을 해제합니다.

예시

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

소멸자입니다.

~CComBSTR();

설명

소멸자는 m_str에서 가리키는 문자열을 해제합니다.

CComBSTR::Copy

의 복사본을 할당하고 반환합니다 m_str.

BSTR Copy() const throw();

Return Value

멤버의 복사본입니다 m_str . m_strNULL이면 NULL를 반환합니다.

예시

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

매개 변수를 통해 복사본 m_str 을 할당하고 반환합니다.

HRESULT CopyTo(BSTR* pbstr) throw();

HRESULT CopyTo(VARIANT* pvarDest) throw();

매개 변수

pbstr
[out] 이 메서드에서 할당한 문자열을 반환할 주소 BSTR 입니다.

pvarDest
[out] 이 메서드에서 할당한 문자열을 반환할 주소 VARIANT 입니다.

Return Value

복사본의 성공 또는 실패를 나타내는 표준 HRESULT 값입니다.

설명

이 메서드를 호출한 후에는 VARIANT 가리키는 pvarDest 형식이 VT_BSTR됩니다.

예시

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 개체에서 CComBSTR 분리하고 .로 NULL설정합니다m_str.

BSTR Detach() throw();

Return Value

BSTR 개체와 연결된 개체입니다CComBSTR.

예시

// 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

멤버를 해제 m_str 합니다.

void Empty() throw();

예시

CComBSTR bstr(OLESTR("abc"));

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

CComBSTR::Length

종료 null 문자를 m_str제외한 문자 수를 반환합니다.

unsigned int Length() const throw();

Return Value

멤버의 길이입니다 m_str .

예시

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

unsigned int len = bstrTemp.Length();

ATLASSERT(len == 11);

CComBSTR::LoadString

지정된 nID 문자열 리소스를 로드하고 이 개체에 저장합니다.

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

매개 변수

Windows SDK에서 참조 LoadString 하세요.

Return Value

문자열이 성공적으로 로드되었는지를 반환 TRUE 하고, 그렇지 않으면 반환합니다 FALSE.

설명

첫 번째 함수는 매개 변수를 통해 사용자가 식별한 모듈에서 리소스를 로드합니다 hInst . 두 번째 함수는 이 프로젝트에 사용되는 파생 개체와 CComModule연결된 리소스 모듈에서 리소스를 로드합니다.

예시

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

BSTR 개체와 연결된 개체를 CComBSTR 포함합니다.

BSTR m_str;

예시

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

개체를 CComBSTR .에 캐스팅 BSTR합니다.

operator BSTR() const throw();

설명

매개 변수가 있는 BSTR함수에 개체를 전달할 CComBSTR 수 있습니다.

예시

CComBSTR::m_str에 대한 예를 참조하세요.

CComBSTR::operator !

문자열이 .인지 여부를 BSTR 확인합니다 NULL.

bool operator!() const throw();

Return Value

멤버가 m_str 면 반환하고NULL, 그렇지 않으면 .를 FALSE반환 TRUE 합니다.

설명

이 연산자는 빈 문자열이 NULL 아닌 값만 확인합니다.

예시

// 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 !=

의 논리적 반대 부분을 반환합니다 operator ==.

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

매개 변수

bstrSrc
[in] CComBSTR 개체입니다.

pszSrc
[in] 0으로 끝나는 문자열입니다.

nNull
[in] NULL이어야 합니다.

Return Value

TRUE 비교할 항목이 개체와 같지 CComBSTR 않으면 반환하고, 그렇지 않으면 반환합니다FALSE.

설명

CComBSTRs는 사용자의 기본 로캘 컨텍스트에서 텍스트로 비교됩니다. 최종 비교 연산자는 포함된 문자열을 .에 대해 NULL비교합니다.

CComBSTR::operator &

멤버에 저장된 주소를 BSTR 반환합니다 m_str .

BSTR* operator&() throw();

설명

CComBstr operator & 에는 메모리 누수 식별에 도움이 되는 특수 어설션이 연결되어 있습니다. 프로그램은 멤버가 초기화될 때 어설션 m_str 됩니다. 이 어설션은 프로그래머가 첫 번째 할당m_str을 해제하지 않고 멤버에 새 값을 할당하는 데 사용하는 & operator 상황을 식별하기 위해 m_str 만들어졌습니다. 같NULL으면 m_str 프로그램에서는 m_str 아직 할당되지 않았다고 가정합니다. 이 경우 프로그램은 어설션되지 않습니다.

이 어설션은 기본적으로 사용하도록 설정되지 않습니다. 이 어설션을 사용하도록 정의 ATL_CCOMBSTR_ADDRESS_OF_ASSERT 합니다.

예시

#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 +=

개체에 문자열을 CComBSTR 추가합니다.

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

매개 변수

bstrSrc
[in] CComBSTR 추가할 개체입니다.

pszSrc
[in] 추가할 0으로 끝나는 문자열입니다.

설명

CComBSTRs는 사용자의 기본 로캘 컨텍스트에서 텍스트로 비교됩니다. 비교는 LPCOLESTR 각 문자열의 원시 데이터를 사용하여 memcmp 수행됩니다. 비교는 LPCSTR 임시 유니코드 복사본 pszSrc 이 만들어지면 동일한 방식으로 수행됩니다. 최종 비교 연산자는 포함된 문자열을 .에 대해 NULL비교합니다.

예시

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 <

문자열과 CComBSTR 비교합니다.

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

Return Value

비교할 항목이 개체보다 CComBSTR 작으면 반환 TRUE 하고, 그렇지 않으면 반환합니다FALSE.

설명

비교는 사용자의 기본 로캘을 사용하여 수행됩니다.

CComBSTR::operator =

멤버를 복사본 m_str 으로 pSrc 설정하거나 해당 멤버srcBSTR 복사본으로 설정합니다. 이동 할당 연산자는 복사하지 않고 이동합니다 src .

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

설명

매개 변수는 pSrc 유니코드 버전 또는 LPCSTR ANSI 버전을 지정 LPCOLESTR 합니다.

예시

CComBSTR::Copy에 대한 예를 참조하세요.

CComBSTR::operator ==

문자열과 CComBSTR 비교합니다. CComBSTRs는 사용자의 기본 로캘 컨텍스트에서 텍스트로 비교됩니다.

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

매개 변수

bstrSrc
[in] CComBSTR 개체입니다.

pszSrc
[in] 0으로 끝나는 문자열입니다.

nNull
[in] 이어야 NULL합니다.

Return Value

TRUE 비교할 항목이 개체와 같은 CComBSTR 지 반환하고, 그렇지 않으면 반환합니다FALSE.

설명

최종 비교 연산자는 포함된 문자열을 .에 대해 NULL비교합니다.

CComBSTR::operator >

문자열과 CComBSTR 비교합니다.

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

Return Value

TRUE 비교할 항목이 개체보다 CComBSTR 크면 반환하고, 그렇지 않으면 반환합니다FALSE.

설명

비교는 사용자의 기본 로캘을 사용하여 수행됩니다.

CComBSTR::ReadFromStream

지정된 스트림에 m_str BSTR 포함된 멤버로 멤버를 설정합니다.

HRESULT ReadFromStream(IStream* pStream) throw();

매개 변수

pStream
[in] 데이터를 포함하는 스트림의 IStream 인터페이스에 대한 포인터입니다.

Return Value

표준 HRESULT 값입니다.

설명

ReadToStream 에서는 현재 위치에 있는 스트림의 내용이 호출로 작성된 데이터 형식과 호환되어야 합니다 WriteToStream.

예시

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

포함된 문자열을 소문자로 변환합니다.

HRESULT ToLower() throw();

Return Value

표준 HRESULT 값입니다.

설명

변환이 수행되는 방법에 대한 자세한 내용은 참조 CharLowerBuff 하세요.

CComBSTR::ToUpper

포함된 문자열을 대문자로 변환합니다.

HRESULT ToUpper() throw();

Return Value

표준 HRESULT 값입니다.

설명

변환이 수행되는 방법에 대한 자세한 내용은 참조 CharUpperBuff 하세요.

CComBSTR::WriteToStream

멤버를 m_str 스트림에 저장합니다.

HRESULT WriteToStream(IStream* pStream) throw();

매개 변수

pStream
[in] 스트림의 IStream 인터페이스에 대한 포인터입니다.

Return Value

표준 HRESULT 값입니다.

설명

함수를 BSTR 사용하여 ReadFromStream 스트림의 내용에서 다시 만들 수 있습니다.

예시

//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;
}

참고 항목

클래스 개요
ATL 및 MFC 문자열 변환 매크로