title: Calling delphi procedure from C++
body: <p>I have a DLL written in Delphi that I need to call from a C++ code. The signature of the procedure in Delphi is:</p>
  <pre><code>procedure GetDeviceName(     No: integer;
                             Name: PChar;
                              Len: integer;
                        var Error: integer); stdcall;
  </code></pre>
  <p>From the code from the DLL I believed that I could call it with this block of code:</p>
  <pre><code>typedef void (__stdcall *GetDeviceNamePtr)(int, char*, int, int*);
  
  GetDeviceNamePtr GetDeviceName = (GetDeviceNamePtr) GetProcAddress(m, &quot;GetDeviceName&quot;);
  
  char DeviceName[256];
  int Error;
  GetDeviceName(1, DeviceName, 256, &amp;Error);
  
  </code></pre>
  <p>However, I've got an access violation. Should the last parameter of the procedure signature be a pointer to an integer or an integer ? I'm confused about the &quot;var&quot; keyword in the declaration of the procedure. I've checked the exported symbols of DLL and the procedure considered is properly exported. What's wrong in my procedure ?</p>
  <p>Some more info regarding the environment:</p>
  <ol>
  <li>It's a dll compiled with delphi 6.</li>
  <li>ANSI only.</li>
  <li>I'm debugging on the C++ side and the exception is right on the call to the function.</li>
  <li>Nothing is returned from the function calling the DLL API.</li>
  </ol>