The Old New Thing

What is the hSection parameter to CreateDIBSection for?

The function creates a special type of bitmap known as a DIB section. We've worked with these guys before: The feature of DIB sections that is by far the most interesting is that the raw pixels in the bitmap are mapped into your process space as if they were normal memory, which you can read from and write to directly. But what is the deal...

Your program assumes that COM output pointers are initialized on failure; you just don't realize it yet

We saw last time that the COM rules for output pointers are that they must be initialized on return from a function, even if the function fails. The COM marshaller relies on this behavior, but then again, so do you; you just don't realize it yet. If you use a smart pointer library (be it ATL or boost or whatever), you are still relying on ...

Why does COM require output pointers to be initialized even on failure?

One of the rules of COM is that if a parameter is marked as an output pointer, then you have to initialize the thing it points to, even if your function failed and you have nothing to return. For example, we saw the problems that can occur if you forget to set the output pointer to in the method. Why does COM have this rule? Doesn't it know...

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

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 ...

I got an array with plenty of nuthin'

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 ...

The format of bitmap resources

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 ...

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

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...

How do I get the command line of another process?

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...