title: Argument of function is being corrupted when function is exported in C++ when using extern "C" __declspec(dllexport)
body: <p>I came across a code as follows:</p>
  
  <pre><code>#define FUNCTION_EXPORT extern "C" __declspec(dllexport)
  typedef int32 (*U_Function)(HINSTANCE, const std::string &amp;);
  const char *P_FUNCTION = "processFunc";
  </code></pre>
  
  <p>Now this is being used in another part of same file:</p>
  
  <pre><code>int32 run(HINSTANCE instance, const std::string &amp;cmdLine) {
  try {
        LibraryManager lib(PROC_LIBRARY);
        FARPROC ptr = GetProcAddress(lib.getLibHandle(), U_FUNCTION);
        if (ptr) {
           result = reinterpret_cast&lt;U_Function&gt;(ptr)(instance, cmdLine);
        }
         .....
         .....
         so on
  }
  </code></pre>
  
  <p>Now this is being used in another file .cpp of same project as following the reinterpret_cast step during debugging in visual studio in release mode:</p>
  
  <pre><code>FUNCTION_EXPORT int processFunc(HINSTANCE instance, const string &amp;cmdLine) {
  ......
  ......
  }
  </code></pre>
  
  <p>Here the cmdLine argument is being corrupted when function export is being used.
  The cmdLine is given by user. For example if the user gives cmdLine as "None Stay" (the cmdLine was watched during debugging; as the first four bytes being randomly filled like 'su\0 and then the given argument "None Stay" follows in cmdLine) thus having only value 'su during runtime causing the application to fail.(it is being randomly generated, each time a different value following by None Stay like "¨‘\x16\x1NONE STAY etc.)</p>
  
  <p>Note: The ptr and ProcessFunc have same value in run time watch.</p>
  
  <p>How do we make that the user entered cmdLine argument is being successfully used during runtime and prevent the application from failing?</p>