Ed Andersen

Software Developer and Architect in Japan

XNA2.0 Dependency checking

Ed Andersen Avatar

by

in , ,

After a lot of trial and error using Process Monitor and Virtual PC, I have finally sussed out exactly what XNA2.0 games on Windows need to run. The requirements are slightly different to XNA 1 games.

Direct X runtimes

There are four files that need to be installed in the system32 folder for XNA to initialise properly. They are:

  • xinput1_3.dll
  • x3daudio1_3.dll
  • d3dx9_31.dll, and
  • xactengine2_9.dll

The first three can be placed alongside the application exe and then load fine, but xactengine2_9.dll does not load this way for some reason, and has to be present in the system directory. Distributing these files alongside the application breaks the DirectX EULA, so they have to be installed using dxsetup.exe.

To check the presence in your XNA game, just put this code in Program.cs before game.Run() is called:

bool HasAllPrereqs = true;
// check all the required files, if any missing, return false
if (!System.IO.File.Exists(System.Environment.SystemDirectory 
    + "\\xactengine2_9.dll")) HasAllPrereqs = false;
if (!System.IO.File.Exists(System.Environment.SystemDirectory 
    + "\\d3dx9_31.dll")) HasAllPrereqs = false;
if (!System.IO.File.Exists(System.Environment.SystemDirectory 
    + "\\x3daudio1_2.dll")) HasAllPrereqs = false;
if (!System.IO.File.Exists(System.Environment.SystemDirectory 
    + "\\xinput1_3.dll")) HasAllPrereqs = false;

If HasAllPrereqs is false after those lines, exit the application before it crashes horribly when XNA tries to initialise.

Visual C++ 2005 SP1 runtimes

Even a fresh Vista install doesn’t have these. They are provided when updating Visual Studio 2005 to SP1, or installing SP1 of the .Net Framework 2.0. However, Vista comes with SP0 of .Net 2.0, meaning 99% of machines you come across will be lacking what XNA 2.0 needs. There is a 2.5MB standalone installer on the MS download site here which installs what you need even on .Net 2.0 SP0 machines. .Net 3.5 installs Net 2.0 SP1.

So if any of the following are installed, we safely have the right Visual C++ 2005 runtimes:

  • .NET Framework 2.0 SP1
  • .NET Framework 3.5
  • Visual C++ 2005 SP1 Redistributable

By looking up the product codes in the registry, we can also check at runtime if we have the runtimes (again, before game.Run()):

[DllImport("msi.dll")]
public static extern Int32 MsiQueryProductState(string szProduct);

…goes before the main application entry point, and

bool vccOK = false;
// check for VC++ 2005 SP1 redist (very rare in the wild)
if (MsiQueryProductState(
"{7299052b-02a4-4627-81f2-1818da5d550d}") == 5) vccOK = true;
// check for .NET Framework 2.0 SP1
if (MsiQueryProductState(
"{2FC099BD-AC9B-33EB-809C-D332E1B27C40}") == 5) vccOK = true;
// check for .NET Framework 3.5 (includes 2.0 SP1)
if (MsiQueryProductState(
"{B508B3F1-A24A-32C0-B310-85786919EF28}") == 5) vccOK = true;

If vccOK is still false, exit the application before you call game.Run().

Ed Andersen Avatar

About me

Hi! 👋 I’m a Software Developer, Architect and Consultant living in Japan, building web and cloud apps. Here I write about software development and other things I find interesting. Read more about my background.

Ed’s “Newsletter”

Get the latest blog posts via email ✌️


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *