精通
英语
和
开源
,
擅长
开发
与
培训
,
胸怀四海
第一信赖
When I try and debug the example I get this following message when I remove a usb disk. If I run the exe it seems to work fine.当我试着调试示例时,移除usb磁盘后,我得到这个消息。 如果我运行exe似乎正常工作。
System.AccessViolationException was unhandled System.AccessViolationException未处理
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt." 消息= "尝试读取或写入受保护的内存。 这通常是一个迹象表明内存崩溃。”
What am I missing?我缺少什么? Thanks,谢谢,
That is indeed strange. I've not seen that exact exception in this demo. However, I have noticed odd behavior depending on where you set a breakpoint. For example, if you set a breakpoint at the first line of UsbManager.GetDiskInformation, the VS test host will crash. But you can set a breakpoint on the second line of that method without a problem. I'll keep an eye on it and post any fixes if I find them.
这的确是奇怪的。 我未见此异常。 然而,我注意到奇怪的行为取决于你设置的一个断点。 例如,如果您在UsbManager的第一行设置一个断点。 GetDiskInformation,VS测试主机将崩溃。 但是你可以在第二行设置一个断点的方法没有问题。 我会留意它和修复它
Yes, there is a big mistake here.:是的,这里有一个巨大的错误。
if ((message.Msg == WM_DEVICECHANGE) &&
(*1*)(Marshal.ReadInt32(message.LParam, 4) == DBT_DEVTYP_VOLUME))
{
(*2*) switch (message.WParam.ToInt32())
{
You can not handle lParam first, besause its format depends 你不能处理lParam第一,因为它的格式决定
on a value of the wParam parameter.在按钮的值参数。
In the MSDN dokumentation for the lParam of a WM_DEVICECHANGE message says:在MSDN dokumentation lParam WM_DEVICECHANGE消息说:
http://msdn.microsoft.com/en-us/library/aa363480(VS.85).aspx
"A pointer to a structure that contains event-specific data. Its format depends on the value of the wParam parameter. For more information, refer to the documentation for each event."一个指针指向一个结构,其中包含相关的数据。 它的格式取决于按钮的值参数。 有关更多信息,请参考文档每个事件”。
For example, if you obtain DBT_CONFIGCHANGED event, its lParam is set to zero, and you really have "Attempted to read or write protected memorytry" as the exception message said.例如,如果您获得DBT_CONFIGCHANGED事件,其lParam设置为零,你真的有“试图读或写保护memorytry”异常消息说。
Excellent catch. Thank you very much for pointing this out. I've submitted updated Demo and Source zip files to the editors and hopefully they'll post them asap.
出色的捕捉。 非常感谢你指出这一点。 我已经提交更新演示和源zip给编辑了,希望他们会尽快发布。
No problem. Thank you also, for the excellent article and the quick response. My five for useful code. Keep up the good work.
没有问题。 也谢谢你,优秀的文章和快速反应。 我对代码打5分。 保持良好的工作。