T
Thorsten
HI
I'm a C# developer and unfortunately I have to write now some code in
managed and unmanaged C++. In this area I'm Newbie and therefore please
forgive me if this is a really simple question.
1) I have two classes defined in two header files, it is possible to have a
member from the other class? My problem is that as soon as I include the
other header file I get linking errors. See example below.
2) It is possible to call from unmanaged code a managed instance of a class?
I can use GCHandle class to extract a fixed pointer to the managed class but
how do I cast this pointer in my unmanaged class to a "managed" class
instance? Or it is better to use the template gcroot<ManagedClass*>?
Thanks for any help!
Cheers
Thorsten
Example Code:
-> Managed.h
class CUnmanaged;
#pragma once
#include "Unmanaged.h"
namespace Test
{
public __gc class CManaged
{
private:
CUnmanaged* m_Unmanaged;
public:
CManaged();
void DoSomeThing();
};
}
-> Unmanaged.h
class Test::CManaged;
#pragma once
#include "Managed.h"
#include <vcclr.h>
__nogc class CUnmanaged
{
public:
gcroot<Test::CManaged*> m_Managed;
void DoSomeThing();
CUnmanaged();
};
Some errors are like this:
Unmanaged.h error C2653: 'Test' : is not a class or namespace name
Unmanaged.h error C2079: 'CManaged' uses undefined class 'Test'
Unmanaged.h(12): error C2059: syntax error :
I'm a C# developer and unfortunately I have to write now some code in
managed and unmanaged C++. In this area I'm Newbie and therefore please
forgive me if this is a really simple question.
1) I have two classes defined in two header files, it is possible to have a
member from the other class? My problem is that as soon as I include the
other header file I get linking errors. See example below.
2) It is possible to call from unmanaged code a managed instance of a class?
I can use GCHandle class to extract a fixed pointer to the managed class but
how do I cast this pointer in my unmanaged class to a "managed" class
instance? Or it is better to use the template gcroot<ManagedClass*>?
Thanks for any help!
Cheers
Thorsten
Example Code:
-> Managed.h
class CUnmanaged;
#pragma once
#include "Unmanaged.h"
namespace Test
{
public __gc class CManaged
{
private:
CUnmanaged* m_Unmanaged;
public:
CManaged();
void DoSomeThing();
};
}
-> Unmanaged.h
class Test::CManaged;
#pragma once
#include "Managed.h"
#include <vcclr.h>
__nogc class CUnmanaged
{
public:
gcroot<Test::CManaged*> m_Managed;
void DoSomeThing();
CUnmanaged();
};
Some errors are like this:
Unmanaged.h error C2653: 'Test' : is not a class or namespace name
Unmanaged.h error C2079: 'CManaged' uses undefined class 'Test'
Unmanaged.h(12): error C2059: syntax error :