Solved

How to get the BSTR value set through  property in ATL COM Dll

Posted on 2002-03-28
2
520 Views
Last Modified: 2013-11-25
Hi,

I have created a property in my COM Dll and the property type is BSTR.I have retrieved a char * and
want to get it thru property .How to do that ????

e.g:
STDMETHODIMP XYZ::get_Path(BSTR AppName, BSTR *pVal)
{
 //Retieved a chsr * value lets say "Hello".
 How can I get it as return value in pVal????
Can I Type cast it.If yes,how???
}
0
Comment
Question by:goodami
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Robalitoru earned 20 total points
ID: 6903092
Try this:
        USES_CONVERSION;
        *pVal=A2BSTR( yourChar );

0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 6905049
Here's a little help class that helps with BSTR's:

#define BSTR_MAX_STRING   1024

// Helper class for BSTR processing
class CBStr
{
public:
  CBStr(LPCTSTR lpszValue=NULL);
  virtual ~CBStr();
  operator BSTR() { return m_bstr; };
  operator BSTR*() { return &m_bstr; };
  operator CString();
  BSTR m_bstr;
};

CBStr::CBStr(LPCTSTR lpszValue)
{
  USES_CONVERSION;

  m_bstr = lpszValue ? ::SysAllocString(T2COLE(lpszValue)) : NULL;
}

CBStr::~CBStr()
{
  if (m_bstr)
    ::SysFreeString(m_bstr);
}

CBStr::operator CString()
{
  CString str;

  WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) m_bstr, -1,
    str.GetBuffer(SS_MAX_STRING),
    SS_MAX_STRING, NULL, NULL);

  str.ReleaseBuffer();

  return str;
}

// Here's how to you it

CBStr bstr(_T("Test test"));
CString str;

str = bstr;

Good Luck,
Steve


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question