【问题标题】:DllImport for C# (original is in C++/CLI) Need to output arraysC# 的 DllImport(原始在 C++/CLI 中)需要输出数组
【发布时间】:2012-04-05 00:22:50
【问题描述】:

这就是它在 C++ 中的样子:

[DllImportAttribute("Win32DLLRecon.dll", CharSet=CharSet::Auto, CallingConvention=CallingConvention::StdCall)]
    extern "C" void proc1
        (__int32 *i1,
             __int16 *i2,
             __int16 *i3,
             char *i4,
             unsigned *i5,      
             unsigned char *o1, 
             unsigned __int16 *o2,
             float *o3); 

其中 i = 输入,o = 输出 什么是 C# 等价物?
我试图指定类似的数组,例如“out Byte [] output”,但它抱怨它需要 byte*,而不是 byte[](我确实需要在代码中使用指针)。 编辑: 如果我只是将我的整个类声明为不安全并将它们作为指针传递会发生什么:extern proc (out Byte* output, etc)?

【问题讨论】:

  • 参数名称和 cmets 都经过精心设计,不会让您得到答案。
  • 我修改了名字,希望现在更清楚了。
  • 拜托,谁能看看!!!

标签: c# pointers c++-cli dllimport


【解决方案1】:

我相信您需要为此使用System.IntPtr,或者为真正的数组使用System.IntPtr[]

【讨论】:

  • 我可以将它用于 Byte 和 SByte 吗?你有什么例子吗?如果我只是将我的整个类声明为不安全并将它们作为指针传递会发生什么:extern proc (out Byte* output, etc)?
猜你喜欢
  • 2021-06-25
  • 2013-07-01
  • 2014-01-30
  • 1970-01-01
  • 2015-01-16
  • 1970-01-01
  • 2012-01-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多