Hi all
Currently porting an application to managed C++
Have managed to create working MDI form and child windows etc.
Also added a callback from an unmanaged 'C' dll (ok that was strangely
easy to do and it works).
The callback simply creates a string form the callback char * data
__delegate void Callback_PositionCallback(char *UpdateText);
and the function address passed to the unmanaged dll event function.
void STDCALL UpdatedTextCallback(char *UpdateText)
{ //
function is called when an event happens in the unmanaged dll
String *strText = new String(UpdateText);
midiForm-> updateTextBox(strText); // <====== problem how to
get a pointer to MidiForm class
}
Within the Midi form class (kindly generated by VS 7), has a function
UpdateTextBox added manually
public __gc class MidiForm : public System::Windows::Forms::Form
{
public:
......
void updateTextBox(String *usetext)
{
TextBox->Text = usetext; // textbox is a simple textbox
placed on the eMidiForm status bar
}
}
The updateTextBox works great if called from any class that can have a
pointer to the MidiForm class
For example
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPTSTR
lpCmdLine,int nCmdShow)|
{
System::Threading::Thread::CurrentThread->ApartmentState =
System::Threading::ApartmentState::STA;
MidiForm *midiForm = new MidiForm;
midiForm->updateTextBox("hello");
Application::Run(midiForm);
return 0;
}
But the compiler will not allow a global variable to allow the
UpdatedTextCallback to be called from Callback function.
i.e MidiForm *midiForm cannot be global.
So how do you get a pointer to call the main Form (and any functions in it).
Help!
Thanks
Bob
|