title: Delphi 2007 EXE and C++ DLL: Debug Output: Heap block at 027D4FF8 modified at 027D5009 past requested size of 9 Process
body: <p>I am trying to execute imported function in Delphi 2007:</p>
  
  <pre><code>function getOfficialCardNumber(): WideString ; cdecl; external 'idcapp.dll';
  </code></pre>
  
  <p>but after few second (in debug configuration) it stops here:</p>
  
  <pre><code>77BD37D6 C6055562C17700   mov byte ptr [$77c16255],$00
  </code></pre>
  
  <p>and says this:</p>
  
  <pre><code>Debug Output: Heap block at 027D4FF8 modified at 027D5009 past requested size of 9  Process PreglediZaDom.exe (23672)
  </code></pre>
  
  <p>Mentioned function was written in C++ (Visual Studio)</p>
  
  <p>I have tried changing WideString to PWideString and others, but no success. Does anyone know what can be a problem?</p>
  
  <p>In similar application, but written in VB6 they gave me this function to convert strings:</p>
  
  <pre><code>Public Function pisBstrToString(bstr) As String
  
      Dim bArray()    As Integer
  
      Dim longArray() As Long
  
      Dim str         As String
  
      Dim i           As Integer
  
      bArray = pisStringToBArray(bstr)
      longArray = pisBArrayToLongArray(bArray)
  
      str = ""
  
      For i = 1 To UBound(longArray)
  
          If longArray(i) &gt; 0 And longArray(i) &lt; 256 Then
              str = str &amp; Chr(longArray(i))
          Else
              str = str &amp; pisLongToUnichar(longArray(i))
          End If
  
      Next i
  
      pisBstrToString = str
  
  End Function
  </code></pre>
  
  <p>I know now that function written in C++ was exported like this:</p>
  
  <pre><code>BSTR _stdcall getOfficialCardNumber()
  </code></pre>