c++winapidirect2ddll-injectiondirect3d11

Direct2D Error NO_HARDWARE_DEVICE When Injecting Dll Into Another Process


I have a native target application that renders something by using Direct3D11. I want to extend the functionality of the target by injecting a DLL and hooking some APIs(not important to mention but it is XInputGetState). When DLL is injected, it also creates a window and provides some useful information. To render the information in the window, I use Direct2D, but after injecting the DLL, in another process's address space, calling the ID2D1Factory::CreateHwndRenderTarget fails with the error code D2DERR_NO_HARDWARE_DEVICE and doesn't create the ID2D1HwndRenderTarget object. The Factory object is created successfully and it is not NULL.

When I change the project type from Dynamic Link Library(.dll) to Application(.exe) and the entry point from DllMain to main and run it as a separate console application, the ID2D1Factory::CreateHwndRenderTarget succeeds.

I think that the problem causes by the existence of a created Direct3D11 Device already, but I am not sure.

Is there documentation about that? How can I solve the issue?


Solution

  • Put directly the D2D creating function into new thread by CreateThread in DllMain.