Few days ago we had a problem to initialize DirectX of our ultrasonic application AES.
The interesting thing was that the application war running well for years. Once day it just didn't want to run.
We try everything and finally we came to idea that there must be some other software causing DirectX to initialize properly.Zeljko has briefly described the problem here.
Because of that I decided to write a demo which shows what was wrong during initialization. The code bellow shows how to initialize the DirectX to be able to drow in the WindowsForm. The compiled code can be downloaded here.
using System; using System.Collections.Generic; using System.Text; using Microsoft.DirectX.Direct3D; using System.Windows.Forms; namespace DirectXTest { class Program { static void Main(string[] args) { DeviceType devType = DeviceType.Hardware; int adapter = 0; foreach(string arg in args) { if(arg=="deviceType=hardware") devType = DeviceType.Hardware; else if(arg=="deviceType=software") devType = DeviceType.Software; else if(arg=="deviceType=reference") devType = DeviceType.Reference; if (arg == "adapter=1") adapter = 1; if (arg == "adapter=2") adapter = 2; if (arg == "adapter=3") adapter = 3; } PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; Form frm = new Form(); Device device = new Device(adapter, devType, frm.Handle, CreateFlags.SoftwareVertexProcessing, presentParams); Console.WriteLine("Device has been initialized correctly. Press any key to exit..."); Console.ReadLine(); } } } |
Posted
May 26 2007, 05:42 PM
by
Damir Dobric