CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    37

    [COM] How to get BSTR from COM

    I want to receive string from COM component.

    <IDL>
    HRESULT Test([out, string] BSTR* abc);

    <Test Server>
    HRESULT Test(/*out, string*/ BSTR* abc)
    {
    _bstr_t bstrResult(abc, false);
    bstrResult = L"This is a test";
    abc = (BSTR)bstrResult;
    return S_OK;
    }

    <Test Client : VB>
    Dim obj as new WebCom
    Dim s as String

    obj.Test s

    ---------------

    But, this code occurs error (in MTS).
    How COM server pass BSTR string to client?


    A programmer who loves Goethe.

  2. #2
    Join Date
    May 1999
    Posts
    48

    Re: [COM] How to get BSTR from COM

    See SysAllocString, SysFreeString, OLE2T, T2OLE, USES_CONVERSION
    Sincerely, Mihai


  3. #3
    Join Date
    Apr 1999
    Posts
    27

    Re: [COM] How to get BSTR from COM

    Since _bstr_t performs all of your allocation for you I believe you can do something like this:

    HRESULT Test(/*out, string*/ BSTR* abc)
    {
    _bstr_t bstrResult;
    bstrResult = L"This is a test";
    abc = bstrResult.copy();
    return S_OK;
    }




  4. #4
    Join Date
    Apr 1999
    Location
    Gothenburg, Sweden
    Posts
    10

    Re: [COM] How to get BSTR from COM

    try s = obj.Test


  5. #5
    Join Date
    Apr 1999
    Posts
    31

    Re: [COM] How to get BSTR from COM

    _bstr_t bstrResult(abc, false);
    bstrResult = L"This is a test"; // Wrong

    Try to do this.

    wchar_t wbst[]= L"This is a test";
    abc = SysAllocString(wbst);


    I hope this will help you.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured