剪贴板混乱!
注: 原始这个内容从 http://mygreenpaste.blogspot.com. 如果您是读书它从某一其他站点,请需要时间参观 我的绿色浆糊,公司. 谢谢。
或许好,因此混乱这里是一点苛刻的话。 但剪贴板最近驾驶我坚果! 我设法做的所有是复制一些文本对它,并且操作发生故障。 当然,因为它是特别app,我没有任何错误处理。 app在一个系统运作正义罚款,但跑app在另一个系统(一台虚拟机)一贯地导致疏忽复制文本到剪贴板。
最后,我能确定什么过程防止我的app投入数据在剪贴板,但我未发现一个正派解决方法为,当问题发生时。 它为我比要求不是重要的,作为复制文本行动对剪贴板是更多美好。
无论如何,使用P/Invoke和 System.Diagnostics我发现vmusrvc.exe -真正个人计算机“虚拟机用户为服务” -有剪贴板开放。 使用时间戳从 处理显示器‘s描出事件的(引起在100女士间隔时间)和不合格的操作的时间戳从我的app,我能确定堆vmusrvc.exe :
| ntdll.dll | KiFastSystemCallRet |
| vmusrvc.exe | vmusrvc.exe + 0x9a17 |
| vmusrvc.exe | vmusrvc.exe + 0x9c24 |
| vmusrvc.exe | vmusrvc.exe + 0x91f8 |
| vmusrvc.exe | vmusrvc.exe + 0x907f |
| USER32.dll | InternalCallWinProc + 0x28 |
| USER32.dll | UserCallWinProcCheckWow + 0x150 |
| USER32.dll | DispatchClientMessage + 0xa3 |
| USER32.dll | __fnDWORD + 0x24 |
| ntdll.dll | KiUserCallbackDispatcher + 0x13 |
| vmusrvc.exe | vmusrvc.exe + 0x2d29 |
| vmusrvc.exe | vmusrvc.exe + 0xdba6 |
| kernel32.dll | BaseProcessStart + 0x23 |
参量, user32.dll当然,并且标志信息为vmusrvc.exe不看来是可利用的,但明显地不处理某一消息。 我也许调查这更多最新点。
要发现干涉我的剪贴板工作的过程,我使用P/Invoke叫 GetOpenClipboardWindow()然后 GetWindowThreadProcessId(),通过在返回的把柄由GetOpenClipboardWindow ()。 然后,发现过程的可执行的名字是事情使用 模块 汇集的 过程 事例通过通过返回了在id中被检索的过程GetWindowThreadProcessId () System.Diagnostics.Process.GetProcessById().
以下代码:
使用System.Runtime.InteropServices;
使用System.Diagnostics;
...
串起数据= “aasdlkjasdlk alkjsdl kajsdlkj Al”;
尝试
{
Clipboard.SetData (System.Windows.Forms.DataFormats.Text,数据);
}
抓住(ExternalException ee)
{
LogIt (ee.ToString ());
IntPtr hWnd = GetOpenClipboardWindow ();
如果(IntPtr.Zero! = hWnd)
{
uint pid = 0;
uint tid = GetWindowThreadProcessId (hWnd, pid);
LogIt (“过程与hWnd {0}, PID {1} ({1 :x}), TID {2} ({2 :x})”, +
“名字{3}有剪贴板”, hWnd, pid, tid,
Process.GetProcessById( (int)pid ).Modules[0].FileName );
}
}
Resulted in the following output:
2008-03-25 00:54:45.4938864--> System.Runtime.InteropServices.ExternalException: Requested Clipboard operation did not succeed.
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
at System.Windows.Forms.Clipboard.SetData(String format, Object data)
at Clippy.Form1.button1_Click(Object sender, EventArgs e)
2008-03-25 00:54:45.5339440--> Process with hWnd 65716 (65716), PID 1492 (5d4), TID 1496 (5d8), name C:\Program Files\Virtual Machine Additions\vmusrvc.exe has the clipboard
Interestingly, trying an alternative method of the Clipboard to set the content also failed. The Clipboard.SetDataObject() overload that takes a retryTimes and retryDelay parameter failed in the same fashion after roughly ten seconds when invoked as follows:
Clipboard.SetDataObject( data, false, 100, 100 );
I tried variations on retryTimes and retryDelay, to no avail.
Not sure what vmusrvc.exe is doing with the clipboard (probably has to do with monitoring it for host / guest VM interaction), but the act of setting the contents of the clipboard didn't fail 100% of the time in the VM. Often enough to make it extremely unreliable, though. During "normal" system usage, I was not able to cause a failure when running the app on a non-virtual (actual?) system.
Popularity: 2%
Written by «/\/\Ø|ö±ò\/»®©. Read more great feeds at is source WEBSITE
no comments.
Read more articles on P/Invoke and GetOpenClipboardWindow and System.Diagnostics and Clipboard and GetWindowThreadProcessId and Process Monitor and c# and processes and Virtual Machine and otherSoftware and Virtual PC.
- [+] Digg: Feature this article
- [+] Del.icio.us: Bookmark this article
- [+] Furl: Bookmark this article














