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?
 
Gus012498Connect With a Mentor Commented:
You can simply create a BSTR with the

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

function.

Regards,

Gus
0
 
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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
All Courses

From novice to tech pro — start learning today.