Compile result for native C++ code mixed with managed code for .Net import -


i developing c++ wrapper c# project. little bit confused how end result compiled. have situation:

a solution 1 projects. project common language runtime support (/clr). native cpp files configured without common language runtime support (/clr) , no precompiled headers.

so questions are:

  1. why obligated have use no precompiled headers native cpp files?
  2. what end result, native code compiled machine code? or jit because use wrapper .net?

native header:

    #pragma once      #include <string>     using namespace std;      class person     {     private:      string _name;      public:       person(string name);       ~person();        string getname();     }; 

native cpp:

    #include "stdafx.h"     #include "person.h"       person::person(string name)     {         _name = name;     }       person::~person()     {     }      string person::getname()     {        return _name;     } 

c++ wrapper header

#pragma once  #include <msclr\marshal_cppstd.h>  #pragma unmanaged #include "person.h"   using namespace system; using namespace msclr::interop;  namespace wrapperlib{  public ref class personmanaged { private:     person *_person; public:     personmanaged(string ^name){         _person= new person(marshal_as<std::string>(name));     }     ~personmanaged()     {         delete _person;         _person = 0;     }      string ^getname(){         return gcnew string(_person->getname().c_str());     } }; } 

edit:

thank answer luaan! helped! dowloaded ilspy , opened mixed assembly. found native person class in there.

using system; using system.runtime.compilerservices; using system.runtime.interopservices; [nativecppclass, unsafevaluetype] [structlayout(layoutkind.sequential, size = 24)] internal struct person { } 

now like? there .net usings system system.runtime, there attribut nativecppclass?

you can have precompiled headers - problem managed precompiled headers not compatible native precompiled headers. msdn:

precompiled headers supported under /clr. however, if compile of cpp files /clr (compiling rest native) changes required because precompiled headers generated /clr not compatible generated without /clr. incompatibility due fact /clr generates , requires metadata. modules compiled /clr can therefore not use precompiled headers don't include metadata, , non /clr modules can't use precompiled header files contain meta data.

the article describes how around forcing 2 different precompiled headers, 1 or .net , 1 native. makes sense large projects, though.

as second question, depends. end result either native dll, or mixed managed/native assembly - in case, i'd bet on latter. i've used c++/cli .net wrappers of native types, though, might wrong. it's easy check, though - compile, , try using ilspy on resulting dll - if works, it's .net assembly, if doesn't, it's native dll.

if indeed case, yes, native code machine code, while managed parts il usual. see mixed assemblies further reference.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -