Solved

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

Posted on 2002-03-28
6
362 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
6 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6902752
Use

STDMETHODIMP XYZ::get_Path(BSTR AppName, BSTR *pVal)
{
char*p = "HELLO";

*pVal = SysAllocStringByteLen ( p, lstrlen ( p));

}
0
 

Author Comment

by:goodami
ID: 6902790
Thanks jkr,

It Works but now when I call this function from a VB client ,and try to retrieve the value its coming out to be junk.

I am trying like this in VB:

Private Sub Command1_Click()
Dim x As New TESTDLL
Dim y As String

y = x.Path("XY")
msgbox(y)
End Sub

If I print the message using AfxMessageBox("Hello");
it works fine but here I get ????? as message box in VB.Can you pls help me
0
 

Author Comment

by:goodami
ID: 6902817
Thanks jkr,

It Works but now when I call this function from a VB client ,and try to retrieve the value its coming out to be junk.

I am trying like this in VB:

Private Sub Command1_Click()
Dim x As New TESTDLL
Dim y As String

y = x.Path("XY")
msgbox(y)
End Sub

If I print the message using AfxMessageBox("Hello");
it works fine but here I get ????? as message box in VB.Can you pls help me
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:goodami
ID: 6902850
Thanks jkr,

It Works but now when I call this function from a VB client ,and try to retrieve the value its coming out to be junk.

I am trying like this in VB:

Private Sub Command1_Click()
Dim x As New TESTDLL
Dim y As String

y = x.Path("XY")
msgbox(y)
End Sub

If I print the message using AfxMessageBox("Hello");
it works fine but here I get ????? as message box in VB.Can you pls help me
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 6902930
How about trying this:
STDMETHODIMP XYZ::get_Path(BSTR AppName, BSTR *pVal)
{
 //Retieved a chsr * value lets say "Hello".
 char *ptr = "Hello";
 int len = _tcslen(ptr);
#ifdef _UNICODE
 *pVal = ::SysAllocStringLen(ptr, len);
#else
 int nLen=MultiByteToWideChar(CP_ACP,0,ptr,len,NULL,NULL);
 *pVal = ::SysAllocStringLen(ptr, nLen);
 MultiByteToWideChar(CP_ACP, 0, ptr, len, *pVal, nLen);
#endif

}
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 6906406
It could be as simple as

STDMETHODIMP XYZ::get_Path(BSTR AppName, BSTR *pVal)
{
TCHAR *p = _T("HELLO");
USES_CONVERSION;
*pVal = SysAllocString (T2OLE(p));
}
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

752 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