3

I have a DLL that exposes a number of functions and I'd like to make a duplicate DLL with the same name that exposes the exact same functions but with my own implementation of each function.

In this case the functions will do nothing, as the purpose is to stud out the functionality for Unit Testing.

I was just wondering if there are any tools that can take an existing DLL and create a new C++ project (ideally Visual C++) that exposes the same interface.

I could do it manually (using Dependency Walker, aka Depends.exe, to see the exposed functions and params) but it would be much easier if there was an automated tool to do it.

  • If not, why not code one & open-source it? Open source always looks goo on the CV/resume ;-) Good question, btw (+1) – Mawg Jan 11 '16 at 10:39
1

What you need is actually so called "Proxy-DLL".

There are some solutions on the web. My favorite is an AutoIt script posted (russian, 1st link binariy, 2nd src) on Habrahabr, which creates VisualStudio 2008/2010 project for any DLL. All functions are forwarded to the original DLL, you probably will like to overwrite some of them.

1

I think it should not be incredibly difficult to use some scripting and get that done. I'm not describing a full solution here, more like a sketch (since I don't do development on Windows), but:

  • Install Cygwin (or use MS Windows equivalents of the Unix tools I propose)
  • Use your Depends.exe to get the DLL contents listing
  • (assuming you don't care about modules and stuff) filter the function names from the output, using sed or grep+cut
  • Now, for every function signature, you need to generate a piece of code to put in the .cpp intended to be a DLL. This can probably be done with echo and a template, substituting some variables for what you've obtained as the signature. And before writing anything else in it, write whatever initial header you want.
  • You might also need to do about the same for a .h file (just the declarations).

That's the code itself. As for the MSVC project file - you're on your own figuring out how to generate it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.