Showing tag results for Code

Dec 23, 2009
Post comments count0
Post likes count0

Why is it possible to destroy a critical section while it is in use?

Raymond Chen
Raymond Chen

Some time back, Stu wondered why it is possible to destroy a critical section while it is in use. Well, there's nothing stopping you from creating a file that contains these lines: and then telling your compiler to turn it into a program. It's not like a bolt of lightning is going to come out of the sky and zap you before you hit the Enter k...

Code
Dec 18, 2009
Post comments count0
Post likes count0

I got an array with plenty of nuthin'

Raymond Chen
Raymond Chen

A customer reported a memory leak in the function : We found the following memory leak in the function . Please fix it immediately because it causes our program to run out of memory. If the 's type is , then the corresponding is leaked and not cleaned up. Right now, we are temporarily working around this in our program by inserting code b...

Code
Dec 11, 2009
Post comments count0
Post likes count0

The format of bitmap resources

Raymond Chen
Raymond Chen

Another in a sporadic series on the format of Win32 resources. Here's a question from a customer: I'm noticing some strange behavior: When I call then on an embedded bitmap, the data being returned by is not a properly formatted bitmap. The data is missing the , but the rest of the file is there. also states that the bitmap resource is 14 byt...

Code
Dec 8, 2009
Post comments count0
Post likes count0

How do I determine the processor's cache line size?

Raymond Chen
Raymond Chen

When doing high-performance computing, you need to worry about the CPU cache line size in order to avoid issues like false sharing. But how can you determine the processor's cache size? The function will give you characteristics of the logical processors in use by the system. You can walk the returned by the function looking for entries of type...

Code
Dec 2, 2009
Post comments count0
Post likes count0

A shell extension is a guest in someone else's house; don't go changing the carpet

Raymond Chen
Raymond Chen

A customer was running into this problem with a shell extension: I am writing a shell namespace extension. I need to get data from a COM server, which requires impersonation via with . As I am just writing an extension into , I am not able to call , anymore from my extension. Is there a way I can start by setting in its COM initialization? I w...

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 count1

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 count1

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