title: call delphi dll from visual c++
body: <p>I have DLL file which compiles in Delphi, functions export as __stdcall, and functions description txt file. I havn't got any source code.</p>
  
  <p>And I'll use this DLL in visual studio c++ project. Google says that need use <code>LoadLibrary + GetProcAddress</code> , but GetProcAddress returns NULL if  exported function declared as __stdcall, i.e. I can't call function with its name. And others recomended using .def file, 
  but I don't know what .def file, and what need for generating .def file, if I can use this way on my situation, please describe thoroughly.</p>
  
  <p><strong>QA: How I can call these exported functions?</strong></p>
  
  <p>Here I post my main.cpp file,  dll name and function name changed specially.</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;tchar.h&gt;
  #include &lt;cassert&gt;
  #include &lt;cstdio&gt;
  
  
  int main()
  {
      //foo(80, 127);
      HMODULE hLib;
      hLib = LoadLibrary( _T("MyDLL.dll") );
  
      assert(hLib != NULL ); // pass !!
  
  
      int ( __stdcall *pFoo)(int, int);
      (FARPROC &amp;)pFoo = GetProcAddress(hLib, _T("foo") );
  
      if (pFoo== NULL )
      {
          DWORD errc = GetLastError();
          printf("%u\n",errc); // it gets error 127
  
      }else{
          printf("success load\n");
      }
  //  pFoo(04,1);
  
      FreeLibrary(hLib);
      return 0 ;
  }
  </code></pre>