Creation of a ID2D1DCRenderTarget

0

I'm trying to create a GDI device context from Direct2D but when I call CreateDCRenderTarget, it returns D2DERR_NO_HARDWARE_DEVICE error and my RenderTarget is null. Is there something wrong with the properties ?

ID2D1Factory* _pDirect2dFactory = NULL;
ID2D1DCRenderTarget *_pRenderTarget = NULL;

D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
    D2D1_RENDER_TARGET_TYPE_DEFAULT,
    D2D1::PixelFormat(
        DXGI_FORMAT_B8G8R8A8_UNORM,
        D2D1_ALPHA_MODE_IGNORE),
    0,
    0,
    D2D1_RENDER_TARGET_USAGE_NONE,
    D2D1_FEATURE_LEVEL_DEFAULT
    );

  HRESULT hr;

  hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &_pDirect2dFactory);

  if (_pDirect2dFactory)
  {
    // *** ERROR here *** : hr=0x8899000B (D2DERR_NO_HARDWARE_DEVICE)
    hr = _pDirect2dFactory->CreateDCRenderTarget(&props, &_pRenderTarget);
  }

EDIT : That code works fine when it is called from my executable but do not work when it is called from another program through my injected DLL.

EDIT2 : Well, that works now. This code was called when my DLL was attached and I think that D2D1.dll was not correctly attached to the process yet.

c++
windows
hook
direct2d
dll-injection
asked on Stack Overflow Aug 27, 2013 by Michael M. • edited Aug 27, 2013 by Michael M.

1 Answer

0

For those who still had a same problem injecting dll which creates d2d, try putting the function into a new thread. In my case, I put directly the d2d creating function into new thread by CreateThread in DllMain and it works.

answered on Stack Overflow Apr 30, 2018 by LeePai Chan

User contributions licensed under CC BY-SA 3.0