You are laboring under some false assumptions RawBits.
First, every process that loads your Dll will have fresh instances of all variables in the Dll - even globally defined data.
Secondly, if you are creating a 'control' as opposed to something that just does data crunching, then there is a window class that needs to be registered for the control. Your host/client should then be able to create an instance of the control through a CreateWindowEx() function call where the class name of your control is passed in through the szClassName parameter of the call. At the point of the CreateWindowEx() call on the custom control registered in the dll the created object will receive a WM_CREATE message. The Window Procedure for the custom control should be in your dll. In the WM_CREATE handler you need to perform a memory allocation for whatever 'state' data your control needs to do whatever it does. Here is an example. I'm clueless what your control does, but lets say every instance of it needs to maintain a unique integer value and a unique character string. Then make a struct like so...
1 2 3 4 5
|
struct Something
{
int iSomeNumber;
TCHAR szSomeString[64];
};
|
Then, in your WM_CREATE handler, which will be called exactly once for each instance of a control created, you will do a memory allocation for a Something struct, and store the pointer to that memory either within the Window Class structure througfh the WNDCLASSEX::cbWndExtra bytes, or through Window Properties, i.e., GetProp() / SetProp().
For example...
1 2 3 4 5 6 7
|
Something* pSomeThing=NULL;
pSomeThing=(SomeThing*)GlobalAlloc(GPTR,sizeof(Something));
if(pSomething)
{
SetWindowLong(hWnd,0,(long)pSomething);
}
|
In your WM_DESTROY handler you need to release any allocated memory.
Using this technique every instance of your control will maintain 'state' and be seperate from every other instance.