how i can start an external exe application

  • Thread starter Thread starter Lonifasiko
  • Start date Start date
L

Lonifasiko

Not completely sure, but I think this can be done using
System.Diagnostics.Process.Start.

I suppose it's the same as in the full framework.

Hope it helps.
 
hi guys,

i want to start an external exe application.
do anybody knows how i can do it? i am using c# with cf.

with best regards,
elmar
 
You can use ShellExecuteEx in core.dll to launch a program or CAB on device.

Here is an example in C# of launching a CAB (so that it will self -install).


///////////////////
string docname = GetCurrentDirectory() + @"\download.cab";
int nSize = docname.Length * 2 + 2;
IntPtr pData = LocalAlloc(0x40, nSize);
Marshal.Copy(Encoding.Unicode.GetBytes(docname), 0, pData, nSize - 2);
SHELLEXECUTEEX see = new SHELLEXECUTEEX();
see.cbSize = 60;
see.dwHotKey = 0;
see.fMask = 0;
see.hIcon = IntPtr.Zero;
see.hInstApp = IntPtr.Zero;
see.hProcess = IntPtr.Zero;;
see.lpClass = IntPtr.Zero;
see.lpDirectory = IntPtr.Zero;
see.lpIDList = IntPtr.Zero;
see.lpParameters = IntPtr.Zero;
see.lpVerb = IntPtr.Zero;
see.nShow = 1;
see.lpFile = pData;
ShellExecuteEx(see);
LocalFree(pData);
///////////////

and here is a SHELLEXECUTEEX class that wraps the p/invoke calls for you:

class SHELLEXECUTEEX
{
public UInt32 cbSize;
public UInt32 fMask;
public IntPtr hwnd;
public IntPtr lpVerb;
public IntPtr lpFile;
public IntPtr lpParameters;
public IntPtr lpDirectory;
public int nShow;
public IntPtr hInstApp;

// Optional members
public IntPtr lpIDList;
public IntPtr lpClass;
public IntPtr hkeyClass;
public UInt32 dwHotKey;
public IntPtr hIcon;
public IntPtr hProcess;
}

[DllImport("coredll")]
extern static int ShellExecuteEx( SHELLEXECUTEEX ex );

[DllImport("coredll")]
extern static IntPtr LocalAlloc( int flags, int size );

[DllImport("coredll")]
extern static void LocalFree( IntPtr ptr );

[DllImport("coredll")]
public static extern IntPtr GetCapture();

[DllImport("coredll")]
public static extern IntPtr MoveWindow(IntPtr hWnd, int X, int Y, int
Width, int Height, bool Repaint);

[DllImport("coredll")]
public static extern int GetWindowLong(IntPtr hWnd, int nItem);

[DllImport("coredll")]
public static extern void SetWindowLong(IntPtr hWnd, int nItem, int
nValue);

public const int GWL_STYLE = (-16);
public const int GWL_EXSTYLE = (-20);
public const int GWL_USERDATA = (-21);
public const int GWL_ID = (-12);

public const int WS_BORDER = 0x00800000;
public const int WS_CAPTION = 0x00C00000;

}

--
Darren Shaffer
..NET Compact Framework MVP
Principal Architect
Connected Innovation
www.connectedinnovation.com
 
I find that in OpenNETCF, the method Process.start can invoke an application. But there is bug in its Kill() method. Is there any other way to terminate a process?
 
Back
Top