DLL question

Hello everyone,

I am new to this forum and new to c++ but I have a question so please bear with me.

The situation is this:
I have a .dll file with some code in it and I have an .exe which I can't alter. I want the code inside my .dll to be performed when the .exe starts.
Is it possible to permanently link my .dll to the .exe somehow without another .exe?
If it is not possible without another .exe(2), is it possible to link this other .exe(2) with the .exe(1) I can't change so that the .exe(2) starts when the other .exe(1) starts?

I really hope anyone can help me with this problem.
Someone told me it might be possible with regsvr32.exe?

Thanks alot in advance!
More info would help...
an .exe which I can't alter

do you mean you dont have the source code for it? or you are not allowed to modify even the assembly code for it?
------------------------------------------------------------------------------------------------

you dont have the source code / it is okey to modify the assembly code for the exe
you can use a code cave and made a call for loadlibrary...

you can modify the exe / you dont want to do anything with assembly / all what you want is to call dllmain
add the dll to the PE's import table using PE tools see
http://stackoverflow.com/questions/18018497/what-is-the-most-easy-and-fast-way-to-edit-pe-executable-file-to-make-it-load-sp

you cant touch the exe and you want your dll to be loaded or your exe to run
make a bat file and start the two exes, then all you need to do is run the bat file instead of exe(1)... if it is a dll that you want to load then use a DLL injector

you dont want to modify the exe at all, and you dont want to use dll injector nor a batch file
well... you can see what dlls/APIs an exe call with some kind of PE tool (PE inspector for example / function tab) and then made a modified version of any dll that the exe load using code caves to load your dll... and place it in the same folder as exe(1)

here is a link that demonstrate code caves
http://www.codeproject.com/Articles/20240/The-Beginners-Guide-to-Codecaves
I mean't that I don't have the source code for it.

Thanks alot for taking the time to answer me! These answers really help, I am going to look into code caving as that seems to be the best option.

Thanks again.
The linker will need a stub library to link map the calls in your program to the stuff in the DLL.

If you have the matching .lib that goes with your .dll, just use that. The program will be bound to the DLL.

If you don't have the .lib, you need to load the DLL and map its functions at runtime.

To do that you load the library with LoadLibrary and lookup symbols with GetProcAddress.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms684175%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683212%28v=vs.85%29.aspx

There are many examples around. If you're still stuck, let us know.

EDIT:
There's an example here. http://www.cplusplus.com/forum/general/8090/#msg37603
Last edited on
Topic archived. No new replies allowed.