Sign in to follow this  

DLL and singlton problems

This topic is 4839 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

Hello, I am trying to export a singleton class to a dll, when I run the first error I had was with the following line: cConsoleLog(); cConsoleLog(const cConsoleLog&) { } cConsoleLog& operator = (const cConsoleLog&) { } normaly the last line there works but when compiling from a dll it doesnt like that at all, says the opertor = must return a value (which makes sense but it never asked about it before) , the entire point is I dont want it ti return a value I dont even want it access so its private, but I fixed that by making it return the class and still making it private, will that cause problems later? The second problem I have is I have an instance of stl vectors in another singleton class vector<textures> but I get the following error message: c:\My Documents\Visual Studio Projects\SEngine\Headers\texture.h(80): warning C4251: 'cTextureManager::textures' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'cTextureManager' with [ _Ty=stexture ] a rather strange one it is. The last problem and the biggest I belive I have is when I try to delete any of those singetons in the program accessing the dlls aka if(Log) delete Log , I get a pHead->isVaild error, (the kind you get when your trying to access memory you dont have access too. Any help is appreciated thank you very much, Me

Share this post


Link to post
Share on other sites
Quote:
Original post by Blackkata
normaly the last line there works but when compiling from a dll it doesnt like that at all, says the opertor = must return a value (which makes sense but it never asked about it before) , the entire point is I dont want it ti return a value I dont even want it access so its private, but I fixed that by making it return the class and still making it private, will that cause problems later?

Usually you just do retrun *this; in operator=. You should be able to do that here without any problems.

Quote:
Original post by Blackkata
The second problem I have is I have an instance of stl vectors in another singleton class vector<textures> but I get the following error message:

c:\My Documents\Visual Studio Projects\SEngine\Headers\texture.h(80): warning C4251: 'cTextureManager::textures' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'cTextureManager'
with
[
_Ty=stexture
]

I'm not sure about the error, but be very careful when using the STL in a DLL. You can't insert / erase elements in the DLL and EXE, one of them has to take control of the object. So you shouldn't expose the vector at all.

Quote:
Original post by Blackkata
The last problem and the biggest I belive I have is when I try to delete any of those singetons in the program accessing the dlls aka if(Log) delete Log , I get a pHead->isVaild error, (the kind you get when your trying to access memory you dont have access too.

Thats probably related to the second question. You can't allocate memory in the DLL and free it from the EXE. Under Windows, the DLL and the EXE use different heaps, so if you allocated the memory in the DLL, and try to free it in the EXE, the EXE's heap doesn't own the memory (as you said), so you get the error.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by Blackkata
The last problem and the biggest I belive I have is when I try to delete any of those singetons in the program accessing the dlls aka if(Log) delete Log , I get a pHead->isVaild error, (the kind you get when your trying to access memory you dont have access too.

Thats probably related to the second question. You can't allocate memory in the DLL and free it from the EXE. Under Windows, the DLL and the EXE use different heaps, so if you allocated the memory in the DLL, and try to free it in the EXE, the EXE's heap doesn't own the memory (as you said), so you get the error.


So place create()/destroy() methods in the singleton class, then these can be called by the app, because the functions are in the DLL, and so are using the DLL heap

SwiftCoder

Share this post


Link to post
Share on other sites

This topic is 4839 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