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.