c++ - Callback unmanaged code from managed C# -


Bit of a history lesson here I am working on a legacy C ++ / MFC application and am trying to start an incremental modernization by pushing components written in C # (WinForms and later WPF).

I have Net / 1.1 and VS / 2003 for many reasons which are impossible to solve in the near future.

Currently, as a proof of concept, it works like something:

  #pragma push_macro ("new") #undef New WinFormA :: Form1 * Myform; Myform = __gc new WinFormA :: Form1 (); Myform-> ShowDialog (); #pragma pop_macro ("new")  

The problem I am having is - I need unmanaged C ++ / MFC code to pass the callback pointer in the Managed C # Winform code So that I can capture user interaction and process them through the application.

I have seen some articles, but it does not work in VS / 2003 (the compiler does not like representative syntax).

Is there any other option? I do not think I can use DLLImport because I do not need to interact with specific application examples, not flat APIs.

Thank you!

If other answers do not work, you can always write a roller roller to level the classes Are there. For example, if there is a C ++ class:

  class TheClass {public: The class (int paragraph); ~ TheClass (); Some functions (int paragraph 1, int paragraph 2); };  

I will write a cover:

  extern "C" zero * TheClass_Create (int param) {return (zero *) new TheClass (Ultimate); } Extern "C" Zero TheClass_Destroy (Zero * This) {Delete (TheClass *) This; } Extern "C" bool TheClass_SomeFunction (zero * this, int paragraph 1, int paragraph 2) {return ((TheClass *) this) - & gt; Some Functions (Param 1, Para 2); }  

Because the cover is straight, you can p / c to your heart's content in C # ( zero * this to ensure compatibility Should be an IntPtr you take up to 64-bit) Sometimes, if I am really ambitious, then I will actually write a C # cover around the P, to 're-classify'.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -