Start an extern application

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

Hello,

I'm trying, via my code in C#, to start an extern application. I've
tried to following code without success :

public struct ProcessInfo
{
public IntPtr hProcess;
public IntPtr hThread;
public Int32 ProcessId;
public Int32 ThreadId;
}

[DllImport("CoreDll.DLL", SetLastError=true)]

private extern static int CreateProcess(String imageName, String
cmdLine,
IntPtr lpProcessAttributes, IntPtr lpThreadAttributes, Int32
boolInheritHandles,
Int32 dwCreationFlags, IntPtr lpEnvironment, IntPtr lpszCurrentDir,
byte [] si, ProcessInfo pi );

ProcessInfo pi = new ProcessInfo();
byte [] si = new byte[128];

int process = CreateProcess("", @"\Windows\TheApplication.exe",
IntPtr.Zero,
IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, si, pi);

I end up with a NotSupportedException.
Thanks for all the hints you could give me...
 
ProcessInfo is data that's returned from CreateProcess. Given that, your
declaration is wrong. The pi item should be 'ref'. Further, the si
parameter is really a pointer and it should be set to NULL, so change your
declaration to take an IntPtr and pass IntPtr.Zero.

You can look at OpenNETCF and see how we declared CreateProcess().

Paul T.
 
Back
Top