博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转] Tips - C#获取LastError
阅读量:7305 次
发布时间:2019-06-30

本文共 1134 字,大约阅读时间需要 3 分钟。

如下代码示例如何在C#中取得Win32的GetLastError.
// this function is just for fun
[DllImport("winusb.dll", SetLastError = true
)]
public static extern bool WinUsb_SetPowerPolicy(IntPtr InterfaceHandle, UInt32 PolicyType, UInt32 ValueLength, ref Byte Value);
// this function is just for fun
[DllImport("winusb.dll", SetLastError = true
)]
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;
}

转载于:https://www.cnblogs.com/gnhao/archive/2013/01/12/2857427.html

你可能感兴趣的文章
IT人要时刻感激父母培养之恩
查看>>
分享Silverlight/WPF/Windows Phone一周学习导读(05月09日-05月14日)
查看>>
第8部分:敏捷教练
查看>>
腾讯,是抄袭、还是创新
查看>>
linux解压rar
查看>>
微软私有云分享(R2)17SCAC被精简的功能
查看>>
苹果页面启动icon大小(57*57 114*114)
查看>>
半同步半异步模式的实现 - MSMQ实现
查看>>
jquery ajax 跨域
查看>>
Unix Shell中单引号、双引号字符、反斜杠、反引号的使用[转]
查看>>
samba config
查看>>
win7能上网,上网图标显示红叉的解决办法
查看>>
adnroid 监听收到的短信并根据短信内容进行回复短信
查看>>
Rational Rose 2003 逆向工程转换C++源代码成UML类图
查看>>
Cross-Browser, Event-based, Element Resize Detection(转)
查看>>
QM课程01-功能概述
查看>>
九度 1095:2的幂次方
查看>>
[OSX] 在 OS X 中安装 MacPorts 指南
查看>>
在WPF中显示动态GIF
查看>>
java:hibernate + oracle之坑爹的clob
查看>>