Click to See Complete Forum and Search --> : Looking for some advice on DLL usage


seregsarn
February 12th, 2005, 08:02 AM
So... I'm trying to write a DLL which, when completed, will sit as an intermediary between two other modules: On one side, I have a program that expects to load a particular library (of C functions, if that matters) from a DLL, and the actual library DLL on the other side. Essentially, I want to pass most of the functions through my wrapper DLL, and tack new functionality on in between them.

So far I've been trying to blunder my way through writing the DLL myself, but it doesn't seem to be working out so well. The closest I've gotten to getting a working DLL that just passes the functions through from library to executable is a DLL which, according to my debugger, seems to be exporting all the right symbols, yet which the program refuses to recognize as valid (i.e. when I try to run the program it complains that one of the functions it needs is not found in the DLL)

The other notable problem I've seen so far is that my DLL needs to import a function foo() from the library DLL so that it can be called by, say, wrapper_foo(), then it has to export wrapper_foo to the program in such a way that the program still thinks it's getting foo(). I thought I had put together a working way of doing it (I used LoadLibrary and GetProcAddress to assign the "real" functions to differently named variables, then exported the "fake" functions and called the real-function pointers), but the program still rejects the DLL. I am unsure how to proceed here.

I guess what I'm asking is, when all's said and done, am I going about this the wrong way? Is there a simpler way I might accomplish the same task? And if not, is there something easily identifiable by outsiders that I'm obviously not doing correctly?

NoHero
February 12th, 2005, 08:11 AM
I am afraid I have enough time today. I will help you out with each problem you have. Just post them one by one, and I will see what I can do.

Andreas Masur
February 13th, 2005, 06:09 AM
Well...first of all...is there any need for doing it this way? I mean do you have (source) access to the dll itself? If so, why not simply changing the dll (providig a common interface with different implementation -> 'pImpl' pattern)? However, maybe I misunderstood your concept here...

Other than that...it is pretty hard to say what is going wrong based on this information. For a starting point, you might want to take a look at the following FAQ (http://www.codeguru.com/forum/showthread.php?s=&threadid=231254)...