title: Use C CLR::Class Library in C#
body: <p>I am trying to get some C++ code working under C#. I have been trying to follow tutorials online all over the place without any luck compiling or executing the code.</p>
  
  <p>I've written a basic C++ class that compiles to a .dll, and a C# console application.
  - I've changed the platform toolset to v100 on the C++ dll
  - I've added a reference to the dll in my C# application</p>
  
  <p>Note I am trying to use a C++ class, not C++ static functions... on to the code!</p>
  
  <pre><code>// CTrans.h
  #pragma once
  
  #include "windows.h"
  
  using namespace System;
  
  namespace CTrans {
  
      public ref class CTransClass
      {
      public:
      System::String^ helloWorld();
      };
  }
  
  // CTrans.cpp
  // This is the main DLL file.
  #include "stdafx.h"
  #include "CTrans.h"
  
  String^ CTrans::CTransClass::helloWorld()
  {
      return gcnew System::String("Hello World!");
  }
  
  // Program.cs
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace CTWrapper
  {
      class Program
      {
          static void Main(string[] args)
          {
              unsafe
              {
                  CTrans.CTransClass trans = new CTrans.CTransClass();
                  String tmp = trans.helloWorld();
              }
          }
      }
  }
  </code></pre>
  
  <p>Error: <a href="http://sumarlidason.com/Capture.PNG" rel="nofollow noreferrer">http://sumarlidason.com/Capture.PNG</a></p>
  
  <p>edit: removed niceties, add screenshot of error.</p>