problem: not valid win32 app

G

Gigs_

im getting this tutorial:
http://einfall.blogspot.com/2005/02/using-directx-and-c-sharp-to-create.html

and i got some error, i dont know how to fix it.

Can someone help?

i use visual c# express 2008, latest runtime and latest directx


using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace VerticesTutorial
{
public class example : Form
{
Device device = null;
VertexBuffer vertexBuffer = null;

static void Main()
{
example form = new example(); //<= this is where i get error message
form.InitializeGraphics();
form.Show();
while (form.Created)
{
//Update our game, and render to screen
form.Render();
Application.DoEvents(); //Let the OS handle what it needs to
}
}

private void Render()
{
if (device == null)
return;
device.Clear(ClearFlags.Target, System.Drawing.Color.Blue, 1.0f, 0);

device.BeginScene();

device.SetStreamSource(0, vertexBuffer, 0);
device.VertexFormat = CustomVertex.TransformedColored.Format;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

device.EndScene();
device.Present();
}



public void InitializeGraphics()
{
try
{
// Now let's setup our D3D stuff
PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;

device = new Device(0,
DeviceType.Hardware,
this,
CreateFlags.HardwareVertexProcessing,
presentParams);

device.DeviceReset +=
new System.EventHandler(this.OnResetDevice);
this.OnResetDevice(device, null);
}
catch (DirectXException e)
{
MessageBox.Show(null, "Error intializing graphics: " +
e.Message, "Error");
Close();
}
}

public void OnResetDevice(object sender, EventArgs e)
{
Device dev = (Device)sender;
vertexBuffer
= new VertexBuffer(typeof(CustomVertex.TransformedColored),
3,
dev,
0,
CustomVertex.TransformedColored.Format,
Pool.Default);

GraphicsStream stm = vertexBuffer.Lock(0, 0, 0);
CustomVertex.TransformedColored[] verts =
new CustomVertex.TransformedColored[3];

verts[0].X = 150;
verts[0].Y = 50;
verts[0].Z = 0.5f;
verts[0].Rhw = 1;
verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
verts[1].X = 250;
verts[1].Y = 250;
verts[1].Z = 0.5f;
verts[1].Rhw = 1;
verts[1].Color = System.Drawing.Color.Brown.ToArgb();
verts[2].X = 50;
verts[2].Y = 250;
verts[2].Z = 0.5f;
verts[2].Rhw = 1;
verts[2].Color = System.Drawing.Color.LightPink.ToArgb();
stm.Write(verts);
vertexBuffer.Unlock();
}
}

}
 
B

Balaam

What error do you get, exactly? How did you configure the project this
code is being compiled in? What's the target type?

Pete

Are you referencing the DirectX libraries?
But really as Pete says, unless you tell us the error it's very hard
to suggest what your problem might be.
 
G

Gigs_

Balaam said:
Are you referencing the DirectX libraries?
But really as Pete says, unless you tell us the error it's very hard
to suggest what your problem might be.

Yes i reference directx.

I get

Unhandled Exception: System.BadImageFormatException: is not valid Win32
application. (Exception from HRESULT: 0x800700c1)
at VerticesTutorial.example.InitializeGraphics()
at VerticesTutorial.example.Main() in Aform.cs:line 18

im new to c# and visual studio so for project configure i dont know what you
mean. i just use empty project.
 
W

Willy Denoyette [MVP]

Gigs_ said:
Yes i reference directx.

I get

Unhandled Exception: System.BadImageFormatException: is not valid Win32
application. (Exception from HRESULT: 0x800700c1)
at VerticesTutorial.example.InitializeGraphics()
at VerticesTutorial.example.Main() in Aform.cs:line 18

im new to c# and visual studio so for project configure i dont know what
you mean. i just use empty project.


What OS are you running this on? When running on a 64-bit os, you'll have to
change the target platform "MSIL" into "X86" in your project properties.
DirectX can only be used from 32-bit applications, so it's better to set the
target platform to "X86" even when running on a 32-bit OS.

Willy.
 
G

Gigs_

Willy said:
What OS are you running this on? When running on a 64-bit os, you'll
have to change the target platform "MSIL" into "X86" in your project
properties. DirectX can only be used from 32-bit applications, so it's
better to set the target platform to "X86" even when running on a 32-bit
OS.

Willy.
x64 is os. can you tell me exactly where can i change MSIL? im new to visual studio?

thanks!
 
W

Willy Denoyette [MVP]

Gigs_ said:
x64 is os. can you tell me exactly where can i change MSIL? im new to
visual studio?

thanks!


Project menu -> project Properties -> Build tab - Platform target "Any CPU"
select "X86" from the dropdown, rebuild the project when done.

Willy.
 
G

Gigs_

Willy said:
Project menu -> project Properties -> Build tab - Platform target "Any
CPU" select "X86" from the dropdown, rebuild the project when done.

Willy.
thanks mate, its working now. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top