title: Export C function from a C++/CLI DLL that uses .NET code
body: <p>I have a C++/CLI DLL that uses some managed code (written in C#). I want to export a pure C function from the DLL - it will be called from unmanaged code using <code>LoadLibrary</code> and <code>GetProcAddress</code>.</p>
  
  <p>In the exported function I just need to create an instance and call one method of a C# class. So I tried this:</p>
  
  <pre><code>extern "C" __declspec( dllexport ) int __stdcall DoWork(
         const wchar_t* Param1,
         int Param2,
         void* Param3)
  {
      WorkerNamespace::ManagedClass1 worker;
      return worker.DoWork( gcnew String(Param1), Param2, IntPtr( Param3 ) );
  }
  </code></pre>
  
  <p>It compiles fine but when I do a <code>dumpbin CompiledDll.dll /exports</code> there are no exported functions.</p>
  
  <p>I tried adding <code>#pragma unmanaged</code> before the function declaration but then I get errors for using managed types inside the body.</p>
  
  <p>If I replace the body of the function with an empty stub (just <code>return 1;</code>) and with <code>#pragma unmanaged</code>, the function <strong>still</strong> doesn't show up in <code>dumpbin</code>. So what am I doing wrong? How do I export a C function from a C++/CLI Class Library project?</p>