Sign in to follow this  
vivendi

[C++] What kind of dll??

Recommended Posts

If i want other people to make use of the classes/functions inside my dll. What kind of dll do i need to create? A static dll or dynamic dll?? Example, I have a class defined in my dll with public functions inside that class. Are other then able to call my class from my dll and have access to those functions??

Share this post


Link to post
Share on other sites
Quote:
Original post by vivendi
If i want other people to make use of the classes/functions inside my dll. What kind of dll do i need to create? A static dll or dynamic dll??
I'm assuming you mean "a static library or a dynamic library". A static library is a .lib file, which is linked at compile time. A dynamic library is a .dll (Hence, Dynamic Link Library), and is linked at runtime.

Quote:
Original post by vivendi
Example, I have a class defined in my dll with public functions inside that class. Are other then able to call my class from my dll and have access to those functions??
You can use a static or dynamic library, it's entirely up to you. Using a static library, your code gets linked into the target .exe file, using a dynamic library it'll be in its own DLL file which the .exe then accesses.

Share this post


Link to post
Share on other sites
Ok thanks. I thought a DLL also had its differences.

So now i have created a dll with only the dllMain function.
I also have 2 other files in that DLL project. One source file and one header file. And ofcourse the headerfile contrains the class structure and the sourcefile has the functions/logic that belong to the class.

So if i want to use that function from another application, do i still use GetProcAddress() to retrieve the name of the class, so i can access the public members?? Or is this going to be a different approach?

I haven't found any information yet about this particular subject. So any good info about this is always welcome :)

Share this post


Link to post
Share on other sites
Quote:
Original post by vivendi
So if i want to use that function from another application, do i still use GetProcAddress() to retrieve the name of the class, so i can access the public members?? Or is this going to be a different approach?

The common way is to include the header files in the application project, and to link the DLL with the application project. Later, when the runtime system starts the application, it recognizes with which DLLs the application was linked and tries to load that DLLs. If that was successful, it binds the functions of the DLL to their invocation points in the application. In such a scenario you should not need to invoke GetProcAddress().

As a special usage, e.g. for a plug-in system, you can also avoid to link with the DLL and instead load it manually at runtime. In such a situation you will need to use GetProcAddress().

BTW: GetProcAddress() doesn't return the name of a class. It returns the address of a function, class method (what is a function after compilation, though), variable, or similar.

Share this post


Link to post
Share on other sites
Quote:
Original post by vivendi
Ok thanks. I thought a DLL also had its differences.

So now i have created a dll with only the dllMain function.
I also have 2 other files in that DLL project. One source file and one header file. And ofcourse the headerfile contrains the class structure and the sourcefile has the functions/logic that belong to the class.

So if i want to use that function from another application, do i still use GetProcAddress() to retrieve the name of the class, so i can access the public members?? Or is this going to be a different approach?
There's also static linking to a DLL (Linking with a .lib file), or dynamic linking (LoadLibrary() and GetProcAddrss()).

If you're doing anything with classes, you'll want to stay the hell away from GetProcAddress, unless you want a world of pain.

Share this post


Link to post
Share on other sites
The classes in a C++ DLL tend to be exported automatically, but this is compiler-specific. If you use classes directly, be warned that your DLL and executable likely have to be built with the same compiler in order to function together, due to differences in C++ name mangling between compilers. Regardless, your compiler will produce an appropriate exports definition file against which your application must link to make use of the DLL.

A common solution that allows the DLL to be used with any compiler is to provide an interface of C-style functions that manipulate C++ objects behind the scenes. If you do this, just make sure to use 'extern "C"' to turn off C++ name mangling.

Share this post


Link to post
Share on other sites
Quote:
Original post by EvincarOfAutumn
A common solution that allows the DLL to be used with any compiler is to provide an interface of C-style functions that manipulate C++ objects behind the scenes. If you do this, just make sure to use 'extern "C"' to turn off C++ name mangling.


I guess that's the one i need then. Because i'm only going to create a dll file. Others have to use the functionality of my dll.

Do you know a site or other resource that explains more about this? I'm not really sure how to code my dll right now.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this