gpt4 book ai didi

传递给 C++ CLI 的 C# 字符串

转载 作者:太空狗 更新时间:2023-10-30 01:21:20 25 4
gpt4 key购买 nike

在 S/O 上没有看到我要找的东西。我有一个 C# 应用程序需要将值传递给 C++ CLI 应用程序(托管代码)。 (我真的只需要弄清楚字符串传递)

C#我有

double xCoordinate = 4820.85;
double yCoordinate = 9792.93;
string stringName = "My string stuff";
abc.Highlight(xCoordinate, yCoordinate, stringName);

在 C++/CLI 中,我希望接收字符串(double 似乎没问题)

我阅读了以下内容

C++ --> std::wstring
or in C++ --> extern "C" __declspec void GetString( char* buffer, int* bufferSize );
C# --> void GetString( StringBuilder buffer, ref int bufferSize );

也许

System::String^
const char *

?因此,我似乎只想将字符串从 C# 发送到 C++/CLI,虽然它看起来很简单,但我没有接受过 C++ 培训,并且查找 Interop/marshalling 的示例似乎并不那么简单。

最佳答案

如果你使用的是C++/CLI,你可以直接使用String:

void Highlight(double xCoordinate, double yCoordinate, String^ name)
{
//...

关于传递给 C++ CLI 的 C# 字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15982703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com