Showing tag results for Code

Sep 7, 2006
Post comments count0
Post likes count0

You have to free memory with the same allocator that allocated it: Logical consequences

Raymond Chen
Raymond Chen

Everybody should know by now that you have to free memory using the same allocator that you used to allocate the memory. If you allocate with then you have to free with ; if you allocate with then you have to free with . Once you've internalized this rule, you can use it to draw other logical conclusions. Consider: When I call the function, wh...

Code
Sep 6, 2006
Post comments count0
Post likes count0

You already know what your target architecture is (or at least you should)

Raymond Chen
Raymond Chen

Sometimes the questions I see make me shake my head in wonderment. How do I determine programmatically what processor architecture my program was compiled for? I want the x86 version of my program to behave differently from the ia64 version. Is there some API I can call? Note that this person isn't asking whether the program is running on 64-...

Code
Sep 1, 2006
Post comments count0
Post likes count0

On the unanswerability of the maximum number of user interface objects a program can create

Raymond Chen
Raymond Chen

The answer to the question "What is the maximum number of window classes a program can register?" is not a number. Most user interface objects come from a shared pool of memory known as the "desktop heap". Although one could come up with a theoretical maximum number of window classes that can fit in the desktop heap, that number is not achievable ...

Code
Aug 31, 2006
Post comments count0
Post likes count0

The dialog class goes under the sneaky name WC_DIALOG

Raymond Chen
Raymond Chen

An anonymous commenter wanted to know how to create a dialog box with . The window class for dialog boxes is . I'm not quite sure why anybody would want to create a dialog box this way, but there you have it.

Code
Aug 28, 2006
Post comments count0
Post likes count2

Try to avoid having BOOL function parameters

Raymond Chen
Raymond Chen

Generally speaking, I believe that you should try to avoid giving functions a boolean parameter (, , etc.) unless the meaning of that boolean parameter is blatantly obvious. Examples of obvious meaning would be the second parameter to the function ( obviously means the window is being enabled and means that it's being disabled) and the final para...

Code
Aug 23, 2006
Post comments count0
Post likes count1

Environment variable expansion occurs when the command is read

Raymond Chen
Raymond Chen

On the command line (and in batch files), environment variable expansion occurs when the command is read. This sounds obvious at first, but it has its own consequences. In the online documentation for , one such consequence is spelled out: would never display the message, since the in both "" statements is substituted when the first "" state...

Code
Aug 22, 2006
Post comments count0
Post likes count0

Who says there's only one? There can be more than one logon session

Raymond Chen
Raymond Chen

An extension of the "What if two programs did this?" thought experiment is the "Who says there's only one?" question. A common question I see is, "From a service, how do I do X with the currently logged-on user?" (Where "X" can be a variety of things such as interact with them or impersonate them.) But who says that there's only one? With the int...

Code
Aug 21, 2006
Post comments count0
Post likes count0

Sucking the exception pointers out of a stack trace

Raymond Chen
Raymond Chen

Often, you find yourself staring at a stack trace for a caught exception and want to see the original exception. (You too can get symbols for operating system binaries, either by using the symbol server to get the symbols on-demand or, if you have a gigabyte of disk space, you can download symbol packages to get them all at one go. Even if yo...

Code
Aug 17, 2006
Post comments count0
Post likes count0

Don't trust the return address, no really

Raymond Chen
Raymond Chen

In the discussion of how to prevent non-"trusted" DLLs from using private OS resources, more than one person suggested having the or function behave differently depending on who the caller is. But we already saw that you can't trust the return address and that you definitely shouldn't use the return address to make a security decision (which i...

Code
Aug 16, 2006
Post comments count0
Post likes count0

Accessibility is not just for people with disabilities

Raymond Chen
Raymond Chen

When the topic of accessibility comes up, most people think it's all about people with disabilities. While it's true that people with disabilities were the original target audience for accessibility, more recent developments have highlighted the value of accessible technologies to everyone. For one thing, making your program accessible means that ...

Code