Import one dll to another dll

Pages: 12
May 16, 2011 at 8:36pm
I created my own DLL which does exporting. Now I wanna do imports, I want to load the same function from another import function DLL (ex. user32.dll). I tried to do LoadLibrary, it does load the DLL but nothing is being imported in my DLL.

Basically I want to see my DLL IAT has user32.dll with all the functions in the IAT.
Last edited on May 16, 2011 at 8:39pm
May 16, 2011 at 10:43pm
I don't understand the question.

Are you trying to make your DLL export the same function as one in user32.dll?
May 16, 2011 at 11:30pm
First, I am assuming that IAT stands for Import Address Table? If not then skip the rest of this post.

You're going about this wrong. What you would do in this case is write your executable to mediate communication between the two DLL's. You do this with Function Pointers and Call Backs, not by mergeing two tables and hoping for they work. Now, if what you're trying to do is make sure that a call to a function normally in user32.dll actually gets processed by your Lib, then that's a different story.
May 17, 2011 at 1:33pm
I'm trying to do this

User32.dll --> (import) --> My DLL

Where does windows xp keep their Lib for all their dll's?
May 17, 2011 at 1:52pm
I should imagine User32.lib comes with the Windows SDK. I certainly have a copy of it in there.
Last edited on May 17, 2011 at 1:53pm
May 17, 2011 at 3:44pm
User32.lib does indeed come with the Windows SDK, I'm looking at it right now in fact. But if you are using another compiler then you'll want to use the lib that came with that one instead. For example, I use MingW so I would use the file "libuser32.a" in order to access the functions in that DLL.
May 17, 2011 at 3:54pm
@Computergeek Where would one get libuser32.a? It doesn't come with MinGW, does it? And I can't imagine Microsoft providing one.
May 17, 2011 at 4:03pm
It comes with MingW, under the lib folder. It's just an import library made for that dll made by MingW.
May 17, 2011 at 4:16pm
My bad - I didn't look hard enough for it in the MinGW directory. It was there though.
May 17, 2011 at 5:37pm
Anyone know where I can get Windows SDK offline?

EDIT: I found the offline version.
Last edited on May 17, 2011 at 5:39pm
May 17, 2011 at 5:45pm
I cannot tell you how happy I am that you edited this two minutes after you asked that question.
May 17, 2011 at 6:57pm
@computergeek01

If I look under PEview, it does not show any IAT(import address table) in my dll. How do I load my IAT into my dll from the functions of user32.dll? Without writing an exe, this has to be done in the dll.

I did go under properties -> linker->input->additional dependencies , add the user32.lib but I see nothing any IAT in my dll.
Last edited on May 17, 2011 at 7:02pm
May 17, 2011 at 7:03pm
Are you trying to statically link to this DLL? I only ask because that isn't what your first question sounded like.

Also, IDE are you using?
May 17, 2011 at 7:12pm
I just want my dll that has IAT with functions from user32.dll. That is my goal.
I'm using Visual Studio 2010.
May 17, 2011 at 7:16pm
That's not how you're supposed to use DLL's though... I'm certain this is possible but because I've never wanted to do it I'll have to look it up.
May 17, 2011 at 7:57pm
No luck with this :(
1
2
#pragma comment(lib, "user32.lib")
#pragma comment(linker, "/include:AnyPopup") 


Basically, user32.dll has export function called AnyPopup which that function should be import into my IAT dll.

My IAT should show the function AnyPopup from user32.dll
Last edited on May 17, 2011 at 8:05pm
May 17, 2011 at 8:52pm
I don't understand the SOURCE of the problem.
When you will need to call AnyPopup from your Exe (the one that you want to call AnyPopup from your DLL right at the moment), you will need to declare it first right? For that, you will have to include the system header file in which it is declared, and then you will just need to link user32.lib in the Exe and that's it.
Are you for some reason forbidden to include user32.lib directly in the Exe, but in the need to use one of it's functions?
Also, when you include that header for the declaration of AnyPopup in your DLL, the symbol of AnyPopup is declared as imported in your DLL. FOr it to be visible in the export table of your DLL, it would have to be declared as exported.
May 18, 2011 at 1:56pm
@bartoli

Yes, I am forbidden to do anything in the exe. This all has to be done in my DLL. AnyPopup is just a short example, but I do have to use all the functions in user32.dll.

All the imports and exports has to be done in my DLL.
Last edited on May 18, 2011 at 6:14pm
May 19, 2011 at 1:54am
What are you really trying to do ? Sounds like hooking user32.dll, in which case look at Microsoft Detours library.
May 19, 2011 at 2:11pm
Yes, it hooking user32.dll(exports) to my DLL(imports), but I am not modifying any functions. I am just trying to get all the export functions in user32.dll into my import address table (IAT) in my DLL.
Last edited on May 19, 2011 at 2:24pm
Pages: 12