Showing tag results for Code

Jan 9, 2013
Post comments count0
Post likes count0

Understanding the classical model for linking: You can override an LIB with another LIB, and a LIB with an OBJ, but you can’t override an OBJ

Raymond Chen
Raymond Chen

If you study the classical model for linking, you'll see that OBJ files provided directly to the linker have a special property: They are added to the module even if nobody requests a symbol from them. OBJs bundled into a library are pulled into the module only if they are needed to resolve a needed symbol request. If nobody needs a symbol in the...

CodeLinker
Jan 8, 2013
Post comments count0
Post likes count0

Understanding the classical model for linking: Taking symbols along for the ride

Raymond Chen
Raymond Chen

Last time, we learned the basics of the classical model for linking. Today, we'll look at the historical background for that model, and how the model is exploited by libraries. In the classical model, compilers and assemblers consume source code and spit out an OBJ file. They do as much as they can, but eventually they get stuck because they do...

CodeLinker
Jan 7, 2013
Post comments count0
Post likes count1

Understanding the classical model for linking, groundwork: The algorithm

Raymond Chen
Raymond Chen

The classical model for linking goes like this: Each OBJ file contains two lists of symbols. Provided symbols: These are symbols the OBJ contains definitions for. Needed symbols: These are symbols the OBJ would like the definitions for. (The official terms for these are exported and imported, but I will use provided and needed to avo...

CodeLinker
Jan 4, 2013
Post comments count0
Post likes count0

What’s the guidance on when to use rundll32? Easy: Don’t use it

Raymond Chen
Raymond Chen

Occasionally, a customer will ask, "What is Rundll32.exe and when should I use it instead of just writing a standalone exe?" The guidance is very simple: Don't use rundll32. Just write your standalone exe. Rundll32 is a leftover from Windows 95, and it has been deprecated since at least Windows Vista because it violates a lot of modern en...

Code
Jan 3, 2013
Post comments count0
Post likes count0

Why does my program run really slow or even crash (or stop crashing, or crash differently) if running under a debugger?

Raymond Chen
Raymond Chen

More than once, a customer has noticed that running the exact same program under the debugger rather than standalone causes it to change behavior. And not just in the "oh, the timing of various operations changed to hit different race conditions" but in much more fundamental ways like "my program runs really slow" or "my program crashes in a totall...

Code
Dec 28, 2012
Post comments count0
Post likes count0

What do HeapLock and HeapUnlock do, and when do I need to call them?

Raymond Chen
Raymond Chen

You never need to call the and functions under normal operation. Assuming the heap is serialized (which is the default), all the standard heap functions like and will automatically serialize. In fact, the way they serialize is by calling the¹ and functions! Nearly all heap operations complete in a single call. If your heap is serial...

Code
Dec 27, 2012
Post comments count0
Post likes count0

What is so special about the instance handle 0x10000000?

Raymond Chen
Raymond Chen

A customer wanted to know what it means when the function returns the special value . Um, it means that the library was loaded at ? Okay, here's some more information: "We're trying to debug an application which loads DLLs and attempts to hook their registry accesses when they call . It looks like when the special handle is returned from , the r...

Code
Dec 20, 2012
Post comments count0
Post likes count0

Why do I sometimes get classic buttons and sometimes themed buttons depending on the host process?

Raymond Chen
Raymond Chen

A customer reported that their printer configuration property sheet page looked different depending on the host process. In some processes, the printer configuration dialog had the classic look of Windows 2000, but in other processes it has the themed look of Windows XP and later versions. The printer driver calls the to create the prop...

Code
Dec 19, 2012
Post comments count0
Post likes count0

Why doesn't SHGetKnownFolderPath return the customized path?

Raymond Chen
Raymond Chen

A customer reported that the function was not working correctly. They moved their Videos folder to a new location, but when they called , they got the old path rather than the new one. A quick check of the code they provided showed why: Um, you're passing the flag. That flag means "Tell me where this folder would have been if its location h...

Code