当前位置:编程学习 > wap >>

在VS2003里开发PPC2002程序:如何在在程序中打开另外一个已存在的应用程序!

在VS2003里开发PPC2002程序:如何在在程序中打开另外一个已存在的应用程序!

pc模式下可以用shell ,或者进程操作。。。但是ppc开发模块下。。这几个东西好像都不行。

    调用shell api 可以正常编译。但是在机子上就是不行。。打开来就是错误。说找不到。shell的动态链接库。。。
    倒。。哪里去找这个动态链接库。 --------------------编程问答-------------------- FindWindow --------------------编程问答-------------------- 不是这个意思。。。我是想调用一个外部程序。。 --------------------编程问答-------------------- CreateProcess()这个函数 --------------------编程问答-------------------- 同意楼上的.
--------------------编程问答-------------------- 一个完整的类:
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, "");
}

#region localAlloc MemoryAllocFlags

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
}

#endregion

#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
 }
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,