Showing tag results for Code

Nov 6, 2007
Post comments count0
Post likes count0

VirtualLock only locks your memory into the working set

Raymond Chen
Raymond Chen

When you lock memory with it locks the memory into your process's working set. It doesn't mean that the memory will never be paged out. It just means that the memory won't be paged out as long as there is a thread executing in your process, because a process's working set need be present in memory only when the process is actually executing. (Ear...

Code
Nov 5, 2007
Post comments count0
Post likes count1

Why do we even have the DefWindowProc function?

Raymond Chen
Raymond Chen

Some time ago, I looked at two ways of reimplementing the dialog procedure (method 1, method 2). Commenter "8" wondered why we have a function at all. Couldn't window procedures have followed the dialog box model, where they simply return to indicate that they want default processing to occur? Then there would be no need to export th...

Code
Nov 1, 2007
Post comments count0
Post likes count0

Why does GetDiskFreeSpaceEx return the wrong amount of free space?

Raymond Chen
Raymond Chen

One customer discovered that viewing the properties of a drive from Explorer shows the amount of disk free space significantly lower than the actual amount of free disk space as resported by the disk management snap-in. The command prompt agrees with Explorer and shows the incorrect result. What's going on? Not surprisingly, both Explorer and the ...

Code
Oct 26, 2007
Post comments count0
Post likes count0

If you pass enough random numbers, eventually one of them will look valid

Raymond Chen
Raymond Chen

One customer traced a problem they were having to the way they were calling a function similar in spirit to this one: This function takes a clipboard format and looks for it on the clipboard. If found, it returns a copy of the data. Looks great, huh? The problem is that the customer would sometimes call the function as . The clipboard form...

Code
Oct 24, 2007
Post comments count0
Post likes count0

What's the difference between LVM_HITTEST and LVM_INSERTMARKHITTEST?

Raymond Chen
Raymond Chen

One customer was confused by the two list view hit-test messages and . What is the difference between the two? The message tries to find the item the point is over. The message tries to find the item the point is next to. For example, suppose you have two 32×32 items, item zero at (0, 0) and item one at (0, 32). You use whe...

Code
Oct 22, 2007
Post comments count0
Post likes count0

The best way to process Unicode input is to make somebody else do it

Raymond Chen
Raymond Chen

Andrew M asks via the Suggestion Box: I was hoping you could address how to properly code Unicode character input. It seems like a lot of applications don't support it correctly. I'm not sure I understand the question, but the answer is pretty easy: Don't do it! Text input is hard. It should be left to the professionals. This means you should...

Code
Oct 19, 2007
Post comments count0
Post likes count0

Other problems traced to violating COM single-threaded apartment rules in the shell

Raymond Chen
Raymond Chen

Probably the biggest category of problems that can be traced to violating COM single-threaded apartment rules in the shell is using an object from the wrong thread. Of course, nobody admits to doing this up front, They just report that the shell is broken. We can't enumerate the items on the desktop any more. We take the pointer returned by and...

Code
Oct 18, 2007
Post comments count0
Post likes count0

Win32 user interface work is inherently single-threaded

Raymond Chen
Raymond Chen

At the end of the day, there's a window handle in there. As we saw a few years ago, windows have thread affinity. You can push work to a background thread all you want, but once you send a message to the window (or do something that results in a message being sent to the window), you've given control to the UI thread. Since the shell is all abou...

Code
Oct 17, 2007
Post comments count0
Post likes count0

The wrong way to check whether the mouse buttons have been swapped

Raymond Chen
Raymond Chen

Back in the late 1990's, the window manager team received a bug that said that sometimes the mouse button state got messed up and the computer acted as if the buttons were stuck down. Further investigation revealed that it occurred only when one particular program was running, and only if the user had enabled mouse button swapping. The reason is...

Code
Oct 15, 2007
Post comments count0
Post likes count0

Why aren't shortcuts as easy as unix links?

Raymond Chen
Raymond Chen

Commenter dingo asks, "Why are shortcuts so hard to manipulate? Why can't they be as easy as unix links?" Well, if you want something like unix links, then you can just create a hard link. Creating them is about the same difficulty ( vs ) and manipulating them is the same since you don't actually manipulate a hard link. You just use it like a regu...

Code