PC Review


Reply
Thread Tools Rate Thread

Displaying text on a form form a umanaged callback C++/C# problem

 
 
bob
Guest
Posts: n/a
 
      26th Jun 2005
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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid Error Message while utilising umanaged DLL Sugan Microsoft VB .NET 2 13th Dec 2006 02:58 PM
umanaged code - array error Patrick Sullivan Microsoft VB .NET 4 9th May 2006 02:19 PM
Dynamic Invoke from Umanaged Dll in CompactFramework (WinCE 5, C#, VS 2003) Marco [Stinger] Microsoft Dot NET Compact Framework 4 31st Mar 2005 01:34 PM
creating an umanaged object in a managed wrapper JRoe Microsoft C# .NET 2 9th Feb 2005 12:43 AM
Re: Trouble creating Managed Proxy for umanaged C++ in VS.Net 2003 4Space Microsoft VC .NET 0 8th Jul 2003 12:17 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:18 AM.