Showing results for Code - The Old New Thing

Jun 1, 2012
Post comments count0
Post likes count0

How do I prefetch data into my memory-mapped file?

Raymond Chen
Raymond Chen

A customer created a memory mapping on a large file and found that when the memory manager wanted to page in data from that file, it did so in 32KB chunks. The customer wanted to know if there was a way to increase the chunk size for efficiency. The memory manager decides the chunk size for memory-mapped files, and the chunk size is currently set ...

Code
May 31, 2012
Post comments count0
Post likes count0

What happens if I call KillTimer with a NULL hwnd?

Raymond Chen
Raymond Chen

A customer discovered a bug in their code and wanted some information on how serious it was, so they could assess how urgently they need to issue a fix. We have code that calls with a valid window handle, but then we destroy the window before we get around to calling . When we finally do call , we do so with a window handle. The calls are proba...

Code
May 28, 2012
Post comments count0
Post likes count0

If my window hosts multiple windowless ActiveX controls, which one do I call IOleInPlaceActiveObject::TranslateAccelerator and IOleInPlaceObjectWindowless::OnWindowMessage on?

Raymond Chen
Raymond Chen

Commenter Farproc asks how one goes about hosting two windowless ActiveX controls in a single window. In particular, "none of the documentation explains how to choose which control to send and on?" Actually, the documentation does say. The documentation for says, "Active in-place objects must always be given the first chance at translating ac...

Code
May 25, 2012
Post comments count0
Post likes count0

The extern “C” specifier disables C++ mangling, but that doesn’t mean it disables mangling

Raymond Chen
Raymond Chen

The MSDN documentation on dllexport contains the following enigmatic paragraph, or at least did at the time I wrote this article: dllexport of a C++ function will expose the function with C++ name mangling. If C++ name mangling is not desired, either use a .def file (EXPORTS keyword) or declare the function as extern "C". I've seen this sente...

Code
May 24, 2012
Post comments count0
Post likes count0

How do I prevent unchecked checkboxes in my listview control from disappearing?

Raymond Chen
Raymond Chen

A customer asked, "I have a listview control in report view with the extended style. I noticed that unchecked checkboxes are not visible until I hover over the corresponding item. Is it possible to get the checkboxes to be visible all the time?" I was kind of puzzled by this question because the default behavior of the list view control is to sho...

Code
May 23, 2012
Post comments count0
Post likes count0

GUIDs are designed to be unique, not random

Raymond Chen
Raymond Chen

A customer liaison asked, "My customer is looking for information on the GUID generation algorithm. They need to select N items randomly from a pool of M (jury selection), and their proposed algorithm is to assign each item a GUID, then sort the items by GUID and take the first N." (I've seen similar questions regarding using GUIDs f...

Code
May 11, 2012
Post comments count0
Post likes count0

When you crash on a mov ebx, eax instruction, there aren't too many obvious explanations, so just try what you can

Raymond Chen
Raymond Chen

A computer running some tests encountered a mysterious crash: A colleague of mine quickly diagnosed the proximate cause. *Something* marked the code page PAGE_READWRITE, instead of PAGE_EXECUTE_READ. I suspect a bug in a driver. FOO is just a victim here. This diagnosis was met with astonishment. "Wow! What made you think to check the pr...

Code
May 9, 2012
Post comments count0
Post likes count0

How do I hide a window without blocking on it?

Raymond Chen
Raymond Chen

A customer was working on improving their application startup performance. They found that if their application was launched immediately after a fresh boot, the act of dismissing their splash screen was taking over 5% of their boot time. Their code removed the splash screen by calling . They suspect that the splash screen thread has, for some reaso...

Code
May 4, 2012
Post comments count0
Post likes count0

How does the MultiByteToWideChar function treat invalid characters?

Raymond Chen
Raymond Chen

The flag controls how the function treats invalid characters. Some people claim that the following sentences in the documentation are contradictory: "Starting with Windows Vista, the function does not drop illegal code points if the application does not set the flag." "Windows XP: If this flag is not set, the function silently drops il...

Code