Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quick question about DLLs

Started by Trillian Jun 29, 2007 at 11:31 AM 2 replies 550+ views
Original Post
Trillian
Trillian
Hello Let's say I have a project compiled as a DLL called "Display" which contains classes to handle windows and such. In this project, there's a class called "Size" which represents the width/height of, for example, a window. A method called Size::area() retrieves the area of the size object (width*height). If I implement this method in a .cpp file, but I don't declare the method (in the .h file) as using "__declspec(dllimport)", will it be compiled into the DLL or into the dll-linking .lib, like if I was building a static library? [EDIT] Let me make this clearer : 1- Does symbols not declared as "__declspec(dllexport)" get compiled into the dll-linking .lib? 2- If this is the case, is it possible to compile a DLL without any "__declspec(dllexport)" symbols and use it as a static library? Thanks! [Edited by - Trillian on June 29, 2007 12:04:54 PM]
Nypyren
Nypyren
1 - Yes. The dllexport just provides an extra mechanism to locate that symbol from the "outside" of the DLL. They are used when an EXE loads the DLL at runtime and needs to look up the memory locations of those variables or functions. In a way, the dllexported variables/functions are kind of like the public interface for a class, and anything else is private.

2 - You can compile a DLL without any exports, but it will not become a .lib file. You CAN, however, just change your project options to output a .lib file in the first place.
Trillian
Trillian
Thanks a lot, that information is nice to know. Don't worry, I don't intend to do #2!

3- Can I compile a dll which isn't automatically loaded to when you link to it's .lib? This would enable me to load the dll-exported symbols using a non-exported function, which would allow me to detect if the loading went well instead of getting the usual DLL NOT FOUND dialog box.
LessBread
LessBread
__declspec(dllexport) tells the linker to add the symbol it modifies to the export table in the dll file header.

If you link to the .lib file of a dll, and the exe can't find that dll at runtime, the exe won't run at all. If you want your exe to run regardless of whether the dll can be found, you'll need to use dynamic linking. Look up LoadLibrary and GetProcAddress for details.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.