The loader without the loaded

by Michael S. Kaplan, published on 2005/08/24 23:08 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2005/08/24/456021.aspx


I have mentioned in the past about customers who did not need the Microsoft Layer for Unicode on Win9x Systems itself. They had their own layer, perhaps built based on the article written by F. Avery Bishop, David C. Brown, and David M. Meltzer.

But they did like the loader in unicows.lib, and wanted to hook up their layer to this loader.

So how hard is it to have the loader without having the loaded?

It is actually quite easy!

Basically, you need to have include unicows.lib in your project just as the Platform SDK describes and add a file in your project that has a custom loader function -- something that will return an HMODULE such as that returned by LoadLibrary. What this needs to look like is on the Platform SDK, here. The code looks like this:

#ifdef __cplusplus
extern "C" {
#endif
extern FARPROC _PfnLoadUnicows = (FARPROC) &LoadUnicowsProc;
#ifdef __cplusplus
}
#endif

Of course you need to define your own LoadUnicowsProc procedure. :-)

Now what you do next depends. You have two choices:

A) If you have a library that has all of the functions you call in it and their names are identical, then once you have a LoadUnicowsProc() defined that returns its HMODULE, you are done! The MSLU loader does all of the work for you and loads the functions. You're done!

B) If your library's function names are different or there are other reasons you want to handle having the pointers to functions yourself, you can actually add the following to that source file you added (as is described here) for each function:

#ifdef __cplusplus
extern "C" {
#endif
extern FARPROC Unicows_<function name one> = (FARPROC) <function you want MSLU to call>
extern FARPROC Unicows_<function name two> = (FARPROC) <function you want MSLU to call>
...
extern FARPROC Unicows_<function name n> = (FARPROC) <function you want MSLU to call>
#ifdef __cplusplus
}
#endif

And then you are done with this method. The loader will never use that HMODULE you returned from LoadUnicowsProc(), so you can pass any non-NULL value (I would recommend calling a guaranteed invalid value like (HMODULE)0x00000001 or something).

Now as long as you cover all of the functions your application is calling (via either method), then you get the advantage of the platform-based switching that the MSLU Loader provides, without any worries related to your functions being called on non-Win9x platforms.

Now not everyone needs such a method, but if it would be handy for you then it is available. :-)

 

This post brought to you by "٭" (U+066d, a.k.a. ARABIC FIVE POINTED STAR)


no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day