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,…


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…


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

Use Named Pipes and Shared Memory for inter process communication with a child process or two

  I wanted to inject some very low impact code that would run in any “parent” process, like Notepad or Excel or Visual Studio. I wanted to have some User Interface for the data that my injected code gathered about the parent process, and that would work best in a different “child” process, preferably using…


What is your computer doing with all that memory? Write your own memory browser

  What is your computer doing with all that memory? There are various kinds of memory allocated and used in each process. These include: ·         Managed memory (VB.Net, C#, managed C++) ·         Heap memory ·         Stacks ·         Images (files loaded into a process)   VirtualAlloc is the basis of these allocations. If a process needs…

1

You can use HWndHost to host a Win32 HWnd window inside a WPF element

  Suppose you have some old code lying around that creates a Win32 window with an HWnd (perhaps ATL, MFC, or just C/ C++). For example, if you type some erroneous code into a VB application in Visual Studio:           Dim x=4: catch ex As Exception     The “Exception” will be squiggled and…

2

Dynamically load a DLL from a runtime specified path

When running VB.Net or C# code, often it’s useful to call native code. One way is using PInvoke. (for other ways, see How fast is interop code?)   For example, you can call GetWindowText to get the title of a window. To get it’s managed signature, you can use this code from http://www.pinvoke.net/default.aspx/user32/GetWindowText.html      …


Compress and timestamp your pictures to gain disk space

I was running out of space again on my notebook. As years go by, digital cameras can take pictures with more megapixels, but that means they take up more space.   Thus my pictures from 10 years ago are much smaller than this year’s.   Since I have multiple copies of my picture collection (28,000!)…

3

Extract TreeView or ListView ImageList icons from a DLL

An ImageList can be used for a ListView or TreeView control to contain many images in a single file, usually embedded as a resource.  Visual Studio itself has many icons.   If you open Windows Explorer or Internet Explorer, you can see many icons in toolbars, ListViews or TreeViews.     Using Visual Studio (any…

8

Create a WPF Form to choose a text color

I wanted to choose some nice colors for various kinds of text, so I wrote a simple text color picker using Windows Presentation Foundation (WPF).   The code creates a TextBlock and 4 slider controls: one for Alpha channel (Opacity) and one each for Red, Green and Blue.   The code shows how to add…

2