Hello. In my last question I asked about running a C# form in a C++ program. I got it working, but I am having problems. I will try to be brief.
My C++ program must execute a C# form and execute some simple functions in it (increasing counters and showing them). However I do not know the best way to do this. I have the form initialized in an init function:
C++
SUTAdapter::Form1^ *ptForm1; // Global variable
...
FormProject::Form1^ form1;
form1 = gcnew FormProject::Form1();
ptForm1 = &form1;
(*ptForm1)->Show();
(*ptForm1)->incCounter(0);
Some other functions in the C++ program just call incCounter. My problem is, that a second call from another function to incCounter makes my C# Form1 null (this == null), so I can use the function code of incCounter but not the class variables. It is strange, as if the program disposed the FormProject.
C#
public void incCounter(int counter)
{
int param1 = counter;
this.count[counter]++; // this == null in sucessive calls from c++ program
}
What am I doing wrong? I have actually disabled the form and just using the function and variables in case the problem is with the UI (invoke and so). Is exiting the C++ init function (the first chunk of code) clearing the Form1?