Showing tag results for Other

Jul 28, 2006
Post comments count0
Post likes count0

The efficiency of ordinal-based imports while still being name-based

Raymond Chen
Raymond Chen

Reader Tom brought up the interesting point that ordinal-based imports are slightly faster than name-based, though not by much. But if even that tiny fraction of a percentage bothers you, you can still get the benefits of ordinal-based imports while still being name-based. People are more familiar with the first half of the "rebase and bind" duo ...

Other
Jul 27, 2006
Post comments count0
Post likes count0

Names in the import library are decorated for a reason

Raymond Chen
Raymond Chen

When I wrote that the symbolic name for the imported function table entry for a function is called , the statement was "true enough" for the discussion at hand, but the reality is messier, and the reason for the messy reality is function name decoration. When a naive compiler generates a reference to a function, the reference is decorated in a ma...

Other
Jul 26, 2006
Post comments count0
Post likes count0

What happens when you get dllimport wrong?

Raymond Chen
Raymond Chen

Now that we've learned what the declaration specifier does, what if you get it wrong? If you forget to declare a function as , then you're basically making the compiler act like a naive compiler that doesn't understand . When the linker goes to resolve the external reference for the function, it will use the stub from the import library, and ever...

Other
Jul 25, 2006
Post comments count0
Post likes count0

Issues related to forcing a stub to be created for an imported function

Raymond Chen
Raymond Chen

I noted last time that you can concoct situations that force the creation of a stub for an imported function. For example, if you declare a global function pointer variable: then the C compiler is forced to generate the stub and assign the address of the stub to the variable. That's the best it can do, since the loader will patch up only the ...

Other
Jul 24, 2006
Post comments count0
Post likes count0

How a less naive compiler calls an imported function

Raymond Chen
Raymond Chen

If a function is declared with the declaration specifier, this instructs the Visual Studio C/C++ compiler that the function in question is an imported function rather than a normal function with external linkage. With this additional information, the compiler generates slightly different code when it needs to reference an imported function, since...

Other
Jul 21, 2006
Post comments count0
Post likes count0

Calling an imported function, the naive way

Raymond Chen
Raymond Chen

An import library resolves symbols for imported functions, but it isn't consulted until the link phase. Let's consider a naive implementation where the compiler is blissfully unaware of the existence of imported functions. In the 16-bit world, this caused no difficulty at all. The compiler generated a far call instruction and left an external reco...

Other
Jul 20, 2006
Post comments count0
Post likes count0

Rethinking the way DLL exports are resolved for 32-bit Windows

Raymond Chen
Raymond Chen

Over the past few days we've learned how 16-bit Windows exported and imported functions from DLLs and that the way functions are exported from 32-bit DLLs matches the 16-bit method reasonably well. But the 16-bit way functions are imported simply doesn't work in the 32-bit world. Recall that in 16-bit Windows, the fixups for an imported functio...

Other
Jul 19, 2006
Post comments count0
Post likes count0

Exported functions that are really forwarders

Raymond Chen
Raymond Chen

Last time, we saw how the way Win32 exports functions is pretty much the same as the way 16-bit Windows exports functions, but with a change in emphasis from ordinal-based exports to name-based exports. This change in emphasis is not expressed anywhere in the file format; both 16-bit and 32-bit DLLs can export either by name or by ordinal (or by ...

Other
Jul 18, 2006
Post comments count0
Post likes count1

How are DLL functions exported in 32-bit Windows?

Raymond Chen
Raymond Chen

The designers of 32-bit Windows didn't have to worry quite so much about squeezing everything into 256KB of memory. Since modules in Win32 are based on demand-paging, all you have to do is map the entire image into memory and then run around accessing the parts you need. There is no distinction between resident and non-resident names; the names of ...

Other