# DirectX inside a form

This topic is 4373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, so I am trying to create a DirectX display within a windows Form object in C++. The problem is that I am having some issues initialising it. Although the code compiles fine, I get the error: D3DERR_INVALIDCALL when creating the D3D device. Here is the line giving the error (called when creating the window):

try
{
PresentParameters^ presentParams = gcnew PresentParameters();

device =
gcnew Device(
0,
DeviceType::Hardware,
render->Handle,
CreateFlags::SoftwareVertexProcessing,
gcnew cli::array<PresentParameters^> {presentParams});
}
catch (Microsoft::DirectX::DirectXException^ e)
{
MessageBox::Show(e->ToString(),
"Error", MessageBoxButtons::OK, MessageBoxIcon::Error);
return;
}


render is a pannel (though using the form itself doesn't seem to help) and device is of type Device ^. I have been googling around, but almost all evamples are for anything but C++... If anyone has an example of displaying a DirectX window within a form, or what is wrong with my code, then please let me know, thanks :)

##### Share on other sites
You forgot to set some default variables. Although the window width and height and all the other variables aren't needed it's generally good practise to set them. What you forgot was the SwapChain effect.

I hope this helps.
Take care.

##### Share on other sites

I had tried setting a few properties, but that was one I hadn't tried. Seems to work perfectly now :)

Just need to figure out a nice way to thread it so I can use buttons etc at the same time...