Showing results for Code - The Old New Thing

Feb 1, 2010
Post comments count0
Post likes count0

Why can't I use the linker to delay-load a function from kernel32?

Raymond Chen
Raymond Chen

For some time (I am too lazy to look up when it was introduced), the Visual Studio linker has supported a feature known as delay-loading. But why can't you use this feature to delay-load a function from ? It would be very handy: If you write the program fails to load on versions of Windows which do not support the function because the Win32 ...

Code
Jan 29, 2010
Post comments count0
Post likes count0

How do I suppress full window drag/resize for just one window?

Raymond Chen
Raymond Chen

A customer asked, Is there a way to turn off Full Window Drag on a single window? I have a resizable control that I would like not update itself while resizing. It so happens that I wrote a sample program ages ago to illustrate how to do this. You can find it in the Platform SDK under . The source code is also reproduced in this Knowledge ...

Code
Jan 28, 2010
Post comments count0
Post likes count0

What idiot would hard-code the path to Notepad?

Raymond Chen
Raymond Chen

There seemed to be a great deal of disbelief that anybody would hard-code the path to Notepad. Here's one example and here's another. There's a large class of problems that go like this: I'm running Program X, and when I tell it to view the error log, I get this error message: What is wrong and how do I fix it? Obviously, the file is ...

Code
Jan 26, 2010
Post comments count0
Post likes count0

Microspeak: Zap

Raymond Chen
Raymond Chen

You may hear an old-timer developer use the verb zap. That proposed fix will work. Until everybody gets the fix, they can just zap the assert. The verb to zap means to replace a breakpoint instruction with an appropriate number of NOP instructions (effectively ignoring it). The name comes from the old Windows 2.x kernel debugger. (Actually, ...

CodeMicrospeak
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 count0

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