Showing results for Code - The Old New Thing

Dec 30, 2003
Post comments count0
Post likes count0

What's the difference between CreateMenu and CreatePopupMenu?

Raymond Chen
Raymond Chen

CreateMenu creates a horizontal menu bar, suitable for attaching to a top-level window. This is the sort of menu that says "File, Edit", and so on. CreatePopupMenu creates a vertical popup menu, suitable for use as a submenu of another menu (either a horizontal menu bar or another popup menu) or as the root of a context menu. If you get the two con...

Code
Dec 26, 2003
Post comments count0
Post likes count0

You can read a contract from the other side

Raymond Chen
Raymond Chen

An interface is a contract, but remember that a contract applies to both parties. Most of the time, when you read an interface, you look at it from the point of view of the client side of the contract, but often it helps to read it from the server side. For example, let's look at the interface for control panel applications. Most of the time, ...

Code
Dec 22, 2003
Post comments count0
Post likes count0

How do I determine whether I own a critical section if I am not supposed to look at internal fields?

Raymond Chen
Raymond Chen

Seth asks how he can perform proper exception-handling cleanup if he doesn't know whether he needs to clean up a critical section. I'm using SEH, and have some __try/__except blocks in which the code enters and leaves critical sections. If an exception occurs, I don't know if I'm currently in the CS or not. Even wrapping the code in __try/__finall...

Code
Dec 18, 2003
Post comments count0
Post likes count0

How to void your warranty

Raymond Chen
Raymond Chen

MSDN just published an article telling people that it's okay to use reserved fields in an internal structure. Anybody who does this has just voided their warranty. Please put a "This program has a high likelihood of crashing after you install the next Service Pack or upgrade your OS" in your license agreement.And you wonder why app compat is so ha...

Code
Dec 18, 2003
Post comments count0
Post likes count0

What is the window nesting limit?

Raymond Chen
Raymond Chen

In the old days, Windows didn't bother enforcing a nesting limit because, well, if you want to nest windows 200 deep, that's your decision. Many window operations are recursive, but since everything happened on the application's stack, it was your own responsibility to make your stack big enough so it didn't overflow. But Windows NT moved the windo...

Code
Dec 15, 2003
Post comments count0
Post likes count0

Welcome to the New Old New Thing

Raymond Chen
Raymond Chen

Hey there, everybody. It's going to take me a while to settle in, so please be patient. It seems I always celebrate a new blog by designing some insane multi-part series on some obscure aspect of Win32, so I think I'll welcome this site with a series of articles that demonstrate various things you can do with the shell namespace. I haven't planned ...

CodeOther
Dec 11, 2003
Post comments count0
Post likes count0

How do I pass a lot of data to a process when it starts up?

Raymond Chen
Raymond Chen

As we discussed yesterday, if you need to pass more than 32767 characters of information to a child process, you'll have to use something other than the command line. One method is to wait for the child process to go input idle, then for some agreed-upon window and send it a message. This method has a few problems: You have to come up with...

Code
Dec 10, 2003
Post comments count0
Post likes count1

What is the command line length limit?

Raymond Chen
Raymond Chen

It depends on whom you ask. The maximum command line length for the CreateProcess function is 32767 characters. This limitation comes from the UNICODE_STRING structure. CreateProcess is the core function for creating processes, so if you are talking directly to Win32, then that's the only limit you have to worry about. But if you are reaching Cr...

Code
Dec 9, 2003
Post comments count0
Post likes count0

Why you should never suspend a thread

Raymond Chen
Raymond Chen

It's almost as bad as terminating a thread. Instead of just answering a question, I'm going to ask you the questions and see if you can come up with the answers. Consider the following program, in (gasp) C#: When you run this program and hit Enter to suspend, the program hangs. But if you change the worker function to just "for(;;) {}" the ...

Code
Dec 4, 2003
Post comments count0
Post likes count0

Which access rights bits belong to whom?

Raymond Chen
Raymond Chen

Each ACE in a security descriptor contains a 32-bit access mask. Which bits belong to whom? The access rights mask is a 32-bit value. The upper 16 bits are defined by the operating system and the lower 16 bits are defined by the object being secured. For example, consider the value 0x00060002 for the access rights mask. This breaks down as the sy...

Code