locked
C++ COM dll returned string is empty in C# caller when the string is long RRS feed

  • Question

  • I have created a C++ COM dll and used it in a c# code. It has a function whose signature is as follows:

    STDMETHODIMP CTranslatorCOMWrapper::translateBunch(BSTR bunch, BSTR option, VARIANT_BOOL transliterate, BSTR* translation)


    I use BSTR* to return string from this function.

    I have imported the DLL into C# project using "add reference" to COM DLLs, and it has generated the following code automatically.

    [DispId(2)]
    [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
    [return: MarshalAs(UnmanagedType.BStr)]
    string ITranslatorCOMWrapper.translateBunch([MarshalAs(UnmanagedType.BStr), In] string bunch, [MarshalAs(UnmanagedType.BStr), In] string option, bool transliterate);

    I have called the function in c# code as follows:

    string result = translatorWrapper.translateBunch(bunch, option, transliterate);

    This works fine when the returned string is not too long, but when the returned string be long, nothing will be assigned to variable "result" and it will contain a empty string.

    Could anyone help me solve the problem or Where should I ask this question?

    Regards

    Thursday, February 7, 2013 9:09 AM

Answers

All replies