net Compact Framework中用一個程式調用另一個程式

來源:互聯網
上載者:User

在.net Compact Framework中用一個程式調用另一個程式!其中用到三個API 這三個API的原型可以在 .NET Compact Framework SDK 協助中查到! 希望對大家有用

代碼如下

 

 

using System.Runtime.InteropServices;

using System.Text;

 

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;

// 以下的成員目前沒用,可選

public IntPtr lpIDList;

public IntPtr lpClass;

public IntPtr hkeyClass;

public UInt32 dwHotKey;

public IntPtr hIcon;

public IntPtr hProcess;

}

 

[DllImport("coredll")]

extern static int ShellExecuteEx(ref  SHELLEXECUTEEX ex ); //注意,原函數要的是指標!所以必為ref

 

[DllImport("coredll")]

extern static IntPtr LocalAlloc( int flags, int size );

 

[DllImport("coredll")]

extern static void LocalFree( IntPtr ptr );

 

// 如何使用的代碼在這裡!

 

string docname = @"/windows/default.htm";

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 = 0;

see.lpFile = pData;

 

ShellExecuteEx(ref see);

 

LocalFree(pData);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.