?
Solved

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

Posted on 2002-03-28
2
Medium Priority
?
525 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 60 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

764 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