Original Post
I''m attemping to get DirectInput up and running with C# but I''m having a bit of a problem. I''m new to DirectX, so I''ve been following the tutorials in the SDK. Specifically, my problem is setting up the buffer size. Here''s the function I use to initialize DirectInput:
The problem is the call SetProperty("DIPROP_BUFFERSIZE", pdiProp). This is the exception I''m getting:
An unhandled exception of type ''System.ArgumentException'' occurred in SpaceBreakout.exe
Additional information: The parameter is incorrect.
This code is taken (almost)verbatim from the SDK (ported to C# of course), so maybe there''s a better way of doing this.
Any help/ideas would be greatly appreciated!
public void InitializeDirectInput(int hwnd, DirectXEvent app)
{
m_objDirectInputDevice = m_objDirectInput.CreateDevice("GUID_SysMouse");
m_objDirectInputDevice.SetCommonDataFormat(CONST_DICOMMONDATAFORMATS.DIFORMAT_MOUSE);
m_objDirectInputDevice.SetCooperativeLevel(hwnd, CONST_DISCLFLAGS.DISCL_FOREGROUND | CONST_DISCLFLAGS.DISCL_EXCLUSIVE);
DIPROPLONG diProp = new DIPROPLONG();
diProp.lHow = (int)CONST_DIPHFLAGS.DIPH_DEVICE;
diProp.lObj = 0;
diProp.lData = 128;
System.IntPtr pdiProp = new System.IntPtr();
pdiProp = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(DIPROPLONG)));
Marshal.StructureToPtr(diProp, pdiProp, true);
m_objDirectInputDevice.SetProperty("DIPROP_BUFFERSIZE", pdiProp);
Marshal.FreeHGlobal(pdiProp);
int eventHandle;
eventHandle = m_objDirectX.CreateEvent(app);
m_objDirectInputDevice.SetEventNotification(eventHandle);
}