public class LLht
{
//手持机下载上传
[DllImport("llht.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int llht_down(string PCFile, string HTFile, int port, int baud, int SerialNO);
[DllImport("llht.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern int llht_up(string PCFile, string HTFile, int iPort, int iBaud, int iSerialNo);
//取得HT 的文件放在FILEBUFF 中 每个文件的长度不超过12字节,返回是文件的数目
[DllImport("ht32dll.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern long GetHtFile(ref byte filebuff, uint iPort, long iBaud);
}
这就是DLL的入口函数,没有DLL的头文件,注释也只有那一行,long GetHtFile(char * filebuff, unsigned int iPort, long iBaud);这是函数原型。
调用代码如下:
string name = "000000000000";
byte[] filename = new byte[12];
for (int i = 0; i < name.Length; i++)
{
filename[i] = (byte)name[i];
}
long read = LLht.GetHtFile(ref filename[0], comid, 57600);//此行报错
MessageBox.Show(read + ":" + filename[0].ToString());
报错内容为:对 PInvoke 函数“数据审核!数据审核.LLht::GetHtFile”的调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。请检查 PInvoke 签名的调用约定和参数与非托管的目标签名是否匹配。
求助各位大神