title: Including C-DLL from C++
body: <p>This feels like a noob question, so if it's a dupe, please point me to the right location :)</p>
  
  <p>I tried including a DLL written in C into a C++ program. It didn't work; gcc said</p>
  
  <blockquote>
    <p>test.cpp: xxx: error: too many arguments to function. </p>
  </blockquote>
  
  <p>Here's a minimal working example: </p>
  
  <p>Wrapper for DLL functions: </p>
  
  <pre><code>/* myWrapper.h */
  
  #ifndef _MYWRAPPER_H
  #define _MYWRAPPER_H
  #include &lt;windows.h&gt;
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  extern  FARPROC   EXPORTED_functionNameP;
  
  int GetDLLpointers();
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif
  </code></pre>
  
  <p>Implementation thereof: </p>
  
  <pre><code>/* myWrapper.c */
  #include &lt;windows.h&gt;
  #include "myHeader.h"
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  HINSTANCE drvsHANDLE;
  
  extern  FARPROC   EXPORTED_functionNameP;
  
  int GetDLLpointers()
  {
      static int result;
  
      drvsHANDLE = LoadLibrary("myLibrary.dll");
      if (drvsHANDLE == NULL) return (result=0);
  
      EXPORTED_functionNameP = GetProcAddress(
          drvsHANDLE, "originalFunctionName");    
      if (EXPORTED_functionNameP == NULL) return (result = 0);
  
      return (result = 1);
  }
  
  #ifdef __cplusplus
  }
  #endif
  </code></pre>
  
  <p>Naturally, I haven't written these nor the library myself, and preferably, they should all stay untouched. I <em>did</em> however add the <code>extern "C"</code> lines.</p>
  
  <p>Then, my main file: </p>
  
  <pre><code>// my Main
  #include &lt;windows.h&gt;
  #include "myHeader.h"
  
  int main(int argc, char **argv)
  {
      int arg = 1;
      EXPORTED_functionNameP(arg);
  
      return 0;
  }
  </code></pre>
  
  <p>Build commands: </p>
  
  <pre><code>gcc -I. -c -o myHeader.o myHeader.c -L. -lmyLibrary
  g++ -I. -o main.exe myMain.cpp myHeader.o -L. -lmyLibrary
  </code></pre>
  
  <p>It works fine if I rewrite my <code>main.cpp</code> into valid C and compile with <code>gcc</code> instead of <code>g++</code>. </p>
  
  <p>I tried changing <code>extern "C"</code> into <code>extern "C++"</code> to no avail, I tried all permutations or <code>gcc</code> and <code>g++</code> for the two build commands, nothing. </p>
  
  <p>I know it's something to do with name mangling, but I thought <code>gcc</code> would take care of that when you include the <code>extern "C"</code> lines...Can someone please explain what I'm missing here? </p>
  
  <p>In case it matters -- </p>
  
  <p>Windows XP Pro (will be Win7 later on) </p>
  
  <p>(MinGW) gcc 4.6.2 </p>