Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

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

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
goodami
Asked:
goodami
1 Solution
 
jkrCommented:
Use

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

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

}
0
 
goodamiAuthor Commented:
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
 
goodamiAuthor Commented:
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
Technology Partners: 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!

 
goodamiAuthor Commented:
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
 
pagladasuCommented:
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
 
naveenkohliCommented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now