Click to See Complete Forum and Search --> : BSTR Formatting


AltPluzF4
August 3rd, 2005, 05:23 AM
I'm not having much luck with these BSTRs, can someone give me a reference where I can learn how to format / compare / find / etc BSTRs...

Mainly, I am looking for a way to compare 2 BSTRs with functions like CString's Left() and Right()
So I can check for partial matches.

Thanks.

golanshahar
August 3rd, 2005, 03:27 PM
if you need CString functionality why dont you construct CString from BSTR?


BSTR bStr(L"Test Str"); // create dummy bstr string
CString str( bStr );


Cheers

AltPluzF4
August 3rd, 2005, 04:05 PM
I didn't have MFC support... I gave up and just redid the project with MFC support so it's pretty much done now :-/

Thanks anyway!

humptydumpty
August 4th, 2005, 12:17 AM
So add MFC Support to your project and try this.and if you already had a ATL project manually also you can add MFC support to your project
even if you are working with ATL you can Add MFC support to your project just got through this in MSDN

or try this

Add the following #include directives to StdAfx.h prior to including Atlbase.h:
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation extensions



Follow steps 1 to 3 from above.
Move the code in the AppWizard-generated DllMain's
DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH to the CMyApp's
InitInstance and ExitInstance and remove the DllMain as follows:

BOOL CMyApp::InitInstance()
{
_Module.Init(ObjectMap, m_hInstance);
return CWinApp::InitInstance();
}

int CMyApp::ExitInstance()
{
// MFC's class factories registration is
// automatically revoked by MFC itself.
if (m_bRun)
_Module.RevokeClassObjects();
}



Add the following line of code to the beginning of every member function of a COM interface, window procedure and exported function:
AFX_MANAGE_STATE(AfxGetStaticModuleState());

For additional information, please see the following article in the Microsoft Knowledge Base:


or just check out in MSDN
for
Add MFC Support to an ATL Project you can get all information here.after that very easily you can use BSTR with your CString

sam_kannan
August 4th, 2005, 01:41 AM
_bstr_t encapsulates BSTR and you can extract the underlying c string from _bstr_t. Check out MSDN for _bstr_t

S.Kannan

Arjay
August 4th, 2005, 03:06 AM
Also, check out ATL::CComBSTR.

Arjay

stober
August 4th, 2005, 07:17 AM
I always find google to be my best programming buddy -- you get answeres to many common questions without waiting for someone to answer on forums.

http://www.google.com/search?hl=en&q=BSTR&btnG=Google+Search

NoHero
August 4th, 2005, 07:45 AM
std::wstring or std::string and use the <algortithm>