The Old New Thing

Why can't I GetProcAddress a function I dllexport'ed?

The dllexport attribute tells the linker to generate an export table entry for the specified function. This export entry is decorated. This is necessary to support ing of overloaded functions. But it also means that the string you pass to needs to be decorated. As we learned earlier, the decoration scheme varies from architecture to ...

Don't trust the return address

Sometimes people ask, "So I know how to get my return address [use the _ReturnAddress() intrinsic]; how do I figure out what DLL that return address belongs to?" Beware. Even if you figure out which DLL the return address belongs to [use Get­Module­Handle­Ex(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS)], that doesn't mean that that...

What's the difference between CreateMenu and CreatePopupMenu?

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 ...

You can read a contract from the other side

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 ...

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

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/...

How to void your warranty

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 ...

What is the window nesting limit?

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 ...

Welcome to the New Old New Thing

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 ...

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

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...

What is the command line length limit?

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 ...