CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    32

    SysReAllocString - newbie confused!

    Hi everyone,

    I've written a class and put a COM wrapper around it. The class (and COM) takes a BSTR as an input parameter which is modified and then sent back out to whatever called the COM. I've declared the BSTR as [in, out] in the IDL and I'm using:

    SysReAllocString(&strParameters, (OLECHAR*)chstrParams);

    to alter the BSTR strParameters that is the input to the COM. I then have to call delete[] on the char* chstrParams. At this point the BSTR still appears to be valid, but when the COM exits I get an unhandled exception error. Am I dealing with returning the altered BSTR correctly and the re-allocation of the string?

    Thanks for your help.

  2. #2
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: SysReAllocString - newbie confused!

    BSTR cannot be the [in,out] parameter. Only BSTR*.

    Code:
    HRESULT cX::funcX(... /*[in,out]*/ BSTR * strParameters,...)
    {...
    SysReAllocString( strParameters, (OLECHAR*)chstrParams);
    ...
    }
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

  3. #3
    Join Date
    May 2004
    Posts
    45

    Re: SysReAllocString - newbie confused!

    It's always good to think in VB first and then define the IDL interface to your COM DLL.

    For instance, if you have a "(ByRef P As String)" (or "P As String") you'll translate it as ([in,out]BSTR *P); and if you have a "(ByVal Q As String)" you'll translate it as ([in]BSTR Q);

    It's almost mechanical, but you need to get used to that.

    You can even try writing an empty VB DLL with the desired interface, and use OLEVIEW to check exactly how you need to write the IDL interface in your COM DLL. OLEVIEW is a good learning tool.

  4. #4
    Join Date
    Mar 2004
    Posts
    32

    Re: SysReAllocString - newbie confused!

    Thanks guys I've taken what you've said on board and managed to get everything going now. Cheers!

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