Solved

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

Posted on 2002-03-28
6
361 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
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…
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…

713 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