Solved

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

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

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
Use

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

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

}
0
 

Author Comment

by:goodami
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:goodami
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now