It’s easy to use Windows Hooks, even from C#

Microsoft Windows is based on showing windows of data to the user (duh). An application can create windows with which to interact with the user. Every window has a Window Handle, which is used just like an ID number. The Windows OS communicates with the application windows via Windows Messages. For example, when you type…

0

Automatically open Visual Studio Projects and Solutions using IMessageFilter

I wanted to learn more about what an IMessageFilter is and how it behaves. So I wanted to have some sample code that used it to demonstrate its behavior. So I wrote a program that starts Visual Studio, calls some properties and methods (like Get Version and MainWindow.Activate)  and then opens a solution of one…

0

Examining a crash dump

A crash dump is very helpful for diagnosing a problem with software. It can contain enough information to recreate a debug session, almost as if you’re debugging the problem live on the repro machine. Last time I showed some code to create a crash dump with various settings. You can choose to include many different…

1

Heap Corruption Exception 0xC0000374

Modern computers can execute millions of instructions per second, and if one of them is erroneous, then the process could crash. Often analysis of a crash dump can immediately indicates what the problem is, so the fix is easy. For example a NullReference exception: declare a Process variable with a null value, then try to…

0

DPI Aware Sample

Last time I showed a way to use immediate mode graphics in WPF by showing balls bouncing around in a window. This time, we’ll add a few features. I’ve made the program DPI (Dots Per Inch) Aware. On most machines it works correctly. However, on my brand new Surface Pro 3 (really nice!), the screen…

0

Windows Error Reporting and the Appdomain.UnhandledException Event

Sometimes applications fail. If you are the author and it fails on your machine, typically you fire up the code in a debugger, figure out the issue, fix it, and rebuild the code. If the applications is out in the wild, perhaps with millions of users, it gets much more complicated. Yet, the goal is…

1

Create multiple threads to see if work is done simultaneously

When you hear about threads and threading, you hear that they allow concurrent execution of code, which is supposed to lead to better performance. Most computers nowadays have more than one CPU, meaning that each CPU can be executing code at the same time. Hit Ctrl-Shift-Escape to bring up Task Manager, then switch to the…

0

Process Windows Messages in your WPF application

  I have some code that attaches and injects code into a target application (like Visual Studio or IE) to examine its memory use. In order to do that, my code freezes the target.   I wanted my application to respond to WM_QUERYENDSESSION so that when the user is shutting down, it unfreezes the target,…

0

The cost of using nothing

What is the cost of using nothing? Seems like a silly question.   Suppose you see code like this:   void *  MyClass::DoSomething() { int size = sizeof(MyThing) * m_NumItems; var ptr = malloc(size); return ptr;}   It’s a method that allocates space for m_NumItems  MyThings.  This is a real code pattern that exists in…

0

Using multiple heaps efficiently

You can inspect the processes that run on your machine using Task Manager (Ctrl-Shift-Escape) or , Process Explorer from Sysinternals   Or you can write your own: here’s source code: What is your computer doing with all that memory? Write your own memory browser (if you’re using Dev10, just change “Class Window1” to “Class MainWindow”)…

1