# Starting with SlimDX.

## Recommended Posts

I'm currently trying to use SlimDX, but I'm getting an unhelpful 'Invalid Call' when trying to create the device - i.e. the very first step! I've looked at the examples, but they all use the huge 'SampleFramework' which is a nightmare to dig through. MiniTri, the one example that doesn't, crashes whenever I run it. My code is as follows:
        private void Form1_Load(object sender, EventArgs e)
{
this.Size = new Size(800, 600);
IntPtr windowHandle = this.Handle;

Direct3D direct3D = new Direct3D();

PresentParameters presentParams = new PresentParameters();
presentParams.BackBufferWidth = 800;
presentParams.BackBufferHeight = 600;
presentParams.Windowed = true;

Device device = new Device(direct3D, 0, DeviceType.Hardware, windowHandle, CreateFlags.HardwareVertexProcessing, presentParams);

device.BeginScene();
device.Clear(ClearFlags.Target, 0, 0F, 0);
device.EndScene();

device.Present();
}

Can anyone see why the code might be crashing on the Device instantiation? The exception, as if it helps, reads 'D3DERR_INVALIDCALL: Invalid call (-2005530516)' Also, as a side question, are there any issues with getting SlimDX working in a WPF application? Thanks! :)

##### Share on other sites
Enable unmanaged debugging for your project and create the device with the debug flag. This will cause D3D to emit diagnostics to the output window.

An invalid call often means the parameters you passed to the function are nonsense. The MiniTri sample is likely crashing for exactly the same reason (since it's "mini" it does no error checking; an invalid call exception will be uncaught and terminate the application).

Are you sure your machine supports the parameters you assigned to the present parameters? Remember that this is C#, so value types (like PresentParameters) are default-initialized. For most of the values in that structure, this will be the equivalent of a zero, which may not correspond to a sane value. It is best to explicitly set all fields of PresentParameters when trying to diagnose this kind of issue.

##### Share on other sites
Thanks, I'll try that!

Any help with my side question - will I encounter any issues trying to get this working with WPF? I think WPF uses DX for its own rendering, and I've heard of 'issues' getting the two working together, but I don't know to what extent.

Thanks again. :)

!!! EDIT !!! : When you say 'and create the device with the debug flag', how do I set this? I've looked through the CreateFlags enumeration, and the PresentParameters class, and see no reference to a debug flag.

[Edited by - Bargaust on December 19, 2008 5:43:36 PM]

##### Share on other sites
you can find the debug mode setting in the directx configuration tool, given along the DirectX SDK.

http://slimdx.mdxinfo.com/wiki/index.php?title=Debugging_Tips

##### Share on other sites
Quote:
 Original post by Bargaustwill I encounter any issues trying to get this working with WPF? I think WPF uses DX for its own rendering, and I've heard of 'issues' getting the two working together, but I don't know to what extent.

Prior to .NET 3.5 SP1, using WPF and DirectX together was a problem. In .NET 3.5 SP1, Microsoft exposed the ability to draw to a surface using the new D3DImage image source. Basically you can apply the surface as a brush to anything you want. :-)

Dr. WPF posted a very good article outlining the usage of the D3DImage with DirectX. If you want to understand how the image source works, I would highly recommend giving it a read.

Introduction to D3DImage

Also check out this post on GameDev:WPF D3DImage with SlimDx.

-Bill

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628275
• Total Posts
2981762

• 10
• 11
• 17
• 10
• 9