title: PonyLang Windows CreateProcess FFI
body: <p>I've been trying to call Window's <code>CreateProcessA</code> from Pony Language's FFI.</p>
  
  <p>I created both a C and a PonyLang example. The C example works great:</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;tchar.h&gt;
  
  void wmain(void) {
      STARTUPINFO info={0};
      PROCESS_INFORMATION processInfo={0};
  
      CreateProcessA("calc.exe", 0, 0, 0, 0, 0, 0, 0, &amp;info, &amp;processInfo);
  
      if (status == 0)
          printf("%d",GetLastError()); // never hits
  
  }
  </code></pre>
  
  <p>I put <code>calc.exe</code> in the current directory. This works flawlessly on Windows.
  However, my PonyLang implementation keeps on returning a non zero <code>GetLastError</code>:</p>
  
  <pre><code>use "lib:kernel32"
  
  primitive _ProcessAttributes
  primitive _ThreadAttributes
  primitive _Inherit
  primitive _Creation
  primitive _Environment
  primitive _CurrentDir
  primitive _StartupInfo
  primitive _ProcessInfo
  
  primitive _HandleIn
  primitive _HandleOut
  primitive _HandleErr
  
  primitive _Thread
  primitive _Process
  
  struct StartupInfo 
      var cb:I32 = 0
      var lpReserved:Pointer[U8] tag= "".cstring()
      var lpDesktop:Pointer[U8] tag= "".cstring()
      var lpTitle:Pointer[U8] tag= "".cstring()
      var dwX:I32 = 0
      var dwY:I32 = 0
      var dwXSize:I32=0
      var dwYSize:I32=0
      var dwXCountChars:I32=0
      var dwYCountChars:I32=0
      var dwFillAttribute:I32=0
      var dwFlags:I32=0
      var wShowWindow:I16=0
      var cbReserved2:I16=0
      var lpReserved2:Pointer[U8] tag="".cstring()
      var hStdInput:Pointer[_HandleIn] = Pointer[_HandleIn]
      var hStdOutput:Pointer[_HandleOut]= Pointer[_HandleOut]
      var hStdError:Pointer[_HandleErr]= Pointer[_HandleErr]
  
  struct ProcessInfo
      var hProcess:Pointer[_Process] = Pointer[_Process]
      var hThread:Pointer[_Thread] = Pointer[_Thread]
      var dwProcessId:I32 = 0
      var dwThreadId:I32 = 0
  
  
  //var si:StartupInfo = StartupInfo
  
  actor Main
    new create(env: Env) =&gt;
      var si: StartupInfo = StartupInfo
      var pi: ProcessInfo = ProcessInfo
      var inherit:I8 = 0
      var creation:I32 = 0
      var one:I32 = 0
      var two:I32 = 0
      var three:I32 = 0
      var four:I32 = 0
      var z:I32 = 0
  
      var p = @CreateProcessA[I8]("calc.exe",
      z,
      one,
      two,
      inherit,
      creation,
      three,
      four,
      addressof si,
      addressof pi)
  
      if p == 0 then
          var err = @GetLastError[I32]() // hits this every time.
          env.out.print("Last Error: " + err.string())
      end
  </code></pre>
  
  <p>So the above code compiles for PonyLang, but <code>GetLastError</code> most of the time returns 2. Sometimes <code>GetLastError</code> returns 123. Other times it returns 998?
  It all seems odd that the error code is different sometimes. Those codes all mean that there is some issue with file access? </p>
  
  <p><code>Calc.exe</code> is in the current directory (same directory as the c example).</p>
  
  <p>Also not only is the Error code different but calc.exe is executed(runs fine) in the C version but not in the PonyLang version.  This leads me to believe something is off with my PonyLang ffi setup.</p>
  
  <p>Does anyone know what may be wrong?  </p>