c++ cli - Passing a native pointer function to a C# method -


I have a C ++ project that uses a non-administrative class method to display the string in the user interface Done:

  zero MyProject :: displayIHM (std :: string mystring);  

This project has been compiled with CLR because it makes another call made from C # / .NET 4.0. The aim of the .NET project is to do heavy calculation tasks. During computation, we want to return some information to the user interface.

My idea was to create two new methods in the C ++ - Clei project:

  zero MyProject :: displayFromDotNet (string ^ migrating) {displayIHM (ToStdString (mystring) ); } String ToStdString (string ^ s) {const char * chars = (const char *) (Marshall :: StringToHZylobal NSCI). ToPointer (); String os = character; Marshall :: FreeHGlobal (IntPtr ((* Zero *) character); Return os; }  

So far, everything is fine, but now the hard part: how to display. My idea was to provide function pointer in the .NET class constructor and then launch this process:

  void (MyProject :: * pointeurFunc) (string ^) = & amp; MyProject:: displayFromDotNet; Computation Project ^ Colonel = GCNE Computation Project ((--- punterFunk);) Kernel- & gt; Compute ();  

The second line does not work The computational project's constructor has an IntPtr parameter but I do not know that I can change the function pointer to an IntPtr ^ in C ++. I have also made some attempts to use Marshall :: GetDelegateForFunctionPointer but could not compile it.

I do not know what to do, any help would be appreciated!

Edit: Yes, the computation project is Marie C #. Error with line 2 "parameter 1 can not be changed from 'overloaded function type' to 'System :: intit'.

I finally got an ugly way.

My main problem was I could not pass a method pointer to C # because it is not a real function indicator (hence I can not put it in IntPtr). I have a static MyProject object and static object in a second class Decided to create a steady way of calling displayIHM at: StaticMyProject {public: static MyProject staticObject; Fixed zero DisplayInIHM (four *);};

In CPP:

  MyPrice Static MyProject :: Ozetstatic; Zero StaticMyProject :: DisplayInIHM (four * messages) {std :: string message2 (message); staticObject.displayIHM (message2 );}  

To call the Compute method of the computation project, I have modified the code like this:

  StaticMyProject :: objetStatique = * Y ; Zero (* FunkConverter) (Four *) = Static MyProject :: Display these IHMs; Computing Project ^ kernel = GCNE Computation Project (IntPtr) Funk Pointer); Kernel- & gt; Compute ();  

and in my computing projects:

  public class computation project {[unmanagedFunctionPointer (calling convention. CDEcl)] Public Representative Zero Function Pointer ([Marshall AS Unmanaged type. LPStr)] string message); Public readonly function pointer display system; Public Computation Project (INTERPTR PTR) {this.DisplayMethod = (Function Pointer) Marshall.Get DelegateForFactory Pointer (PTR, TypePoint (Function Pointer)); } Public Intu Compute () {this.DisplayMethod ("Starting Count ..."); ...}}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -