由于在某些PDA上的WINCE操作系统不像PPC那样直接插上USB就可以连接上PC,必须手动选择菜单上的连接程序才可以连接,而在特殊情况下必须由用户控制连接,在此提供代码:
1、加入命名空间:
using System.Runtime.InteropServices;
using System.Reflection;
2、声明API和类
[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 );
public class ProcessInfo
{
public IntPtr hProcess;
public IntPtr hThread;
public Int32 ProcessId;
public Int32 ThreadId;
}
3、创建调用函数
public static bool CreateProcess( String ExeName, String CmdLine, ProcessInfo pi )
{
//Int32 INFINITE;
//unchecked {INFINITE = (int)0xFFFFFFFF;}
if ( pi == null )
pi = new ProcessInfo();
byte [] si = new byte[128];
CreateProcess(ExeName, CmdLine, IntPtr.Zero, IntPtr.Zero,
0, 0, IntPtr.Zero, IntPtr.Zero, si, pi);
//WaitForSingleObject(pi.hProcess,INFINITE);
return true;
}
4、调用连接程序
private void menuItem9_Click(object sender, System.EventArgs e)
{
string progPath = "
\\WINDOWS\\REPLLOG.EXE"; //
在设备和桌面计算机之间建立ActiveSync 连接
//string progPath = @"\Windows\obrread.exe";//这个程序我忘了是调用什么的,好像是CASIO IT500机上什么的:)
ProcessInfo pi=new ProcessInfo();
CreateProcess(progPath, "", pi);
// if ( CreateProcess(progPath, "", pi) )
// MessageBox.Show("Success! PID = " + pi.ProcessId.ToString());
// else
// MessageBox.Show("Failed! System Error = " + GetLastError().ToString());
// MessageBox.Show("Done Waiting");
}