Showing results for Code - The Old New Thing

Aug 25, 2004
Post comments count0
Post likes count0

Why can’t you treat a FILETIME as an __int64?

Raymond Chen
Raymond Chen

The FILETIME structure represents a 64-bit value in two parts: typedef struct _FILETIME { DWORD dwLowDateTime; DWORD dwHighDateTime; } FILETIME, *PFILETIME; You may be tempted to take the entire FILETIME structure and access it directly as if it were an __int64. After all, its memory layout exactly matches that of a 64-bit (little-endian)...

CodeTime
Aug 24, 2004
Post comments count0
Post likes count1

Beware of non-null-terminated registry strings

Raymond Chen
Raymond Chen

Even though a value is stored in the registry as REG_SZ, this doesn't mean that the value actually ends with a proper null terminator. At the bottom, the registry is just a hierarchically-organized name/value database. And you can lie and get away with it. Lots of people lie about their registry data. You'll find lots of things that should be...

Code
Aug 20, 2004
Post comments count0
Post likes count0

Writing your own menu-like window

Raymond Chen
Raymond Chen

Hereby incorporating by reference the "FakeMenu" sample in the Platform SDK. It's in the winui\shell\fakemenu directory. For those who don't have the Platform SDK, what are you doing writing Win32 programs without the Platform SDK? Download it if it didn't come with your development tools. If for some reason you don't want the Platform SDK yet ...

Code
Aug 4, 2004
Post comments count0
Post likes count0

Never leave focus on a disabled control

Raymond Chen
Raymond Chen

One of the big no-no's in dialog box management is disabling the control that has focus without first moving focus somewhere else. When you do this, the keyboard becomes dead to the dialog box, since disabled windows do not receive input. For users who don't have a mouse (say, because they have physical limitations that confine them to the keyboar...

Code
Aug 4, 2004
Post comments count0
Post likes count2

Why .shared sections are a security hole

Raymond Chen
Raymond Chen

Many people will recommend using shared data sections as a way to share data between multiple instances of an application. This sounds like a great idea, but in fact it's a security hole. Proper shared memory objects created by the CreateFileMapping function can be secured. They have security descriptors that let you specify which users are all...

Code
Aug 2, 2004
Post comments count0
Post likes count0

How to set focus in a dialog box

Raymond Chen
Raymond Chen

Setting focus in a dialog box is more than just calling SetFocus. A dialog box maintains the concept of a "default button" (which is always a pushbutton). The default button is typically drawn with a distinctive look (a heavy outline or a different color) and indicates what action the dialog box will take when you hit Enter. Note that this is no...

Code
Jul 29, 2004
Post comments count0
Post likes count0

When should you use a sunken client area?

Raymond Chen
Raymond Chen

The WS_EX_CLIENTEDGE extended window style allows you to create a window whose client area is "sunken". When should you use this style? The Guidelines for User Interface Developers and Designers says in the section on the Design of Visual Elements that the sunken border should be used "to define the work area within a window". Spec...

Code
Jul 27, 2004
Post comments count0
Post likes count0

Disabling the program crash dialog

Raymond Chen
Raymond Chen

If you don't want your program to display the standard crash dialog, you can disable it by setting the SEM_NOGPFAULTERRORBOX flag in the process error mode. The simple-minded way is just to do but this overwrites the previous error mode rather than augmenting it. In other words, you inadvertently turned off the other error modes! Unfortunat...

Code
Jul 23, 2004
Post comments count0
Post likes count0

Why do some process stay in Task Manager after they've been killed?

Raymond Chen
Raymond Chen

When a process ends (either of natural causes or due to something harsher like TerminateProcess), the user-mode part of the process is thrown away. But the kernel-mode part can't go away until all drivers are finished with the thread, too. For example, if a thread was in the middle of an I/O operation, the kernel signals to the driver res...

Code