Showing tag results for Code

Jan 25, 2010
Post comments count0
Post likes count0

Why doesn't the window manager have a SetClipboardDataEx helper function?

Raymond Chen
Raymond Chen

Jonathan Wilson asks why the clipboard APIs still require GlobalAlloc and friends. Why is there not a or something that does what does but without needing to call ? Okay, here's your function: Whoop-dee-doo. Historically, Windows doesn't go out of its way to include functions like this because you can easily write them yourself, or you ...

Code
Jan 22, 2010
Post comments count0
Post likes count1

During process termination, the gates are now electrified

Raymond Chen
Raymond Chen

It turns out that my quick overview of how processes exit on Windows XP was already out of date when I wrote it. Mind you, the information is still accurate for Windows XP (as far as I know), but the rules changed in Windows Vista. What about critical sections? There is no "Uh-oh" return value for critical sections; doesn't have a...

Code
Jan 20, 2010
Post comments count0
Post likes count0

The wrong way to determine the size of a buffer

Raymond Chen
Raymond Chen

A colleague of mine showed me some code from a back-end program on a web server. Fortunately, the company that wrote this is out of business. Or at least I hope they're out of business!

Code
Jan 18, 2010
Post comments count0
Post likes count0

It's fine to rename a function in your DEF file, but when you do, you have to link to that function by its new name

Raymond Chen
Raymond Chen

Jeffrey Riaboy asks why, if he renames a function in his DEF file, attempts to link to the function by its old name fail. Well, um, yeah, because you renamed it. Let's take the situation apart a bit; maybe it'll make more sense. I'm going to ignore a lot of details (, calling conventions) since they are not relevant to the discussion and wou...

Code
Jan 15, 2010
Post comments count0
Post likes count0

How you might be loading a DLL during DLL_PROCESS_DETACH without even realizing it

Raymond Chen
Raymond Chen

As you are I'm sure aware, you shouldn't be doing much of anything in your function, but you have to watch out for cases where you end up doing them accidentally. Some time ago, I was investigating a failure which was traced back to loading a DLL inside . Wait, what kind of insane person loads a DLL as part of shutting down? Shouldn't you be cl...

Code
Jan 13, 2010
Post comments count0
Post likes count0

Why does GetCommandLine give me a corrupted command line?

Raymond Chen
Raymond Chen

A customer had the following problem: We're calling to retrieve the command line, and the documentation says that it returns a single null-terminated string. However, when we call it in our application, we find that it is actually a double-null-terminated string. The buffer returned consists of a series of null-terminated strings, one string per ...

Code
Jan 8, 2010
Post comments count0
Post likes count0

What is the hSection parameter to CreateDIBSection for?

Raymond Chen
Raymond Chen

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

Code
Jan 1, 2010
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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

Code
Dec 31, 2009
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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

Code
Dec 24, 2009
Post comments count0
Post likes count0

Why don't we create a special class of programs which can break the normal rules?

Raymond Chen
Raymond Chen

In response to a discussion of why the window handle limit is 10,000, commenter Juan wondered why we don't create a special class of programs which can exceed the 10,000 handle limit and otherwise bypass the normal operation of the system. This is another case of the tragedy of special treatment: Eventually, nothing is special any more. If ther...

Code