[转] Tips - C#获取LastError
// this function is just for fun
[DllImp
public static extern bool WinUsb_SetPowerPolicy(IntPtr InterfaceHandle, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value);
// this function is just for fun
[DllImp
public static extern bool WinUsb_Initialize(Microsoft.Win32.SafeHandles.SafeFileHandle DeviceHandle, ref IntPtr InterfaceHandle);
public bool SetPowerPolicy()
{
// this function never work
IntPtr interfaceHandle = IntPtr.Zero;
Microsoft.Win32.SafeHandles.SafeFileHandle sfh = new Microsoft.Win32.SafeHandles.SafeFileHandle(new IntPtr(this.deviceHandle), true);
bool temp = USBXpressAPI.WinUsb_Initialize(sfh, ref interfaceHandle);
System.ComponentModel.Win32Exception we = new System.ComponentModel.Win32Exception(System.Runtime.InteropServices.Marshal.GetLastWin32Error());
System.Console.WriteLine(we.Message);
byte value = 1;
bool result = USBXpressAPI.WinUsb_SetPowerPolicy(interfaceHandle, (uint)0x01, (uint)1, ref value);
return result;
}
出处:http://www.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。