Showing tag results for Code

Nov 25, 2009
Post comments count0
Post likes count0

How do I get the command line of another process?

Raymond Chen
Raymond Chen

Win32 doesn't expose a process's command line to other processes. From Win32's point of view, the command line is just a conveniently initialized parameter to the process's startup code, some data copied from the launching process to the new process and forgotten. We'll get back to the Win32 point of view a little later. If you look around in W...

Code
Nov 20, 2009
Post comments count0
Post likes count0

The difference between assignment and attachment with ATL smart pointers

Raymond Chen
Raymond Chen

Last time, I presented a puzzle regarding a memory leak. Here's the relevant code fragment: The problem here is assigning the return value of to a smart pointer instead of attaching it. The function creates a memory stream and returns a pointer to it. That pointer has a reference count of one, in accordance with COM rules that a function ...

Code
Nov 19, 2009
Post comments count0
Post likes count0

We're using a smart pointer, so we can't possibly be the source of the leak

Raymond Chen
Raymond Chen

A customer reported that there was a leak in the shell, and they included the output from Application Verifier as proof. And yup, the memory that was leaked was in fact allocated by the shell: On the other hand, is an object creation function, so it's natural that the function allocate some memory. The responsibility for freeing the memory be...

Code
Nov 13, 2009
Post comments count0
Post likes count0

What a drag: You can be a drag in managed code, too

Raymond Chen
Raymond Chen

David Anson digests my earlier series on virtual drag/drop and translates it into managed code. His example of dragging his entire RSS feed is an excellent illustration of dragging dynamically-generated virtual content. (I didn't use an example like that because the purpose of the What a drag series was to get something done in the least amount...

CodeWhat a drag
Nov 11, 2009
Post comments count0
Post likes count0

Trying to avoid double-destruction and inadvertently triggering it

Raymond Chen
Raymond Chen

We saw some time ago the importance of artificially bumping an object's reference count during destruction to avoid double-destruction. However, one person's attempt to avoid this problem ended up triggering it. The explanation for the line was that it was done to avoid the double-destruction problem if the object receives a temporary during...

Code
Nov 9, 2009
Post comments count0
Post likes count0

How do I create a toolbar that sits in the taskbar?

Raymond Chen
Raymond Chen

Commenter Nick asks, "How would you go about creating a special toolbar to sit on the taskbar like the Windows Media Player 10 minimised toolbar?" You would look at the DeskBand API SDK Sample in the Windows Platform SDK. The magic word is DeskBand. This MSDN page has an overview. Bonus chatter: I've seen some online speculation as to whether ...

Code
Nov 6, 2009
Post comments count0
Post likes count0

Signs that the symbols in your stack trace are wrong

Raymond Chen
Raymond Chen

One of the things programmers send to each other when they are trying to collaborate on a debugging problem is stack traces. Usually something along the lines of "My program does X, then Y, then Z, and then it crashes. Here is a stack trace. Can you tell me what's wrong?" It helps if you at least glance at the stack trace before you send it, bec...

Code
Oct 23, 2009
Post comments count0
Post likes count0

If you have to cast, you can't afford it

Raymond Chen
Raymond Chen

A customer reported a crash inside a function we'll call : The title of today's entry gives the answer away. (The title is also an exaggeration, but it's a pun on the saying If you have to ask, you can't afford it.) The last parameter to the function is declared as a : A pointer to a generic pointer. Note that it is not itself a generic poi...

Code
Oct 16, 2009
Post comments count0
Post likes count0

Important window message numbers to memorize

Raymond Chen
Raymond Chen

You probably know them already, but if you're new to Win32, here are some key window messages. I would normally suggest that you commit them to memory, but if you do enough debugging, you'll end up memorizing them anyway because you see them all the time. I include in the list even though it is a low-traffic message because you do see it a lot w...

Code