Sign in to follow this  

classes in DLLs

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am doing a project in which a lot of class objects are shared between a EXE and several DLLs... and would like to know more about how the objects are handled, shared, and executed... The usual way is to have a class defined as __dllexport in the DLL code. If I understand correctly, this way, the executing code of the class resides in the DLL, when the DLL is linked to the EXE, all the class method calls are binded to the DLL code. Now, what if I have a class, NOT defined as __dllexport, but defined in both the EXE and the DLL ? I figure that, execution code is generated in both the EXE and the DLL, so, no binding is needed. But, how much compatible is the code? If i have an object residing in the EXE space, and I pass a reference of it to the DLL, can the DLL execute its methods safely? , and what code for that class executes the DLL? the code residing in the DLL or the code in the EXE? thanks in advance

Share this post


Link to post
Share on other sites

The local code is executed (ie. dll uses its own code and the exe its own).
This can lead to serious errors if the class definition is changed and no recompile is done.

It is ok to use same class in the exe and dll but sharing them should be avoided.

I'd say that better practise is to use abstract classes and share them between the exe and dll. Then code needs to be only in one place (exe or dll).

Share this post


Link to post
Share on other sites
Quote:
Original post by Demus79

I'd say that better practise is to use abstract classes and share them between the exe and dll. Then code needs to be only in one place (exe or dll).


That means making an abstract class with pure virtual funcions, that will be shared between the DLL and the EXE, and having a derived class, with the actual function definition, only in one of the sides, and hidden to the other side, right?

Share this post


Link to post
Share on other sites

Quote:

That means making an abstract class with pure virtual funcions, that will be shared between the DLL and the EXE, and having a derived class, with the actual function definition, only in one of the sides, and hidden to the other side, right?



right

if the class is defined in the dll, you can export a function for creating instances of the derived class inside the dll.

Share this post


Link to post
Share on other sites

This topic is 4304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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