星期二, 7月 04, 2006

Shutdown Windows in VC++ 2003 with CLR

Shutdown的API是 ExitWindowsEx( ),屬於user32.dll

.NET中要使用dll 要先用 dllimport

只有在msdn sample code中找到C#的example

然後在這一篇中提到Managed C++中使用 DLL 的方法:

所以修改一下,大概是..
加上
using namespace System::Runtime::InteropServices;
[DllImport("user32.dll", EntryPoint="ExitWindowsEx") ]
extern "C" bool ExitWindowsEx( int flg, int rea );
取代prototype 宣告。和
const int  EWX_LOGOFF    = 0x00000000;
const int EWX_SHUTDOWN = 0x00000001;
const int EWX_REBOOT = 0x00000002;
const int EWX_FORCE = 0x00000004;
const int EWX_POWEROFF = 0x00000008;
const int EWX_FORCEIFHUNG = 0x00000010;
作flash const宣告。

然後就可以在source code中使用
    ExitWindowsEx (EWX_POWEROFF | EWX_FORCE , 0x00030001 );
.!!在NT 以上系統不能這樣作,要先取得適當權限後才行。
好像還有3個 Win API要call ...目前只有找到C#的example..
http://www.chinaaspx.com/comm/dotnetbbs/Go.aspx?Forum_ID=6&id=73121&PPage=1&Action=next

沒有留言:

網誌存檔