我的系统为WIN XP+SP2,我用下面的API为何出错,说找不到DLL的入口?

dazhu2 2004-11-13 03:04:53

[DllImport("user32.dll", EntryPoint="ExitWindows")]
public static extern int ExitWindows (
int dwReserved,
int uReturnCode
);


private void button1_Click(object sender, System.EventArgs e)
{
ExitWindows(0,0);
}
...全文
109 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
BearRui 2004-11-13
  • 打赏
  • 举报
回复
[DllImport("user32.dll")]
private static extern int ExitWindows (int dwReserved, int uReturnCode);
AhBian 2004-11-13
  • 打赏
  • 举报
回复
我从未用过这个 API,
关机可能与权限有关。
AhBian 2004-11-13
  • 打赏
  • 举报
回复
uFlags

4 = Force any applications to quit instead of prompting the user to close them.

0 = Log off the network.

8 = Shut down the system and, if possible, turn the computer off.

2 = Perform a full reboot of the system.

1 = Shut down computer.

dwReason

This is the System Shutdown Reason Code. If your application will run in an enterprise environment, set this to the appropriate value found in MSDN or talk to your/customer's IT department - they may have custom codes defined. If you don't care about this just set this = 0



Sample Code:
class Class1
{
[DllImport("user32.dll")]
static extern bool ExitWindowsEx(uint uFlags, uint dwReason);


[STAThread]
static void Main(string[] args)
{
ExitWindowsEx(0, 0); //this will cause the computer to logoff.
ExitWindowsEx(1, 0); //And this will shutdown your computer.
}
}



dazhu2 2004-11-13
  • 打赏
  • 举报
回复
up
dazhu2 2004-11-13
  • 打赏
  • 举报
回复
我用任何参数都是注销!
dazhu2 2004-11-13
  • 打赏
  • 举报
回复
to AhBian(阿扁) :
我为何关不了机呀?应用什么参数?
AhBian 2004-11-13
  • 打赏
  • 举报
回复
[DllImport("user32.dll", EntryPoint="ExitWindowsEx")]
public static extern int ExitWindows (
int dwReserved,
int uReturnCode
);

或者:

[DllImport("user32.dll")]
public static extern int ExitWindowsEx (
int dwReserved,
int uReturnCode
);
dazhu2 2004-11-13
  • 打赏
  • 举报
回复
up

110,534

社区成员

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

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

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