如何在 C++ 中将 byte[] 返回到 C# CLR
我正在使用 C++ CLR 来包装本机 C++ dll。以便C#项目可以访问C++ CLR dll。
问题是,当我想返回一个byte[]到C#,并在CLR中编写这样的代码时:
static System::Byte[]^ GetTestByteBuffer()
{
System::Byte[]^ byte = gcnew System::Byte[128];
return byte;
}
但它无法通过编译。有人可以帮助我吗?
编译错误:
error C3409: empty attribute block is not allowed
error C3409: empty attribute block is not allowed error C2146: syntax error "^":
error C2334: unexpected token(s) preceding '{'; skipping apparent function
I'm using C++ CLR to wrap a native C++ dll. So that the C++ CLR dll can be accessed by a C# project.
The problem is that when I want to return a byte[] to C#, and write such code in CLR:
static System::Byte[]^ GetTestByteBuffer()
{
System::Byte[]^ byte = gcnew System::Byte[128];
return byte;
}
but it cannot pass compilation. Anyone can help me?
compilation error:
error C3409: empty attribute block is not allowed
error C3409: empty attribute block is not allowed error C2146: syntax error "^":
error C2334: unexpected token(s) preceding '{'; skipping apparent function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在 C++/CLI 中声明字节数组的方式:
Google 是你的朋友...
This is the way you declare a byte array in C++/CLI:
Google is your friend...