0

I am writing a windows App in MS Visual Studio 2017 and having a little trouble using a Direct 2D Factory object and Buttons. It appears that if I create the direct 2D Factory object first a.k.a. run:

HRESULT AppObject::CreateDeviceIndependentResources(){
       hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED,&m_pDirect2dFactory);
       return hr;
    }

The factory object is created correctly with a pointer stored in "m_pDirect2dFactory" as it should be. This object pointer persist through the creation of the main window:

m_hwnd = CreateWindowEx(0, ...  

and through the creation of the child windows:

m_hwndRenderView = CreateWindowEx(0, 
                                   L"AppChildWindow", 
                                   L"ChildWinName", WS_CHILD | WS_BORDER | WS_VISIBLE, 
                                   ...   

However when the code creates the Buttons:

m_hwndButton = CreateWindow(L"BUTTON", 
                            TEXT("button name"),
                            WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                            m_buttonStart_pixX,
                            cur_button_pixY,
                            button_pix_width,
                            button_pix_height,
                            m_hwnd,
                            (HMENU)(int)(CORE_BUTTON_IDSTART+1),
                            (HINSTANCE)GetWindowLong(m_hwnd, GWL_HINSTANCE),
                            NULL);

The value of the pointer "m_pDirect2dFactory" changes to an apparently invalid value which causes an error when m_pDirect2dFactory->Release() is called. Or, in other words, the creation of the buttons tampers with the factory object created by D2D1CreateFactory.

Is this a know issue?

BDL
  • 21,052
  • 22
  • 49
  • 55
  • we need an [mcve], presumably one of the variables you pass to `CreateWindow` is incorrect but as we don't know what these variables are its difficult to help. – Alan Birtles Aug 22 '18 at 07:10
  • Sorry about getting back so late. I found the problem myself. 1st I had simplified this example. In the real code m_hwndButton = CreateWindow(...) was actually a loop m_hwndButton[i]=CreateWindow(..). The memory reserved for the m_hwndButton array was only 5 or so. However I tried to create 10 m_hwndButton windows. When this happened i overwrote the next variable in the object which was my m_pDirect2dFactory pointer with a hwnd window handle hence destroying the pointer. – blackbird658 Sep 08 '18 at 15:08

0 Answers0