[.net] Interfacing c# with unmanaged c++

Started by
10 comments, last by Amnesty 19 years, 1 month ago
Quote:Original post by paulecoyote
It might be easier just to have a common file format for the "editor" and the "engine". That way you don't need to interface the two, you just share the files.

Though I guess if your editor needs to use your engine directly, that approach won't work for you.

I need it so I can render things.

@evolutional: Thanks, I was using GCC but I should be able to switch to that with no problem.
______________________________________________________________________________________With the flesh of a cow.
Advertisement
Thanks again. I got strings working to & from C#

Alas i have one more question.
It's a little hard to explain so bare with me.


The API i would like to wrap has a topography like this

Replay (the main class)
--Has instance of a Time class
--Has instance of a Action class
--Has instance of a Header
----Has instance of a Player class

or in C++ code something like this

class replay
{
...
replay_time m_time;
replay_actions m_actions;
header m_header;
};

I'd like to very much to mimic this topography for my managed proxy class so i created a managed proxys classes for those aswell that my managed (main class) Replay will have instances of (pheww say that ten times fast).

So it would look something like this

__gc class Header{public:	Header (replay* arg) : m_replay(arg) {}	~Header () {}	String* get_creator_name()		{ String __pin *str = new String(m_replay->m_Header.get_creator_name());	return str;	}private:// this is a pointer to the main class in the native API// its initialized in the ctor// through this pointer it pretends to be the native header class// by just delagating all of replay.header functions   replay* m_replay;};


Get it? The Header class takes a replay pointer and just delegates as if it were the native API right?

Ideally in C# code i could then use the API like, how its done in C++
Native.Replay rep = new Native.Replay();rep.open("somestring");rep.get_header().get_creation_date();



Anyway doing this compiles fine. But when it try and use it in C#, it crashes.

However if i ignore the proxy and write a function inside the the managed Replay class to access that function without trying to use the proxy it works.

i.e
rep.get_creation_date();


Id rather not do this though. As that one class will have like 100 or so functions if i didn't split it up! And that would just be unwielding.



Any help would be extreamly appreciated

Thanks
"I turned into a driveway I thought was mine and crashed into a tree I don't have."- a real insurance claim

This topic is closed to new replies.

Advertisement