[英]How to create a SafeArray C#?
I need to create a SafeArray to pass to a COM method.我需要创建一个 SafeArray 以传递给 COM 方法。
How do I create/maintain/destroy a SafeArray in C#?如何在 C# 中创建/维护/销毁 SafeArray?
I have never came across SafeArrays before and could not find much with a quick google search, so any help is much appreciated.我以前从未遇到过 SafeArrays,并且通过快速的谷歌搜索找不到太多,因此非常感谢任何帮助。
EDIT: Added Sample Code:编辑:添加示例代码:
The COM method signature COM 方法签名
[id(0x000000d5)]
HRESULT GetTags(
[in] SAFEARRAY(long) buffer,
[out, retval] long* retval);
The generated interop method in C# C#中生成的互操作方法
int GetTags(System.Array buffer)
Member of Cwise.IUser
So in this case do I have to create a SafeArray or can I simply pass a normal.Net Array to the COM method GetTags?所以在这种情况下,我必须创建一个 SafeArray 还是可以简单地将一个 normal.Net 数组传递给 COM 方法 GetTags?
use such a code for this为此使用这样的代码
Array ar = Array.CreateInstance(typeof (int), 500);
instead of typeof(int)
use your own data type, your COM object must say you what type is expecting.而不是
typeof(int)
使用您自己的数据类型,您的 COM object 必须告诉您期望什么类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.