Showing tag results for Code

Jan 15, 2004
Post comments count0
Post likes count1

What can go wrong when you mismatch the calling convention?

Raymond Chen
Raymond Chen

Believe it or not, calling conventions is one of the things that programs frequently get wrong. The compiler yells at you when you mismatch a calling convention, but lazy programmers will just stick a cast in there to get the compiler to "shut up already". And then Windows is stuck having to support your buggy code forever. The window procedure ...

Code
Jan 12, 2004
Post comments count0
Post likes count0

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

Raymond Chen
Raymond Chen

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

Code
Jan 1, 2004
Post comments count0
Post likes count0

Don't trust the return address

Raymond Chen
Raymond Chen

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

Code
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 count1

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