   [SlimDX, C#] Software renderer - SOLVED
  Hello everybody,I'm switching my application from MDX to SlimDX.The application works correctly and I've found myself all the solutions for my problems.The only thing that I cannot port is the use of the Software renderer.I use some times this option in very old machines (the application is very simple, so the software renderer can do the work with a decent frame rate).I read in the documentation that DeviceType.Software is not supported.But in the MDX too I think it was not supported, but with a trick I can use it.Here the code to register the software renderer I use in MDX:[System.Runtime.InteropServices.DllImport("kernel32.dll")]static extern IntPtr LoadLibrary(string lpFileName);[System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi, ExactSpelling = true)]public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);[System.Runtime.InteropServices.Guid("81BDCBCA-64D4-426d-AE8D-AD0147F4275C"), System.Runtime.InteropServices.InterfaceType(System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIUnknown)]public interface ID3D9{  int RegisterSoftwareDevice(IntPtr fnction);  // No reason to add the rest of the interface}private bool registerSoftwareRenderer(){  bool result = false;  try  {    IntPtr hRast = LoadLibrary("RGB9Rast_1.dll");    IntPtr D3D9GetSWInfo = GetProcAddress(hRast, "D3D9GetSWInfo");    System.Reflection.FieldInfo info = typeof(Direct3D).GetField("m_lpUM", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);    IntPtr D3D9Ptr;    unsafe    { D3D9Ptr = new IntPtr(System.Reflection.Pointer.Unbox(info.GetValue(null)));    }    ID3D9 D3D9 = (ID3D9)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(D3D9Ptr, typeof(ID3D9));    int error = D3D9.RegisterSoftwareDevice(D3D9GetSWInfo);    if (error == 0) result = true;    }    catch    { result = false;    }    return result;}The call to GetField is the notch, the class Direct3D.Manager doesnt exist in SlimDX.Maybe the class Direct3D9.Direct3D can be used but I dont know how.Thank you[Edited by - scosta on September 9, 2009 2:08:27 AM]
  I want to edit the subject of the thread but I cannot...The edit button is not visible in my post, but is visible in other posts, not mine!Very very strange... :(I've tried with IE and Firefox   ;  I don't know what type is m_lpUM, but if it is IDirect3D9, then there is no need to use Reflection/FieldInfo's in SlimDX for that.SlimDX provides IDirect3D9 pointer as ComPointer property in SlimDX.Direct3D9.Direct3D class.Or better - put a request on SlimDX issue tracker to add RegisterSoftwareDevice member function for public interface in SlimDX.Direct3D9.Device class, so it can be used in normal way.[Edited by - bubu LV on September 2, 2009 8:30:01 AM];  Thank you bubu LV,I don't know exactly what type is m_lpUM (I think IDirect3D9), I've found that code in the web.I don't know how to try the ComPointer because the software renderer registration is done before the device is created.At this point the Device is null.For the issue tracker, I will try to add an issue if I don't find a solution.P.S. Now I've edited the subject   ;  Solved!I've used the ComPointer of my static variable Utility.Manager.Its a Direct3D9.Direct3D object that I use like the old MDX Direct3D.Manager.I'm very happy... so the software renderer can be used in SlimDX too.Take a look at the code:   private bool registerSoftwareRenderer()   {  bool result = false;  try  { IntPtr hRast = LoadLibrary("RGB9Rast_1.dll"); IntPtr D3D9GetSWInfo = GetProcAddress(hRast, "D3D9GetSWInfo"); //System.Reflection.FieldInfo info = typeof(Direct3D).GetField("m_lpUM", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); //IntPtr D3D9Ptr; //unsafe //{ //    D3D9Ptr = new IntPtr(System.Reflection.Pointer.Unbox(info.GetValue(null))); //} IntPtr D3D9Ptr = Utility.Manager.ComPointer; ID3D9 D3D9 = (ID3D9)System.Runtime.InteropServices.Marshal.GetTypedObjectForIUnknown(D3D9Ptr, typeof(ID3D9)); int error = D3D9.RegisterSoftwareDevice(D3D9GetSWInfo); if (error == 0)result = true;  }  catch  { result = false;  }  return result;   }Thanks   ;  What is Utility.Manager ?   ;  It's a Direct3D9.Direct3D object that I use like the old MDX Direct3D.Manager.In my application is a static variable that I've already instantiated.I hope this helps.   