tags:

views:

376

answers:

3

Hello, I'm sorry if this question has already been answered but I couldn't find it.

I am trying to open a C# form when a function in a C++ program is called (the main program is in C++, the form is in C#, it is an empty form just to try how it works). I am using Visual Studio 2005 and I have both projects in my solution. The C# project is just a form and I have configured it as a class library. However, when I go to the C++ program's function I type this in the beginning:

int _stdcall Init(void)
{
...
FormProject::Form1 form1;
form1 = new FormProject::Form1::Form1();
form1.something();
...
}

I have little experience in C++, I have tried different combinations but I am unlucky. The C++ project has been made compatible with CLI. I have already included the needed:

#using <System.Windows.Forms.dll>
#using <System.dll>

I am aware there are some big mistakes but I only need this form running, no more. Thank you very much.

Edit: I have already added the references.

+3  A: 

The C++/CLI project will need to add a reference to the C# project before you can use types in your C# library.

Judah Himango
A: 

Have you added a reference to the FormProject to your C++ project? If you've done that, have you included a #using statement for the FormProject namespace?

Harper Shelby
+3  A: 

If I understand you, I think you need to instantiate the C# object using C++/CLI's syntax enhancements. For example, the code you posted should be:

FormProject::Form1^ form1;
form1 = gcnew FormProject::Form1::Form1();  // or FormProject::Form1()
form1->something();

I suggest you create a new WinForms project in managed C++, and just look at the generated code for the correct syntax.

Jeremy
Yes, references are already added. I guess those two are my problems, the #using plus the CLI syntax...
Hiperi0n
Noticed I had a syntax error on the third line, fixed. :)
Jeremy