I have a C++ application (calling functions of an SDK for a specific hardware component), and want to display its data in a C# GUI. The C# part is a DLL which the C++ calls. (This is by request from the customer so I don't have much choice about it.)
I'm not very well versed in C#, so might be missing something obvious, but I'm running into problems both displaying the GUI and updating it.
I access the C# code using this method, with code roughly like this (ptr
is a class variable):
// Initialize COM.
CoInitialize(NULL);
ptr = new IPtr(__uuidof(ManagedClass));
(*ptr)->ShowForm();
then in another thread:
if (updating) (*ptr)->Update(data)
On the C# side we have:
FormClass myForm;
void ShowForm()
{
myForm = new FormClass();
Application.Run(myForm);
}
void Update(Data data)
{
myForm.Update(data)
}
When I use Application.Run or ShowDialog to show my GUI, the form shows nicely but the update makes the application crash. Using Show has the GUI get stuck. Using BeginInvoke resulted in the GUI never appearing.
Is there any recommended way for me to start the GUI given this setup? Would it help to somehow use Invoke/BackgroundWorker in Update rather than calling myForm's method directly?