Code snippets‎ > ‎C++‎ > ‎

Using managed code from C++

To use managed code from C++ you have several options. The option described here is to use CLR (Common Language Runtime). This allows you to directly access the managed code from C++.

First, create a project with CLR enabled (Properties -> General -> Common Language Runtime Support -> /clr). Next you can use both managed and unmanaged code in your project.

To import functions from a managed dll you use the #using directive (instead of #include):

#using <ManagedLib.dll>

After that you can access the functions defined in the DLL:
int main(int argc, char* argv[])
{
  ManagedLib::ManagedClass managedClass;
  managedClass.PrintHelloWorld();

  //std::cout<<"Hello world"<<std::endl;
return 0;
}

ċ
clr_application.zip
(6k)
Nico Kruithof,
May 26, 2015, 3:13 AM
Comments