title: Calling DLLs with pointers in Delphi
body: <p>I am new to Delphi. I have a DLL with the following exported function in it:  </p>
  
  <pre><code>bool __stdcall MyFunction(char * name, int * index)  
  </code></pre>
  
  <p>This code which calls this DLL function in C++ works perfectly:  </p>
  
  <pre><code>typedef void (WINAPI * MyFunction_t)(char *, int *);
  void main()
  {
      HMODULE mydll = LoadLibrary(L"C:\\mydll.dll");
      MyFunction_t MyFunction = (MyFunction_t)GetProcAddress(mydll, "MyFunction");
  
      int index = 0;
  
      MyFunction("MyString", &amp;index); 
  }
  </code></pre>
  
  <p>I need to do the same in Delphi. Here is my code, which is not working (MyFunction gets called but the index variable doesn't receive the appropriate value). This is a code excerpt so please ignore disorder. Any input would be much appreciated!</p>
  
  <pre><code>type
    TMyFunction= function(name: PChar; var index_ptr: Integer): Boolean; stdcall;
  
  var
    fMyFunction : TMyFunction;
    i : Integer;
    h: THandle;
  
  begin
    Result := 0;
    h := LoadLibrary('c:\\mydll.dll');
    fMyFunction := GetProcAddress(h, 'MyFunction');
    if @fMyFunction &lt;&gt; nil then
    begin
      fMyFunction('MyString', i);
      Result := i;
    end;
    FreeLibrary(h);
  end;
  </code></pre>