Search code examples
c#windowswinformserror-handlingslimdx

troubles with running SlimDX C# application on Windows XP machine


I've made a simple C# WinForms app, which makes a screen-capture

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SlimDX.Direct3D9;
using SlimDX;

namespace KMPP
{
    public class DxScreenCapture
    {
        Device d;

        public DxScreenCapture()
        {
            PresentParameters present_params = new PresentParameters();
            present_params.Windowed = true;
            present_params.SwapEffect = SwapEffect.Discard;

            d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);
        }

        public Surface CaptureScreen()
        {
            Surface s = Surface.CreateOffscreenPlain(d, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, Format.A8R8G8B8, Pool.Scratch);
            d.GetFrontBufferData(0, s);
            return s;
        }
    }
}

now to call it:

using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SlimDX.Direct3D9;
using SlimDX;
using KMPP;
using System.Diagnostics;
using System.Threading;

namespace dxcapture
{
    public partial class Form1 : Form
    {
        DxScreenCapture sc = new DxScreenCapture();
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Stopwatch stopwatch = new Stopwatch();
            DateTime current = DateTime.Now;

            string n = string.Format(@"text-{0:yyyy-MM-dd_hh-mm-ss-tt}.bmp",DateTime.Now);

            string directory = (@"C:\temp\");
            string name = (".bmp");
            string filename = String.Format("{0:hh-mm-ss}{1}", DateTime.Now, name);
            string path = Path.Combine(directory, filename);


            stopwatch.Start();

            Thread.Sleep(1000);

            Surface s = sc.CaptureScreen();
            Surface.ToFile(s, path, ImageFileFormat.Bmp);
            stopwatch.Stop();
            s.Dispose();

            textBox1.Text = ("Elapsed:" + stopwatch.Elapsed.TotalMilliseconds);


        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

    }
}

Everything works fine when I run this app on Windows 7 x64 (it was compiled here)

Unfortunately, when I try to run this app on Windows XP x86 machine - I'm getting following error:

http://i.minus.com/ipilqHeWqbvKe.png

How I tried to fix it?

  • installed latest DX on WinXP

  • installed latest SlimDX on WinXP (btw this step solved my previous problem)

  • installed latest .Net Framework v.4 on WinXP

  • compiled this app as x86 and used SlimDX.dll x86 for the same reason

  • I also put slimdx.dll into the same folder where dxcapture.exe (app name) is located

What might be the problem? Does WinXP support Directx9 screen capture?

edit: I've tried to comment-out different code-lines and it seems like "device creation" is the problem.. I mean this line:

            d = new Device(new Direct3D(), 0, DeviceType.Hardware, IntPtr.Zero, CreateFlags.SoftwareVertexProcessing, present_params);

WinXP machine has integrated ATI graphics, so, I don't know.. maybe that's the problem, maybe not, but I can't check my program on some other pc.


Solution

  • As mentioned in the bug report you filed, the problem appears to be with your system, whether it be missing DirectX components or your graphics adapter not supporting Direct3D 9. If your card doesn't at least support D3D9, you won't be able to use SlimDX (or any of the other DirectX wrappers) for any kind of rendering.