Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从C+调用C#函数(字符串作为out参数)+;_C#_C++_.net_Winapi_Com - Fatal编程技术网

如何从C+调用C#函数(字符串作为out参数)+;

如何从C+调用C#函数(字符串作为out参数)+;,c#,c++,.net,winapi,com,C#,C++,.net,Winapi,Com,我在一个项目中工作,因为我有一个本机(c++)应用程序和一个COM DLL(c#.Net)。 我的要求是,从我的本机应用程序中,我想调用COM DLL中的函数,该函数返回字符串(out参数) 下面是代码 C#COM代码 [ComVisible(true)] public interface IUserDetais { bool GetUserConfigData(out string configData); } [ ComVisible(true), ClassInterface(C

我在一个项目中工作,因为我有一个本机(c++)应用程序和一个COM DLL(c#.Net)。 我的要求是,从我的本机应用程序中,我想调用COM DLL中的函数,该函数返回字符串(out参数)

下面是代码

C#COM代码

[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++代码

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();
}

可以告诉我如何在C++代码中调用GETUsRealDebug数据。 更新:


C++不是.Net代码。它是C++ Win32或本机代码。< /P>检查这一点-让智能感知帮助你落入成功的坑中,它告诉你很多关于如何正确调用这个方法。您需要两个参数,一个BSTR*和一个VARIANT\u BOOL*。不要忘记检查HRESULT返回值和SysFreeString()以释放字符串。请将定义修改为GetUserConfigData([Runtime::InteropServices::Out]string^%configData),因为您提出了错误的问题。您没有尝试从非托管代码调用托管代码。您正试图从可能使用COM接口的编程语言访问与语言无关的COM对象。这个问题的答案与你所问问题的答案大不相同。