PDA

View Full Version : Exporting from a dll



Atomic_Sheep
8th April 2013, 12:27
Hi Guys, trying to figure out this exporting from a .dll malarkey. Have a lot of knowledge gaps which don't seem to want to be filled courtesy of google.

If I have a .dll file that holds functions/variables that I want to use in my .exe

1.) Does it only spit out values when the application that is running the .dll and conversely, not producing any values when the application ceases to work? Or does standard computer operation kick in whereby when the application not using the .dll is not running, the results I'll be getting in my .exe will be garbage? The third alternative is of course that I'm so confused about all this that what I'm saying is making little sense all together!

2.) From what I've read, when exporting variables/functions etc from a .dll, (this but I don't fully understand as I don't fully understand what the linker is or what it does exactly - I've read about it in the past but I just use it and haven't payed much attention to what it does under the hood... anyway) the linker assigns the variables/functions 'decorated names' and 'ordinals'. What is the difference between a decorated name and an address or is a decorated name a type of address? Why does the linker simply not spit out the address of the thing I'm trying to link to? More importantly, how do I actually tell my .exe to look for various variables that I'm importing via:


__declspec(dllimport) int test;

Does this line basically tell my program to go and look for the memory location/pointer that will hold the variable that I want? Everywhere I read, that seems to be the line that I need to input but my gut tells me there's more that needs to be included in the code. Otherwise, how does it know where the .dll is in the first place? I haven't put the compiled .dll into the build directory of my .exe and to me that would seem kinda pointless anyway considering that the .dll needs to be in the directory of the application that is going to be using the .dll in the first place, so how do I link to that .dll?

amleto
20th April 2013, 14:53
yes, that's the correct line. It just says 'that this variable is imported from a dll - Linker, go find it!'

So it's up to you to link your app with a dll that contains that variable. Just link it like you would to any dll.