title: Access violation when calling external function (C++) from Delphi application
body: <p>I've an external DLL written in C++. The piece below declares a <em>struct</em> type and a function, which, being given a pointer, fills a variable of this type:</p>
  
  <pre><code>enum LimitType { NoLimit, PotLimit, FixedLimit };
  
  struct SScraperState
  {
      char        title[512];
      unsigned int    card_common[5];
      unsigned int    card_player[10][2];
      unsigned int    card_player_for_display[2];
      bool        dealer[10];
      bool        sitting_out[10];
      CString     seated[10];
      CString     active[10];
      CString     name[10];
      double      balance[10];
      bool        name_good_scrape[10];
      bool        balance_good_scrape[10];
      double      bet[10];
      double      pot[10];
      CString     button_state[10];
      CString     i86X_button_state[10];
      CString     i86_button_state;
      CString     button_label[10];
      double      sblind;
      double      bblind;
      double      bbet;
      double      ante;
      LimitType   limit;
      double      handnumber;
      bool        istournament;
  };
  
  extern "C" {
      SCRAPER_API int ScraperScrape(HWND hwnd, SScraperState *state);
  }
  </code></pre>
  
  <p>I declare a similar type in my <strong>Delphi</strong> application and call the above function:</p>
  
  <pre><code>interface
  
  type
    LimitType = (NoLimit, PotLimit, FixedLimit);
  
    SScraperState = record
      title: Array [0..511] of Char;
      card_common: Array [0..4] of Word;
      card_player: Array [0..9, 0..1] of Word;
      card_player_for_display: Array [0..1] of Word;
      dealer: Array [0..9] of Boolean;
      sitting_out: Array [0..9] of Boolean;
      seated: Array [0..9] of String;
      active: Array [0..9] of String;
      name: Array [0..9] of String;
      balance: Array [0..9] of Double;
      name_good_scrape: Array [0..9] of Boolean;
      balance_good_scrape: Array [0..9] of Boolean;
      bet: Array [0..9] of Double;
      pot: Array [0..9] of Double;
      button_state: Array [0..9] of String;
      i86X_button_state: Array [0..9] of String;
      i86_button_state: String;
      button_label: Array [0..9] of String;
      sblind: Double;
      bblind: Double;
      bbet: Double;
      ante: Double;
      limit: LimitType;
      handnumber: Double;
      istournament: Boolean;
    end;
  
    pSScraperState = ^SScraperState;
  
  function ScraperScrape(hWnd: HWND; State: pSScraperState): Integer; cdecl; external 'Scraper.dll';
  
  implementation
  
  var
    CurState: SScraperState;
    pCurState: pSScraperState;
  
    if ScraperScrape(hWnd, pCurState) = 0 then
    ...
  </code></pre>
  
  <p>When the function is called I get Debugger Exception Notification:</p>
  
  <p><em>Project ... raised exception class EAccessViolation with message 'Access violation at address 10103F68 in module 'Scraper.dll'. Read of address FFFFFFFC'. Process stopped.</em></p>
  
  <p>Other functions exported from the same DLL work fine, so my guess is I made a mistake in the type declaration. Any tips will be highly appreciated, as I'm dead stuck at this point.</p>