DLL and singlton problems

Started by
1 comment, last by swiftcoder 19 years, 7 months ago
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
Advertisement
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.
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

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement