// RestartComputer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
void main(int argc, char* argv[])
{typedef int (CALLBACK *SHUTDOWNDLG)(int); //显示关机对话框函数的指针
HINSTANCE hInst = LoadLibrary("shell32.dll"); //装入shell32.dll
SHUTDOWNDLG ShutDownDialog; //指向shell32.dll库中显示关机对话框函数的指针
if(hInst != NULL)
{
//获得函数的地址并调用之
ShutDownDialog = (SHUTDOWNDLG)GetProcAddress(hInst,(LPSTR)60);
(*ShutDownDialog)(0);
}
}
本文提供了一个使用C++实现重启计算机的示例代码。通过加载shell32.dll库和调用显示关机对话框函数,实现了重启功能。代码适用于Windows平台。

被折叠的 条评论
为什么被折叠?



