背景:有一DLL,C#的例程里没有用引用和using,而是直接用
[DllImport("FY4400.dll")]
public static extern IntPtr FY4400_OpenDevice(Int32 Devnum);
[DllImport("FY4400.DLL")]
public static extern Int32 FY4400_CloseDevice(IntPtr hDevice);
[DllImport("FY4400.DLL")]
public static extern Int32 FY4400_DI(IntPtr hDevice);
做法是:
1.在类下面,我们重新做个DLL,把这些声明的函数,重新做成方法给python调用:
public int openCard()
{
hDevice= FY4400_OpenDevice(0);
if (hDevice== (IntPtr)(-1))
{ a = 5; }
//构造窗口的时候调用此函数
return a;
}
public Int32 closeCard()
{
//构造窗口的时候调用此函数
return FY4400_CloseDevice(hDevice);
}
public Int32 DI()
{
//构造窗口的时候调用此函数
return FY4400_DI(hDevice);
}
2.生成DLL
3.重点是不要复制原生DLL,FY4400.dll到python程序文件夹.,让程序到系统里自动查找,否则操作不了硬件