在 C++ 应用程序上使用 C# DLL 的问题

问题描述

我一直在使用我为我正在用 C++ 编写的项目提供的文件。使用 CLR(公共语言运行时),我能够引用 DLL 并使用我需要的函数。当我尝试将字符串作为参数传递给上述函数时,问题就出现了。该错误显示函数仅将 System::string ^Foo 作为参数。我已阅读有关此语法的文章,它被确定为 Microsoft 的 C++/CLI 的一部分(因为 DLL 文件不是用 C++ 编写的)。我的一个朋友正在从事类似的项目,仅使用 C#,他能够按预期传递字符串变量,在需要输入的文本后附加一个变量。代码摘录如下所示。

string Foo; //This string would obvIoUsly have something to pass.
Function function1;
function1.Command(Foo); //A function provided by the DLL. This would throw an error as it does not accept the string variable.
function1.Command("loadasset(etc)");  //This is the only kind of parameter it would allow,however,some input would be dynamic or changed via user input,and the values must be changed.

我尝试了一些解决方案,例如在文本后附加字符串,或使用“%s”并添加我希望输入的变量,但都没有成功。任何关于我如何能够传递字符串变量的想法都值得赞赏。我使用的是最新版本的 Visual Studio IDE。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)