Showing tag results for Code

Mar 1, 2012
Post comments count0
Post likes count0

How do I make it so that users can copy static text on a dialog box to the clipboard easily?

Raymond Chen
Raymond Chen

Given that you have a Win32 dialog box with static text in an control, how do you make it so that users can easily copy that text to the clipboard? The traditional solution is to create a borderless read-only edit control (which draws as static text by default). Add it to the tab order by setting the style, and maybe even give it a keyboard a...

Code
Feb 22, 2012
Post comments count0
Post likes count0

Instead of creating something and then trying to hide it, simply don't create it in the first place

Raymond Chen
Raymond Chen

A customer had a question, which was sort of I bet somebody got a really nice bonus for that feature in reverse. A customer is asking if there is a way to programmatically control the icons in the notification area. Specifically, they want the setting for their notification icon to be "Only show notifications" rather than "Show icon and notifi...

Code
Feb 20, 2012
Post comments count0
Post likes count0

What's the difference between Text Document, Text Document – MS-DOS Format, and Unicode Text Document?

Raymond Chen
Raymond Chen

Alasdair King asks why Wordpad has three formats, Text Document, Text Document - MS-DOS Format, and Unicode Text Document. "Isn't at least one redundant?" Recall that in Windows, three code pages have special status. Three text file formats. Three encodings. Hm... I wonder... As you might have guessed by now, the three text file formats c...

Code
Feb 17, 2012
Post comments count0
Post likes count0

How do I find out which process has a file open?

Raymond Chen
Raymond Chen

Classically, there was no way to find out which process has a file open. A file object has a reference count, and when the reference count drops to zero, the file is closed. But there's nobody keeping track of which processes own how many references. (And that's ignoring the case that the reference is not coming from a process in the first place; ...

Code
Feb 15, 2012
Post comments count0
Post likes count0

When does an icon handler shell extension get unloaded?

Raymond Chen
Raymond Chen

A customer had a question about the function. They used the function to obtain the icon for a file, and they discovered that when they asked for the icon of a particular type of file, the shell extension for the associated application was loaded. But unfortunately the third party shell extension is not getting unloaded, maybe because of a bug. Ca...

Code
Feb 10, 2012
Post comments count0
Post likes count1

Fancy use of exception handling in FormatMessage leads to repeated "discovery" of security flaw

Raymond Chen
Raymond Chen

Every so often, somebody "discovers" an alleged security vulnerability in the function. You can try it yourself: If you run this program under the debugger and you tell it to break on all exceptions, then you will find that it breaks on an access violation trying to write to an invalid address. Did you just find a buffer overflow security v...

Code
Feb 9, 2012
Post comments count0
Post likes count0

What is the effect of memory-mapped file access on GetLastError()?

Raymond Chen
Raymond Chen

A customer was using memory-mapped files and was looking for information as to whether access to the memory-mapped data modifies the value returned by . A member of the kernel team replied, "No, memory-mapped I/O does not ever change the value returned by ." That answer is simultaneously correct and wrong, a case of looking at the world through...

Code
Feb 8, 2012
Post comments count0
Post likes count0

The path-searching algorithm is not a backtracking algorithm

Raymond Chen
Raymond Chen

Suppose your PATH environment variable looks like this: Suppose that you call intending to load the library at . If the network server is down, the call will fail. Why doesn't it just skip the bad directory in the PATH and continue searching? Suppose the function skipped the bad network directory and kept searching. Suppose that the code w...

Code
Feb 3, 2012
Post comments count0
Post likes count0

The compatibility constraints of error codes, episode 2

Raymond Chen
Raymond Chen

A customer reported an incompatibility in Windows 7: If A: is a floppy drive and they call and there is no disk in the drive, the call fails with the error . Previous versions of Windows failed with the error . Both error codes are reasonable responses to the situation. "The module couldn't be found because the drive is not ready." Programs...

Code
Jan 27, 2012
Post comments count0
Post likes count0

Does mapping the same shared memory two times in a process lead to double the address space usage?

Raymond Chen
Raymond Chen

A customer designed a system which uses shared memory. Specifically, for each database file, they create a corresponding shared memory block of, say, 200MB. Multiple clients which connect to the same database file use the same shared memory block. Naturally, if two processes each access the same database file, each process will map the shared memor...

Code