在C#中調(diào)用WINCE連接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、創(chuàng)建調(diào)用函數(shù)
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、調(diào)用連接程序
private void menuItem9_Click(object sender, System.EventArgs e)
{
string progPath = "\WINDOWS\REPLLOG.EXE"; //在設(shè)備和桌面計(jì)算機(jī)之間建立ActiveSync 連接
//string progPath = @"Windowsobrread.exe";//這個(gè)程序我忘了是調(diào)用什么的,好像是CASIO IT500機(jī)上什么的:)
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");
}
pid控制相關(guān)文章:pid控制原理
評論