c# - Difference CLR and CLI and how to call those from pure C -


could tell me difference between clr , cli in it's basic functionallity important 1 of them better?


all got far using iclrruntimehost interface not allow me return else int , allowed parameter lpcwstr (see executeindefaultappdomain)

at point wondering if 1 could/would allocate memory e.g. struct in c program, give pointer lpcwstr string executeindefaultappdomain , translates pointer struct on other side work on struct. don't how 1 can work limitation of signator each function: int fncname(string param);


i took @ this tutorial don't how calling c++/cli c program works , how return complex objects or more complex int.


and please show me how can use cli within c? can't seem find lines of code show how work.


you can pass , return complex data in cli. cli intermediate layer. when pass data managed code(.net) native code (c,c++) need intermediate layer take responsibility of managed native object , vice verse conversation because managed objects managed garbage collector , native objects managed programmer (need delete when created).

in c++/cli there 2 type of class. 1) manged class 2) native class. managed class defined :

public ref class managedclass { nativeobject* native; managedobject^ mobject; } 

this can contain managed , native object. in class create managed/native class object replica of native/managed object (in terms of containing data , method). basic data in object either object or basic primitive data can converted. have take care of objects only.

suppose want execute c++ method form .net. c++ code has object called nativeclass , c++ method return native object. can't pass object directly .net layer. store object instance in variable native of above class managedclass. note can access native managed object in cli layer. create manged object class in cli exact replica of native class in term of containing data. copy date native object managed object , assign managed object instance variable mobject. can pass variable mobject .net layer because manged object.

similar approach can used when pass managed object native method.

you can go through pdf know more c++/cli.

http://asawicki.info/download/productions/publications/cpp_cli_tutorial.pdf


update:

i recommend first go through pdf. below simple example how conversion happens. nativeobject c++ object (you can have c struct instaed of class) , managedobject c# object , cliinterface used provide interface.

public ref class cliinterface { private:     nativeobject* native;     managedobject^ mobject; public:     cliinterface(nativeobject* nativeobj){         native = nativeobj;         mobject = gcnew managedobject(nativeobj);     }     string getnativemessage();     int getnaiveid();     string^ getmanagedmessage();     int getmanagedid(); } 

native class:(c++ object or c struct , can used in cli)

public class nativeobject { private:     int id;     string msg; public:     string getmessage(){return msg;}     int getid(){return id;} } 

managed class: (c# object , can use in cli)

public ref class managedobject { private:     nativeobject* native; public:     managedobject(nativeobject* obj){         native = obj;     }     string^ getmessage(){         convertnativetocli(native->getmessage()); //you can use marshaling implement convertnativetocli method.      }     int getid(){         return native->getid();     } } 

you can use managed class object , cliinterface c# code , can use native object in c++ code. hope help. can go microsoft's c++/cli documentation.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -