本人手里有一设备,有SDK,有VC的DEMO程序,现欲整合到C#中去,在设备头文件中有这样的申明:
BOOL __declspec(dllimport) bAPI4_GetImage(BYTE *picture, int timeout, int iResolution, int* piWidth, int* piHeight);
本人是这样在C#中声明的:
[DllImport("HM130SDK4_SS500A_HMFV.dll", CallingConvention = CallingConvention.StdCall)]
public unsafe static extern bool bAPI4_GetImage(out IntPtr picture, int timeout, int iResolution, out IntPtr piWidth, out IntPtr piHeight);问题在于我调用该函数的时候,参数不知道怎么填,比如:
byte[] m_pPicture = new byte[280 * 320];
IntPtr IntPtrPicture = &m_pPicture;这里报错:无法获得托管类型地址大小,或无法申明指向它的指针
BOOL __declspec(dllimport) bAPI4_GetImage(BYTE *picture, int timeout, int iResolution, int* piWidth, int* piHeight);
本人是这样在C#中声明的:
[DllImport("HM130SDK4_SS500A_HMFV.dll", CallingConvention = CallingConvention.StdCall)]
public unsafe static extern bool bAPI4_GetImage(out IntPtr picture, int timeout, int iResolution, out IntPtr piWidth, out IntPtr piHeight);问题在于我调用该函数的时候,参数不知道怎么填,比如:
byte[] m_pPicture = new byte[280 * 320];
IntPtr IntPtrPicture = &m_pPicture;这里报错:无法获得托管类型地址大小,或无法申明指向它的指针
解决方案 »
- DataRowView row = view.AddNew()错误 Forms.BindingManagerDataErrorEventArgs
- 怎么样算出1~11 中的所有两个数的组合比如1,2 和 1,3...
- 如何用钩子实现两个程序间消息传递,没分了,都给了
- master page套用的时候控件初始化
- web service 安全
- 高手请进
- odp.net的oraclehelper
- 在线等待!请问如何判断textBox控件中是否输入的是字母!
- 关于跳过对话框的问题
- 怎样才能让SqlCommand可以接受SQL Server的GO语句?
- 关于开发完成的软件如何跟.NET framework
- 笔记本 响应不了C#程序 热键
[DllImport("HM130SDK4_SS500A_HMFV.dll")]
static extern bool bAPI4_GetImage(byte[] picture, int timeout, int iResolution, ref int piWidth, ref int piHeight);
感谢楼上的回答,可是,对方要求的是给一个指针啊,而不是一个byte[]数组
unsafe可以使用嘛,就是非托管方式
byte[] will pass in a pointer.Most likely the caller is responsible for creating a buffer. So you create a byte array and pass in the buffer pointer.
int width = 320;
int height = 280;
byte[] picture = new byte[ width * height ];
bool succeeded = bAPI4_GetImage( picture, timeout, iResolution, ref width, ref height);
ref byte[] picture则类似C++中的指针的地址(指针的指针),可以用来传出一个新的数组。