1

I am trying to create a Managed DirectX 9 Device in a DLL and then use that DLL to render scenes to an offscreen surface. I know how to do the offscreen rendering, but my question is:

Is it possible to create a directx device inside a DLL?

Feeble attempt #1 (InvalidCallException):

Device device = new Device(0, DeviceType.Hardware, null, CreateFlags.SoftwareVertexProcessing, presentParams);

Feeble attempt #2 (InvalidCallException):

Device device = new Device(0, DeviceType.Hardware, new IntPtr(0), CreateFlags.SoftwareVertexProcessing, presentParams);

The device constructor overloads available are:

public Device(int, DeviceType, Control, CreateFlags, PresentParameters[]);
public Device(int, DeviceType, IntPtr, CreateFlags, PresentParameters[]);

Any help could quite possibly make my day!

tbridge
  • 1,754
  • 1
  • 18
  • 35
  • remind me how we normally create a device if it were not in a DLL. – BeemerGuy Nov 18 '10 at 04:11
  • instead of passing in `null` or `new IntPtr(0)` you pass in a `Control` object or `IntPtr` handle to that control object, which is the 'render window' – tbridge Nov 18 '10 at 04:14

1 Answers1

0

Found the answer. I created a hidden control, set the width and the height of it appropriately and then set it as the target. Works perfect. For those who may stumble upon this later here is the code:

// Create the hidden control
Control hiddenControl = new Control();
control.Width = width;
control.Height = height;
control.Visible = false;         // Just for good measure, it wouldn't be displayed anyways

// Present Parameters
PresentParamaters presentParams = new PresentParamaters();
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.Windowed = true;

// Create the device
Device device = new Device(0, DeviceType.Hardware, hiddenControl, CreateFlags.SoftwareVertexProcessing, presentParams);

Thats all it takes, assuming like I said before you are rendering to a texture. I'm not sure what (if anything) would happen if you were to actually render to this control.

tbridge
  • 1,754
  • 1
  • 18
  • 35