C# 调用api 问题
c#通过调用api访问usb设备
其中调用DeviceIoControl函数时总是返回错误号87,意味着参数错误,请问是什么问题呢?谢谢,代码如下
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,
ref long InBuffer,
int nInBufferSize,
ref long OutBuffer,
int nOutBufferSize,
ref int pBytesReturned,
ref NativeOverlapped lpOverlapped);
private long ResetPort(IntPtr hDevice)
{
int outByte = 0;
System.Threading.NativeOverlapped overlapped = new System.Threading.NativeOverlapped();
overlapped.InternalLow = IntPtr.Zero;
overlapped.InternalHigh = IntPtr.Zero;
overlapped.OffsetLow = 0;
overlapped.OffsetHigh = 0;
overlapped.EventHandle = CreateEvent(IntPtr.Zero, true, false, null);
long inbuffer = 0;
DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, ref inbuffer, 0, ref inbuffer, 0, ref outByte, ref overlapped);
return Marshal.GetLastWin32Error() ;
}
其中调用DeviceIoControl函数时总是返回错误号87,意味着参数错误,请问是什么问题呢?谢谢,代码如下
[DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool DeviceIoControl(
IntPtr hDevice,
uint dwIoControlCode,
ref long InBuffer,
int nInBufferSize,
ref long OutBuffer,
int nOutBufferSize,
ref int pBytesReturned,
ref NativeOverlapped lpOverlapped);
private long ResetPort(IntPtr hDevice)
{
int outByte = 0;
System.Threading.NativeOverlapped overlapped = new System.Threading.NativeOverlapped();
overlapped.InternalLow = IntPtr.Zero;
overlapped.InternalHigh = IntPtr.Zero;
overlapped.OffsetLow = 0;
overlapped.OffsetHigh = 0;
overlapped.EventHandle = CreateEvent(IntPtr.Zero, true, false, null);
long inbuffer = 0;
DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT, ref inbuffer, 0, ref inbuffer, 0, ref outByte, ref overlapped);
return Marshal.GetLastWin32Error() ;
}
...全文
相关推荐
C# 调用API函数弹出映射网络驱动器对话框问题
首先,了解调用API函数的基本步骤是至关重要的。C#中调用Windows API通常涉及以下几点:1.
前端调用C#写的API接口,跨域问题解决
这样的错误做前端的肯定都见过吧,典型的跨域错误,然后上网一顿搜,结果并不是前端的问题,后端人员也蒙圈了,明明我已经设置了跨域配置,但还是不行。网上很多教程都是告诉你在配置里的 webServer 节点添加这样的跨域配置项,但是并没有卵用
JS调用C#后台方法
**跨域问题**: - 默认情况下,由于同源策略的限制,JavaScript不能跨域调用Web服务。
C#平台调用(非常不错)
总结,C#平台调用是一项关键技能,它使C#开发者能充分利用已有的C/C++库和操作系统API。熟练掌握P/Invoke和C++/CLI,可以大大拓宽C#的应用领域,同时也要注意性能和安全性的考量。
C#调用API串口通信
C#调用API串口通信C#调用API串口通信是指使用C#语言通过API函数调用串口设备,实现串口通信的功能。串口通信是一种常用的通信方式,广泛应用于工业控制、机器人控制、数据采集等领域。


