Reputation: 11
When I attempt to create a device and swapchain D3D11CreateDeviceAndSwapChain fails with 887a0001. I am trying to call this from my dll.
DXGI_SWAP_CHAIN_DESC sd;
ZeroMemory(&sd, sizeof(sd));
sd.BufferCount = 2;
sd.BufferDesc.Width = 0;
sd.BufferDesc.Height = 0;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.OutputWindow = hWnd;
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;
sd.Windowed = FALSE;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
UINT createDeviceFlags = 0;
D3D_FEATURE_LEVEL featureLevel;
const D3D_FEATURE_LEVEL featureLevelArray[2] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0, };
HRESULT res = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, createDeviceFlags, featureLevelArray, 2, D3D11_SDK_VERSION, &sd, &swapchain, &device, &featureLevel, &devicecontext);
if (res != S_OK) {
printf("failed to create device and swap %llx\n", res);
return false;
}
Ive seen a few issue resolved by threading it differently but I havent had any luck in doing so.
__int32 __stdcall DllMain(void* baseaddress)
{
Start();
return 1;
}
The function start is where I create my window, attempt to create my device and thread the message dispatcher
Upvotes: 1
Views: 2114
Reputation: 139187
If you debug your program, you should see this in the output:
DXGI ERROR: CreateDXGIFactory cannot be called from DllMain. [ MISCELLANEOUS ERROR #76: ]
This is expected as explained here: DXGI responses from DLLMain (D3D11CreateDeviceAndSwapChain
will implicitly create a DXGI factory)
If your app's DllMain function creates a DXGI factory, DXGI returns an error code.
So, you must not call this from DllMain
(this is anynay a very special place where some black magic voodoo happens.)
Upvotes: 1