title: Exporting functions from a DLL with dllexport
body: <p>I'd like a simple example of exporting a function from a C++ Windows DLL.</p>
  
  <p>I'd like to see the header, the <code>.cpp</code> file, and the <code>.def</code> file (if absolutely required).</p>
  
  <p>I'd like the exported name to be <strong><em>undecorated</em></strong>. I'd like to use the most standard calling convention (<code>__stdcall</code>?). I'd like the use <code>__declspec(dllexport)</code> and not have to use a <code>.def</code> file.</p>
  
  <p>For example:</p>
  
  <pre><code>  //header
    extern "C"
    {
     __declspec(dllexport) int __stdcall foo(long bar);
    }
  
    //cpp
    int __stdcall foo(long bar)
    {
      return 0;
    }
  </code></pre>
  
  <p>I'm trying to avoid the linker added underscores and/or numbers (byte counts?) to the name. </p>
  
  <p>I'm OK with not supporting <code>dllimport</code> and <code>dllexport</code> using the same header. I don't want any information about exporting C++ class methods, just c-style global functions.</p>
  
  <p><strong><em>UPDATE</em></strong></p>
  
  <p>Not including the calling convention (and using <code>extern "C"</code>) gives me the export names as I like, but what does that mean? Is whatever default calling convention I'm getting what pinvoke (.NET), declare (vb6), and <code>GetProcAddress</code> would expect? (I guess for <code>GetProcAddress</code> it would depend on the function pointer the caller created).</p>
  
  <p>I want this DLL to be used without a header file, so I don't really need the a lot of the fancy <code>#defines</code> to make the header usable by a caller.</p>
  
  <p>I'm OK with an answer being that I have to use a <code>*.def</code> file.</p>