I have an Dll which get´s an instance of a static member. (a singelton)
And this singelton was initialized in the main exe.
But when i try to acces the singelton in the dll it crashes due to that it points to null.
How do i make it possible for the dll to gain the correct pointer for my singelton?
//in the lib.
class MyClassDLL
{
public:
static MyClassDLL* mySingeltonPointer;
void Houlabdoula(void);
};
//in the exe
MyClassDLL::mySingeltonPointer = new MyClassDLL();
//in the dll
MyClassDLL::mySingeltonPointer->Houlabdoula(); //<--- this is where the error occurs becus of //that mySingeltonPinter now is null..
Ok, that is something. Now you need to show the flow of the code. Does the line in the exe file run before or after the line in the DLL? I guess I know the answer: The exe line runs AFTER the dll line, but what I'm looking for is really more detail as to where those lines are placed in each project.
int main(Void)
{
MyClassDLL::mySingeltonPointer = new MyClassDLL();
MyDllFileStuff->Run(); //in this function
//MyClassDLL::mySingeltonPointer->Houlabdoula(); this function is called.
return 0;
}
your dll and exe use different memory, so your singleton should be placed at dll or at separated dll with it own heap.
as I remember this question called: inprocess and outprocess dll's