![](/img/trans.png)
[英]Howto call an unmanaged C++ function with a std::vector as parameter from C#?
[英]C# using a function from C++ dll with std::vector as parameter
我有一个 C++ dll 其中一个函数将std::vector<UInt16>
作为参数。 我想在 C# 应用程序中使用这个 API 但我不确定这是否可能。
我的 C++ function:
EXPORT_API void STACKMODE ConfigurationStream(InterfaceManager * inst, std::vector<UInt16> address, std::vector <UInt16> data);
Is there some way to send a List or an array from C# or should I just change my API call to have two arrays with an extra int
parameter as the size of the arrays. 请注意,两个向量将始终具有相同的大小。
您不能直接执行此操作,因为 dotnet 框架中没有任何内容具有 std::vector 的确切 memory 布局。 但是,如果您将 API 更改为(正如您在问题中提出的那样),您可以做到这一点:
EXPORT_API void STACKMODE ConfigurationStream(
InterfaceManager * inst
, uint16_t* addressPtr
, uint16_t* dataPtr
, int32_t cnt
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.