c# PDA中安装CmpactFramwork2.0(立即给分)

ludeli2004 2009-02-02 10:59:20
我写了一个ppc程序,用来给PDA安装CmpactFramwork2.0,代码如下:
public class ShellExecute
{
public static void Start(string fileName, string parameters)
{
int nSize;
SHELLEXECUTEEX see;
IntPtr pFile;
IntPtr pParams;

see = new SHELLEXECUTEEX();

nSize = fileName.Length * 2 + 2;
pFile = localAlloc(MemoryAllocFlags.LPtr, nSize);
Marshal.Copy(Encoding.Unicode.GetBytes(fileName), 0, pFile, nSize - 2);

nSize = parameters.Length * 2 + 2;
pParams = localAlloc(MemoryAllocFlags.LPtr, nSize);
Marshal.Copy(Encoding.Unicode.GetBytes(parameters), 0, pParams, nSize - 2);

see.lpFile = pFile;
see.lpParameters = pParams;

ShellExecuteEx(see);

LocalFree(pFile);
LocalFree(pParams);
//return see.hProcess;
}

public static void Start(string fileName)
{
Start(fileName, "");
}

private static IntPtr localAlloc(MemoryAllocFlags uFlags, int uBytes)
{
const int GMEM_FIXED = 0x0000;
const int LMEM_ZEROINIT = 0x0040;
const int LPTR = (GMEM_FIXED | LMEM_ZEROINIT);

IntPtr ptr = LocalAlloc(LPTR, (uint)uBytes);
if (ptr == IntPtr.Zero)
throw new Exception("Out of memory!");
return ptr;
}

private enum MemoryAllocFlags : int
{
Fixed = 0x00,
ZeroInit = 0x40,
LPtr = ZeroInit | Fixed
}

#region APIs
[DllImport("coredll.dll")]
private static extern IntPtr LocalAlloc(uint uFlags, uint Bytes);

[DllImport("coredll")]
private static extern IntPtr LocalFree(IntPtr hMem);

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

private class SHELLEXECUTEEX
{
public UInt32 cbSize = 60;
public UInt32 fMask = 0;
public IntPtr hwnd = IntPtr.Zero;
public IntPtr lpVerb = IntPtr.Zero;
public IntPtr lpFile = IntPtr.Zero;
public IntPtr lpParameters = IntPtr.Zero;
public IntPtr lpDirectory = IntPtr.Zero;
public int nShow = 0;
public IntPtr hInstApp = IntPtr.Zero;
public IntPtr lpIDList = IntPtr.Zero;
public IntPtr lpClass = IntPtr.Zero;
public IntPtr hkeyClass = IntPtr.Zero;
public UInt32 dwHotKey = 0;
public IntPtr hIcon = IntPtr.Zero;
public IntPtr hProcess = IntPtr.Zero;
}
#endregion

[DllImport("coredll.Dll")]
private static extern int CreateProcess(string strImageName, string strCmdLine, IntPtr pProcessAttributes, IntPtr pThreadAttributes, int bInheritsHandle, int dwCreationFlags, IntPtr pEnvironment, IntPtr pCurrentDir, Byte[] bArray, ProcessInfo oProc);

public static void LaunchCAB(string cabPath)
{
ProcessInfo pi = new ProcessInfo();
CreateProcess("wceload.exe", cabPath, IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, new Byte[128], pi);
}
}


我在主程序里调用ShellExecute.Start(“\SD Card\Ossur\System_SR_ENU.CAB”);但是无法安装成功,当我手动在PDA中点击这个cab文件去安装的时候,是没有问题的,可以安装成功,我不知道是哪里出问题了,请大家帮忙。(分不够还可以加)
...全文
122 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ludeli2004 2009-02-02
  • 打赏
  • 举报
回复
这个问题就是如何实现WCE5进程的启动,大家没有会的吗?

111,130

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧