Microsoft Specific
A _bstr_t object encapsulates the BSTR data type. The class manages resource allocation and deallocation through function calls to SysAllocString and SysFreeString and other BSTR APIs when appropriate. The _bstr_t class uses reference counting to avoid excessive overhead.
Constructs a _bstr_t object. |
Copies a BSTR into the BSTR wrapped by a _bstr_t. | |
Links a _bstr_t wrapper to a BSTR. | |
Constructs a copy of the encapsulated BSTR. | |
Returns the BSTR wrapped by a _bstr_t and detaches the BSTR from the _bstr_t. | |
Points to the BSTR wrapped by a _bstr_t. | |
Points to the beginning of the BSTR wrapped by the _bstr_t. | |
Returns the number of characters in the _bstr_t. |
Assigns a new value to an existing _bstr_t object. | |
Appends characters to the end of the _bstr_t object. | |
Concatenates two strings. | |
Checks if the encapsulated BSTR is a NULL string. | |
Compares two _bstr_t objects. | |
Extract the pointers to the encapsulated Unicode or multibyte BSTR object. |
// _bstr_t_Assign.cpp
#include <stdio.h>
{
// creates a _bstr_t wrapper
_bstr_t bstrWrapper;
bstrWrapper = "some text";
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
BSTR bstr = bstrWrapper.Detach();
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
// "some text"
wprintf_s(L"bstr = %s\n", bstr);
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
bstrWrapper.Assign(bstr);
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
SysFreeString(bstr);
bstr= SysAllocString(OLESTR("Yet another string"));
// two wrappers, one BSTR
_bstr_t bstrWrapper2 = bstrWrapper;
bstr = 0;
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
wprintf_s(L"bstrWrapper2 = %s\n",
static_cast<wchar_t*>(bstrWrapper2));
_snwprintf_s(bstrWrapper.GetBSTR(), 100, bstrWrapper.length(),
L"changing BSTR");
wprintf_s(L"bstrWrapper = %s\n",
static_cast<wchar_t*>(bstrWrapper));
wprintf_s(L"bstrWrapper2 = %s\n",
static_cast<wchar_t*>(bstrWrapper2));
}
결과값
bstrWrapper = some text bstrWrapper = (null) bstr = some text bstrWrapper = SysAllocedString bstrWrapper = some text bstrWrapper = Yet another string bstrWrapper2 = some text bstrWrapper = changing BSTR bstrWrapper2 = some text
'기타 언어 > C# & MFC' 카테고리의 다른 글
CodeProject The Ultimate TCP-IP Home Page_ Free source code and programming (2) | 2008.12.07 |
---|---|
이벤트를 html 에서 엑세스 하고 싶을때 javascript 와 vbscript 소스 (0) | 2008.09.04 |
ADO : AddNew Method Example (0) | 2007.09.15 |
ASP Component 작성 나만의 표준작성방법 (0) | 2007.09.14 |
ADO _Recordset 예제 (0) | 2007.09.14 |
printf와 scanf (0) | 2007.09.13 |
Asp Component ATL 로 만들기 (0) | 2007.09.05 |
ATL에서 문자열사용하기위한 방법들 (1) | 2007.08.31 |