Use C# managed app class in C++ unmanaged app -
i have project class written in c# use serialize data.
[xmltype("cpersoane")] public class cpersoana { public cpersoana() { } [xmlelement("name")] public string name { get; set; } [xmlelement("profession")] public string profession{ get; set; } [xmlattribute("age")] public int age{ get; set; } //... }
i have project in same solution written c++ mfc (no clr support) dialog box 3 text boxes.
how can access "cpersoana" class c++ can use "name", "profession" , "age" text boxes?
any appreciated!
firstly, c# project needs dll (output type = class library).
secondly, cannot access c# code in unmanaged c++, c++ project needs @ least 1 source file compiled /clr
can access c# class.
in source file, can write code like
#using "mycsharpproject.dll" using namespace mycsharpnamespace; ... gcroot<cpersoana^> ppersona = gcnew cpersoana(); cstring sfilename = <path file>; ppersona->loadfromfile(gcnew system::string(sfilename)); // loadfromfile member function in cpersoana class // bool loadfromfile(string sfilename) cstring sname(ppersona->name->tostring(); ...
Comments
Post a Comment