title: C++ Loading a DLL
body: <p>I'm about to develop a API that should be distributed with a DLL. Because I can't test my code written in the DLL directly, I have to load the DLL within a Test-Project and run it there.</p>
  
  <p>I'm using Visual Studios 2015. There I made a Testproject and within that, I made my Project for the DLL:</p>
  
  <p>Solution-Tree "TestProject"</p>
  
  <ul>
  <li><p>DLLProject</p></li>
  <li><p>TestProject</p></li>
  </ul>
  
  <p>I export a dummy function to test if I am able to load the DLL:</p>
  
  <pre><code>#ifndef EXPORT
  #define EXPORT __declspec(dllexport)
  #endif
  
  extern "C" {
      EXPORT int dummy() {
          return 5;
      }
  }
  </code></pre>
  
  <p>Then, in my Testproject, I try to load the DLL, extract the function and run it:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  typedef int (__stdcall *dll_func)();
  
  int main() {
      HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("H:\\path\\to\\project\\Debug\\DLLProject\\DLLProject.dll"));
  
      if (hGetProcIDDLL == NULL) {
          cout &lt;&lt; "DLL could not be loaded. " &lt;&lt; GetLastError() &lt;&lt; endl;
          return;
      }
  
      dll_func f = (dll_func)GetProcAddress(hGetProcIDDLL, "create");
  
      if (f == NULL) {
          cout &lt;&lt; "Factory function could not be resolved. " &lt;&lt; GetLastError() &lt;&lt; endl;
          return;
      }
  
      cout &lt;&lt; "Factory function returns: " &lt;&lt; f() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>I copied almost everything from <a href="https://stackoverflow.com/questions/8696653/dynamically-load-a-function-from-a-dll">this question</a>.
  Unfortunately, when I run my Testproject, my console prints out: "DLL could not be loaded. 4250"</p>
  
  <p>At this point I really don't know what to do because the Error as described <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms681387(v=vs.85).aspx" rel="nofollow noreferrer">here</a> basicly says nothing. With a bit of research, I couldn't get any answers... hope you can help me :D</p>