title: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Acess c++ dll
body: <p>I converted .cpp file into .dll file and use this .dll file in my vb.net project. Acess c++ dll in my vb.net projevct, I got this error, " Attempted to read or write protected memory. This is often an indication that other memory is corrupt." Can get any help here ?
  Here is my vb.net code:</p>
  
  <pre><code>Public NotInheritable Class myTestDLL
      &lt;DllImport("encryption.dll", EntryPoint:="conv16to64", CallingConvention:=CallingConvention.Cdecl)&gt;
      Public Shared Sub conv16to64(ByVal c As String, ByRef s As String)
      End Sub
  End Class
  </code></pre>
  
  <p>Here is my c++ function code:</p>
  
  <pre><code> extern "C"{
  _declspec(dllexport) void conv16to64(char s[], char b[])
  {
      int i,j;
      char t[65],c[65];
  
      for (i=0; i&lt;=16; i++)
          c[i] = s[i];
  
      for (i=1; i&lt;=64; i++)
          t[i] = 0;
  
      for (i=0; i&lt;=15; i++)
      {
          if (i == 0)
              j = 0;
          else if (i == 1)
              j = 4;
          else if (i == 2)
              j = 8;
          else if (i == 3)
              j = 12;
          else if (i == 4)
              j = 16;
          else if (i == 5)
              j = 20;
          else if (i == 6)
              j = 24;
          else if (i == 7)
              j = 28;
          else if (i == 8)
              j = 32;
          else if (i == 9)
              j = 36;
          else if (i == 10)
              j = 40;
          else if (i == 11)
              j = 44;
          else if (i == 12)
              j = 48;
          else if (i == 13)
              j = 52;
          else if (i == 14)
              j = 56;
          else if (i == 15)
              j = 60;
  
          switch (c[i]) {
          case '0': t[j+1] = 0; t[j+2] = 0;
              t[j+3] = 0; t[j+4] = 0;
              break;
          case '1': t[j+1] = 0; t[j+2] = 0;
              t[j+3] = 0; t[j+4] = 1;
              break;
          case '2': t[j+1] = 0; t[j+2] = 0;
              t[j+3] = 1; t[j+4] = 0;
              break;
          case '3': t[j+1] = 0; t[j+2] = 0;
              t[j+3] = 1; t[j+4] = 1;
              break;
          case '4': t[j+1] = 0; t[j+2] = 1;
              t[j+3] = 0; t[j+4] = 0;
              break;
          case '5': t[j+1] = 0; t[j+2] = 1;
              t[j+3] = 0; t[j+4] = 1;
              break;
          case '6': t[j+1] = 0; t[j+2] = 1;
              t[j+3] = 1; t[j+4] = 0;
              break;
          case '7': t[j+1] = 0; t[j+2] = 1;
              t[j+3] = 1; t[j+4] = 1;
              break;
          case '8': t[j+1] = 1; t[j+2] = 0;
              t[j+3] = 0; t[j+4] = 0;
              break;
          case '9': t[j+1] = 1; t[j+2] = 0;
              t[j+3] = 0; t[j+4] = 1;
              break;
          case 'A': t[j+1] = 1; t[j+2] = 0;
              t[j+3] = 1; t[j+4] = 0;
              break;
          case 'B': t[j+1] = 1; t[j+2] = 0;
              t[j+3] = 1; t[j+4] = 1;
              break;
          case 'C': t[j+1] = 1; t[j+2] = 1;
              t[j+3] = 0; t[j+4] = 0;
              break;
          case 'D': t[j+1] = 1; t[j+2] = 1;
              t[j+3] = 0; t[j+4] = 1;
              break;
          case 'E': t[j+1] = 1; t[j+2] = 1;
              t[j+3] = 1; t[j+4] = 0;
              break;
          case 'F': t[j+1] = 1; t[j+2] = 1;
              t[j+3] = 1; t[j+4] = 1;
              break;
          }
      }
      for (i=1; i&lt;=64; i++)
          b[i] = t[i];
  }
  </code></pre>