在C#中导入C DLL,如何将短**型 [英] Import C dll in C# , how to convert short** type
本文介绍了在C#中导入C DLL,如何将短**型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要导入C#一个DLL这是在C语言编码。以下是我要调用的函数的甲
I want to import a dll in C# which is coded in C language. The following is the formate of the function I want to call.
/*
*ReadAnswer
*@param objectID The answer object ID
*@param answerBuf The answer buffer.This buffer is automatically allocated by
the function.
It is automatically recycled with each call. A call to this
function with an empty answer or a new request will
automatically free the allocated buffer.
*@param answerBufferSize The answer buffer size.This function return the size of the
allocated buffer in this parameter.
*@return 0 if error occurs
1 if success
*/
int ReadAnswer(unsigned short *objectID,
unsigned short **answerBuf, unsighed short *answerBufferSize )
请帮我一下吧。我被这个功能被卡住。谢谢你在前进
Please help me with it. I'm stucked by this function. Thank you in advance.
推荐答案
函数应声明如下:
[DllImport(dllname)]
private extern static int ReadAnswer(
out ushort objectID,
out IntPtr answerBuf,
out ushort answerBufferSize
);
这样称呼它:
Call it like this:
ushort objectID, answerBufSize;
IntPtr answerBufPtr;
int retval = ReadAnswer(out objectID, out answerBufPtr,
out answerBufSize);
if (retval == 0)
// handle error
ushort[] answerBuf = new ushort[answerBufSize/2];
Marshal.Copy(answerBufPtr, (Int16[])answerBuf, 0, answerBuf.Length);
我的假设是, answerBufSize
的大小在字节。
这篇关于在C#中导入C DLL,如何将短**型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文