共用方式為


CStringT::AllocSysString

將型別 BSTR 的 Automation 相容的資料並複製 CStringT 物件的內容放入其中,包括結束的 null 字元。

BSTR AllocSysString() const;

傳回值

新配置的字串。

備註

在 MFC 程式中,則為,如果沒有足夠的記憶體 CMemoryException 類別 存在,則會擲回。 在 ATL 程式, CAtlException 擲回。 這個函式通常用來自動化的字串。

通常,這個字串,如果傳遞給 COM 函式做為 參數,那麼這個要求呼叫端釋放字串。 您可以使用 SysFreeString,這可以 Windows SDK,如中所述。 如需詳細資訊,請參閱 配置和釋放 BSTR 的記憶體。

如需在 視窗中可用的配置功能的詳細資訊,請參閱 Windows SDK的 SysAllocString

範例

以下範例將說明 CStringT::AllocSysString 的用法。

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;
CAtlString str(_T("This is a test string!"));
BSTR bstr = str.AllocSysString();

// bstr now contains "This is a test string!", and can be
// passed to any OLE function requiring a BSTR.
// Normally, if you pass the BSTR, you will
// need to free the string after returning from the function call.   

需求

Header: cstringt.h

請參閱

參考

CStringT 類別