Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Using DirectX9

Started by White Scorpion Dec 31, 2004 at 8:05 PM 5 replies 950+ views
Original Post
White Scorpion
White Scorpion
Hi everyone ! I wanted to start using DirectX with C#, but I've got a (major) problem. In the tutorial, they say to use the following code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
The problem is that my compiler doesn't recognize neither DirectX nor Direct3D. I downloaded the DirectX SDK while I was programming in C++ but now I am going toward C# so it must not be the problem... unless there is a DirectX SDK for C# too... which would be a real pain since I'm on 56kbps and these downloads are something like 50Mo+ ... is there something really stupid I didn't see yet ? I used the following code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace DirectX_Tutorial
{
     public class WinForm : System.Windows.Forms.Form
     {
         private Device device;
         private System.ComponentModel.Container components = null;

         public WinForm()
         {
              InitializeComponent();
         }

         protected override void Dispose (bool disposing)
         {
              if (disposing)
              {
                   if (components != null)
                   {
                        components.Dispose();
                   }
              }
              base.Dispose(disposing);
         }


         private void InitializeComponent()
         {
              this.components = new System.ComponentModel.Container();
              this.Size = new System.Drawing.Size(500,500);
              this.Text = "DirectX Tutorial";
         }

         static void Main() 
         {
              using (WinForm our_dx_form = new WinForm())
              {
                   Application.Run(our_dx_form);
              }
         }
     }
}

swarm
swarm
MS bundles the managed and unmanaged version of the SDK into 1 package. If you have indeed downloaded the latest SDK, just be sure you made references to the DX libraries in your C# projects.
White Scorpion
White Scorpion
How would I do that ? I referenced the libraries through Tools=>Options=>Projects in MSV... I even referenced a lot more folders than I should have but I thought it would fix my problem but it didn't. What exact folder would I have to link ?

[Edited by - White Scorpion on January 1, 2005 12:33:20 AM]
swarm
swarm
I'm using the C# Express but I know adding references in other IDE's are straightforward. There's no need to use the Tools menu. I do the following
1) Open a project
2) On the Solution Explorer, right click the "Reference" node, then click "Add Reference",
3) Find the DirectX assemblies under the .NET tab.
4) click OK

That would be all. You should see new nodes under the "Reference" besides the default System, System.Windows.Forms, System.Drawing

If you can't see any DX assemblies, then you don't have the managed version of DX. Be sure to download the latest SDK. It's big file though :(

thona
thona
::I even referenced a lot more folders than I should have

In C# you do not reference FOLDERS, but DLL's. Assemblies. Directly.

And you do not do yo through the fancy dialog you did, but through the references node IN the project. Just look at the project in the Solutions explorer. There is a node "references". THere you can add additional references.

And while you search, please at least have ONE look at the documentation. Helps to find your way around the IDE without making too stupid mistakes.
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
White Scorpion
White Scorpion
Thank you guys, it worked perfectly. Will I have to add them to every project or it will stay ?
swarm
swarm
you have to add them on every project

avoid using wizard or DX project templates if you're just starting to program directx, so this means you have to manually load the reference

enjoy!!!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.