0

I am working in a project in that i have a native(c++) application and a COM DLL(c# .Net). My requirement is, form my native application I want to call a function in COM DLL, and that function returns string(out parameter).

Bellow is the code

C# COM Code....

[ComVisible(true)]
public interface IUserDetais
{
    bool GetUserConfigData(out string configData);
}

[
ComVisible(true),
ClassInterface(ClassInterfaceType.None),
GuidAttribute("GUID"),
]
public class AppUserDetais : IUserDetais
{
    public bool GetUserConfigData(out string configData)
    {
        configData = "Some JSON content.";
        reurn true;
    }
}

C++ code

void GetUserInfo(IUserDetais* pUserInfo)
{
    // TODO, How to call the function. what should be the signature in C#(the out string length can vary and how to delete the memory allocated).
    //pUserInfo->GetUserConfigData();
}

Can any one tell me how to to call GetUserConfigData in C++ code.

Updated:

C++ is not .Net code. it is C++ win32 or native code.

4
  • Check this - stackoverflow.com/questions/186477/… Commented Nov 4, 2015 at 9:37
  • Do let IntelliSense help you to fall into the pit of success, it tells you a lot about how to call this method properly. You need two arguments, a BSTR* and a VARIANT_BOOL*. Don't forget to check the HRESULT return value and SysFreeString() to release the string. Commented Nov 4, 2015 at 10:05
  • Modify definition as GetUserConfigData([Runtime::InteropServices::Out] string^% configData) Commented Nov 4, 2015 at 10:24
  • You have asked the wrong question. You are not trying to call managed code from unmanaged code. You are trying to access a language-neutral COM object from a programming language, that can consume COM interfaces. The answer to this question is very different from the answer to the question you asked. Commented Nov 5, 2015 at 13:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.