idos


Hi,

I am trying to make chatting program like msn, at first the whole sending message thing was done in unmanaged C++, but then my supervisor ask me to add GUI with C++.Net which is managed.

I spent some time google-ing to find how to comunicate between the two, as the unmanaged component needs to call method in the managed and vice -versa. Fortunately I finally found out that I can do it with gcroot<T>.

However I keep getting the same error:
Error 1 error C2065: 'Form1' : undeclared identifier e:\code\gui3\gui3\server\MyUnManaged.h 105


My code look like as follows:

// in the managed

#include "MyUnManaged.h"
namespace GUI {
public ref class Form1 : public Form{
MyUnManaged * unmanaged;
public:
Form1()
{
unmanaged = new MyUnManaged();
}
private:
void methodThatWillCalledSomeUnmanagedMethod();
public:
void methodToBeCalledByUnmanaged();
}
}

// in the unmanaged
#include "Form1.h"
class MyUnManaged {
gcroot<Form1^> gui;
};

Is this problem because of the gcroot<T> Do I implement it the right way
OR is it a problem of circular dependencies if it is a circular dependencies, I actually have tried to do forward declaration, but the error remains.

Can some one help me please .....



Re: Managed to unmanaged OR circular dependencies

Baris ERGUN


Hello I strongly recomend you to encapsulate your old C++ project into a ATL COM component and use it from a C#.NET Windows Form GUI with INterop. The most challenging part would be building the ATL Project with Visual C++ 6.0 . The INterop is a piece of Cake. Since C# syntax is the best coding language according to me for .NET Programing dont try to understand Visual C++.NET I would say instead try to understand C#.NET. Once you spend some time on doing so you will have much more facility in your life. I can help you if you need some help






Re: Managed to unmanaged OR circular dependencies

idos

Thank you for replying my question, but the problem is that my supervisor require me to use C++.Net and winsock2.h which I believe is unmanaged...

Thank you though






Re: Managed to unmanaged OR circular dependencies

Mike Danes

This kind of problem (circular dependencies between headers) can be avoided by not including one of the headers, for example do not include Form1.h in the unmanaged header.

Of course the compiler will complain that it does not know what Form1 is so you need to declare it:

// unmanaged header

ref class Form1;

class MyUnManaged {
gcroot<Form1^> gui;
};

In the cpp file for MyUnManaged class you still need to include the Form1.h file because otherwise the compiler does not know what methods Form1 contains.





Re: Managed to unmanaged OR circular dependencies

idos

Thank you, it works