Managed, Unmanaged code C++

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Managed, Unmanaged code C++

Post by grimdoomer »

Im playing around with C++, and I've use unmanaged code to learn some basics. But I wanted to make a app to loads tags in a halo map. So I created a CLR Forms project. And the class below keeps giving me errors, can not declare managed System::IO::BinaryReader in unmanaged class Map.

Code: Select all

#include "stdafx.h"

#pragma managed
namespace Test
{
	using namespace System;
    using namespace System::IO;
	using namespace Test;

	class Map
	{
	public:
		FileStream^ fs;
		BinaryReader^ br;
		BinaryWriter^ bw;

		Map(char* Location);
	};
}
Can someone please help?
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
User avatar
LuxuriousMeat





Posts: 824
Joined: Thu Nov 03, 2005 6:43 pm
Location: zzzzzzzzzzzzzzzz
Contact:

Re: Managed, Unmanaged code C++

Post by LuxuriousMeat »

Your trying to use managed code in unmanaged code, thats a no no.
Image
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post by grimdoomer »

But all I did was create a class, whats to say its managed or not?
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
User avatar
xzodia




Translator Connoisseur Coagulator

Posts: 1981
Joined: Sun May 15, 2005 10:31 am
Location: UK
Contact:

Post by xzodia »

Well from the sounds of things you made an unmanaged project..therefore any class made in that project will be unmanaged...
Image
Halo 2 Plugins | Lock-on To Just About Anything | My Sites | Snow Hog
Old Plugins you have, upgrade you must...
Always Maintain a High Quality-To-Crap Ratio.
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post by grimdoomer »

But .NET is managed, isn't it?
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
RapiD





Posts: 2
Joined: Fri Aug 29, 2008 1:21 pm

Post by RapiD »

In visual c++ you have a choice to create a managed class or an unmanaged class. The differences between managed code and unmanaged code are that unmanaged code is compiled directly to native machine code (otherwise known as native code), while managed code is compiled to a secondary language which is then compiled and ran on run-time.
In C# or Visual Basic, you don't have a choice; Your code is always compiled into the standard IL language. In Visual c++ you have a choice. In fact you can even do this per-class simply by defining your classes with "__gc ". An example would be my class known as "Player_Class":
Unmanaged

Code: Select all

class player_class
{
private:
int x, y, z;
}
Managed

Code: Select all

__gc class player_class
{
private:
int x, y, z;
}
which in actual terms mean "Garbage Collected". That is how you define managed code from unmanaged code. Please keep in mind that your project must then compile under CLR instead of into native machine code.

You can technically used managed code together with unmanaged code, however that gets complicated. I will not get into details about that (although i'm sure a simple google search will provide you with more than enough information concerning that)
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post by grimdoomer »

When I add __gc befor the class, I get an error saying I need to add /clr:oldsyntax to the command line options. When I do I get like 20 errors all over the place.
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
RapiD





Posts: 2
Joined: Fri Aug 29, 2008 1:21 pm

Post by RapiD »

well send me a few of those errors and i can try to help there. This is why if you're going to have a major change in your project, make it at a very early stage because converting the project itself is a pain in the ass.
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post by grimdoomer »

Well it is a CLR rpoject, and is being compiled under /clr. So basically I can'y any new classes to a clr project without rewriting half the form code?
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
User avatar
kornman00




ONI New Age

Posts: 146
Joined: Fri Dec 12, 2003 6:30 pm
Contact:

Post by kornman00 »

grimdoomer wrote:Well it is a CLR rpoject, and is being compiled under /clr. So basically I can'y any new classes to a clr project without rewriting half the form code?
The code example he gave you was of MC++ which was in VS03, 05 and onward us C++\CLR (however you can tell it to use the old syntax like it was trying to hint to you) which is a different syntax (a far better syntax that the crap they gave us in MC++). Like they said, you declared a regular unmanaged C++ class and tried to use managed references, which is why it's giving you crap. I'd suggest you actually learn the C++ language then transition into learning C++\CLR before trying to actually code anything as you don't seem to understand what you're doing at all, and it won't help trying to just blindly slice and dice things together.
User avatar
grimdoomer




System Engineer

Posts: 1440
Joined: Mon Oct 09, 2006 4:36 pm

Post by grimdoomer »

Well, I can't learn anything unless I try it myself. And I would rather learn under .NET something I'm familiar with, then using random classes not having any idea what todo.
Image
AI Zones in MP | Ambiance | Gravemind Beta v1.1
Aumaan Anubis wrote:Grimdoomer. The first person ever to mod Halo 2 Vista.
Post Reply