calling xna from c++ (it works!)

// Hi,

// Linker option is /clr, entrypoint "main". Don't forget to add the required references. Heres the code :

// file "main.cpp"

usingnamespace Microsoft::Xna::Framework;

usingnamespace Microsoft::Xna::Framework::Content;

usingnamespace Microsoft::Xna::Framework::Graphics;

namespace SimpleGameLoop

{

refclass Game1 :public Microsoft::Xna::Framework::Game

{

public:

Game1()

{

hGraphics =gcnew GraphicsDeviceManager(this);

hContent =gcnew ContentManager(Services);

}

protected:

virtualvoid Initialize (void)override

{

Microsoft::Xna::Framework::Game::Initialize();

}

virtualvoid Update(GameTime ^hGameTime)override

{

Microsoft::Xna::Framework::Game::Update(hGameTime);

}

virtualvoid Draw(GameTime ^hGameTime)override

{

hGraphics->GraphicsDevice->Clear(Color::Black);

Microsoft::Xna::Framework::Game::Draw(hGameTime);

}

virtualvoid LoadGraphicsContent(bool loadAllContent)override

{

if(loadAllContent)

{

}

}

virtualvoid UnloadGraphicsContent(bool unloadAllContent)override

{

if(unloadAllContent)

{

hContent->Unload();

}

}

private:

GraphicsDeviceManager ^hGraphics;

ContentManager ^hContent;

};

void main(void)

{

Game1 ^hGame =gcnew Game1();

hGame->Run();

}

}

[4870 byte] By [Twilightzone] at [2007-12-27]
# 1
well for one thing ur string doesnt match the part about virtual void Initialie (void) override {, theres supposed to be a z in there
Icelandheater at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2

Thx, I corrected the function name. But still no luck, im not very deep into managed code at the moment, could it be something with the memory allocation in the garbage collection, or with the function declaration (missing sealed, etc.)?

To comment how this problem arose, although I like c# I like c++ even better cuz of the ability of goin to the bone (including the 3D max libraries, testing a bit of DirectX10, etc.), so I decided to give it a try but couldn't find any documentation on the Inet, and as a hobbiest its difficult to find bugs that you aren't notified by the compiler or linker ^^. But I guess if someone has the answer on it its on this forum.

Twilightzone at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3
What do you get on the screen when you run this app?

Have you tried setting a breakpoint in the debugger to see if your draw method is in fact being called?

ShawnHargreaves-MSFT at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4

Thx, it works finally (the function draw was not called)! I adjusted the the code in first post, so you can see how to call XNA from c++ now. So XNA is in fact not only c# (eventhough i start to think c# is better).

You can just copy paste the whole first post into a .cpp and see that it works (don't forget the references and the linker options)

Linker options: (minimal)

Entrypoint main [ /Entry:"main"]

for managed code [ /clr ],

can be [ /clr:pure ] if you only use managed code, but then you have to define

[ /subsystem:windows ] or [ /subsystem:console ]

if you specify [ /subsystem:windows ] the console window will no longer show up

References: (minimal)

Microsoft.Xna.Framework

Microsoft.Xna.Framework.Game

(optional) Microsoft.Xna.Framework.Content.Pipeline

(optional) all other references

Twilightzone at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...