1
votes

Ideally the reader has upgraded a native C++ program to Visual Studio 2008, which contains an OpenClipboard() block. Why not try setting a breakpoint just after getting a successful return-code from OpenClipboard() and step through your code. According to the Internet it may work on your system, but of course, not on mine, thanks for trying.

Googling on e.g. (( OpenClipboard 1418 vc6 )) finds articles like "GetClipboardData fails in debugger" and "No Error in VC++6 but Error in VC++ 2005". Pragmatically for-the-moment, problem solved - I simply cannot set breakpoints within such code, I need to squirrel information and set the breakpoint after the clipboard operations are done. Error 1418 is "Thread does not have a clipboard open" but it works fine as long as you don't step with VS.NET, or like I say if you keep breakpoints outside of the clipboard-open-close-block.

I would feel better knowing what the exact issue is with the VS.NET debugger.

Being a C++ person I am only dimly aware that you are not supposed to think in terms of threads when doing dot-Net. Anyway I did not find a guru-quality explanation of what's really going on, whether in-fact the problem is that the dot-Net debugger is subtly interfering with the thread-information somehow, when you single-step thru native C++ code.

System-wise: about a year old, two dual-core Xeon's, 4 CPU's according to XP-pro. I had just finished debugging the code by single-stepping thru it in vc6 under XP-SP2-32-bit. So I know the code was pretty-much-fine under vc6. However when I tested with a 10-megabyte CF_TEXT I got exceptions. I thought to try debugging under the nicer exception model of XP-x64.

Recompiled with visual-studio-2008, I could not get the code to single-step at all. OpenClipboard worked, but EnumClipboardFormats() did not work, nothing worked when single-stepped. However, when I set the breakpoint below the complete block of code, everything worked fine. And YES vc2008 made a pinpoint diagnostic 'stack frame corruption around szBuf. There is a lot to like about vc2008. It would be nice if this were somehow merely a clipboard problem - without knowing that I would feel compelled to worry about stepping thru ANYTHING, whether thread-context-issues might be due to the dot-Net-debugger.

2

2 Answers

1
votes

I've never looked into this, but it's easy enough to guess:

  1. The clipboard is a shared resource
  2. Only one app (per desktop) can "own" the clipboard at any given point in time
  3. Your app owns it (after calling OpenClipboard())
  4. VS wants it (probably because, among other things, it's an editor)
  5. While your app is stopped at a breakpoint, no amount of waiting will ever find the clipboard not owned by your app.
  6. Hilarity ensues!
1
votes

Don't waste time suspecting it's a .NET thing. At times, the relation between Visual Studio.NET and the .NET runtime is like ActiveX and ActiveDirectory - it tells you which marketeer was involved, Visual Studio.NET in fact has a number of debuggers. Native, script, or managed - only the latter is really .NET-related. You will be using the Native debugger.

If you want to investigate, I suggest hooking OpenClipboard using Microsoft Detours, then running your app in the debugger. You'd be able to see who is competing for the clipboard.