CString to BSTR*

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I have a Function:

STDMETHODIMP CMessageServiceAdmin::GetStorePath(VARIANT inEntryID, BSTR* bstr)


I have a CString whose contents are aching to be "inside" the BSTR*

Thanks!
LVL 1
jhattinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gus012498Commented:
You can simply create a BSTR with the

BSTR SysAllocStringByteLen(
  char FAR*  psz,    
  unsigned int  len  
);
 

function.

Regards,

Gus
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhattinghAuthor Commented:
Please use my code to answer the question. I know my question probably seems ambiguous - sorry.

e.g.

BSTR bstrData=strPath.AllocSysString();
bstr = &bstrData;

(This is something I have tried prior to posting this question on EE, but doesn't seem to work)
0
Gus012498Commented:
One more question:

Does your code look like this:

BSTR bstrData=strPath.AllocSysString();
bstr = &bstrData;

and then you call
CMessageServiceAdmin::GetStorePath(VARIANT inEntryID, BSTR* bstr).

I could not find more information about the CMessageServiceAdmin class. But GetStorePath sounds like that this function returns the store path. I guess that you would like to set the storing path.

Am i right?

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

jhattinghAuthor Commented:
The function:

CMessageServiceAdmin::GetStorePath(VARIANT inEntryID, BSTR* bstr)

is my own function in a COM program that I am writing. the BSTR* is the return value, and in a VB app there is the following code:

Private Sub Command3_Click()

    Dim cStore As MAPI.InfoStore
    Dim sStoreID, sPath As String
   
    Set cStore = cStores.Item(List1.ListIndex + 1)
    sStoreID = cStore.ID
   
    Dim MsgAdmin As New MessageServiceAdmin
    sPath = MsgAdmin.GetStorePath(sStoreID)
    MsgBox sPath
   
End Sub

Inside (my) COM app, I get the path ok (in a CString), and now I want to say, "Make the data pointed to by the BSTR* supplied by the function, equal to the data that my CString holds"

Feel free to make me explain further if I'm still unclear..

LWJason

0
Gus012498Commented:
Could you please post the interface definition of the CMessageServiceAdmin class?

Tnx

Gus
0
Gus012498Commented:
Could you please post the interface definition of the CMessageServiceAdmin class?

Tnx

Gus
0
jhattinghAuthor Commented:
// MsgServiceAdmin.idl : IDL source for MsgServiceAdmin.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (MsgServiceAdmin.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
      [
            object,
            uuid(4B82F9D5-C375-11D3-803C-00805FC1DE10),
            dual,
            helpstring("IMessageServiceAdmin Interface"),
            pointer_default(unique)
      ]
      interface IMessageServiceAdmin : IDispatch
      {
            [id(1), helpstring("method RemoveServiceByName")] HRESULT RemoveServiceByName(VARIANT vName);
            [id(2), helpstring("method RemoveByEntryID")] HRESULT RemoveByEntryID(VARIANT vEntryID);
            [id(3), helpstring("method GetStorePath")] HRESULT GetStorePath(VARIANT inEntryID, [out,retval] BSTR* bstr);
      };

[
      uuid(4B82F9C8-C375-11D3-803C-00805FC1DE10),
      version(1.0),
      helpstring("MsgServiceAdmin 1.0 Type Library")
]
library MSGSERVICEADMINLib
{
      importlib("stdole32.tlb");
      importlib("stdole2.tlb");

      [
            uuid(4B82F9D6-C375-11D3-803C-00805FC1DE10),
            helpstring("MessageServiceAdmin Class")
      ]
      coclass MessageServiceAdmin
      {
            [default] interface IMessageServiceAdmin;
      };
};
0
Gus012498Commented:
Ok: i guess that this happens:

BSTR bstrData=strPath.AllocSysString();
bstr = &bstrData;

bstr points to the location where the return value is expected.

try

*bstr = bstrData;

instead of

bstr = &bstrData;

Regards,

Gus
0
jhattinghAuthor Commented:
THANKS DUDE!!!!
0
jhattinghAuthor Commented:
Q-L!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.