code:
 
#include <string.h>
#include <windows.h>
__declspec(dllexport) int FBD_DLL( float*, float*, int*, int* );
__declspec(dllexport) void zFBD_DLL_info( void* );
__declspec(dllexport) void zFBD_DLL_varname( char* );
// Структура описывающая FBD-модуль
typedef struct
{
int q_in; // Количество входов
int q_out; // Количество выходов
int q_int; // Зарезервировано
int type;  // Номер в списке функциональных разделов. 
           // Должно быть равно 17
char name[8];  // Короткое имя для вывода на экран
char fname[8]; // Полное имя
} DO_DEFAULT;
 
// Тело FBD-модуля
int FBD_DLL( float *in, // Указатель на массив входов
float *out,           // Указатель на массив выходов
int *l, int *rl )     // Зарезервировано
{
	bool AppClose, Reboot;
	if (in[0]==1){
		AppClose=FALSE;
		Reboot	=FALSE;
	}
	if (in[0]==2){
		AppClose=TRUE;
		Reboot	=TRUE;
	}
	if (in[0]==3){
		AppClose=TRUE;
		Reboot	=FALSE;
	}
	if (in[0]==4){
		AppClose=FALSE;
		Reboot	=TRUE;
	}
	if (in[0]>0){
HANDLE hToken;              // handle to process token 
TOKEN_PRIVILEGES tkp;       // pointer to token structure 
 
BOOL fResult;               // system shutdown flag 
 
// Get the current process token handle so we can get shutdown 
// privilege. 
 
if (!OpenProcessToken(GetCurrentProcess(), 
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
    out[0]=1;
		//printf("OpenProcessToken failed.\n");
 
// Get the LUID for shutdown privilege. 
 
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
        &tkp.Privileges[0].Luid); 
 
tkp.PrivilegeCount = 1;  // one privilege to set    
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
 
// Get shutdown privilege for this process. 
 
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
    (PTOKEN_PRIVILEGES) NULL, 0); 
 
// Cannot test the return value of AdjustTokenPrivileges. 
 
if (GetLastError() != ERROR_SUCCESS) 
    out[0]=2;
	//printf("AdjustTokenPrivileges enable failed.\n"); 
 
// Display the shutdown dialog box and start the time-out countdown. 
 
fResult = InitiateSystemShutdown( 
    "",										// shut down local computer 
    "This PC will be shutdown now.",		// message to user 
    (unsigned int)in[1],                                  // time-out period 
    AppClose,                               // ask user to close apps 
    Reboot);                                // reboot after shutdown 
 
if (!fResult) 
{ 
    out[0]=3;
	//printf("InitiateSystemShutdown failed.\n"); 
} 
 
// Disable shutdown privilege. 
 
tkp.Privileges[0].Attributes = 0; 
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
        (PTOKEN_PRIVILEGES) NULL, 0); 
 
if (GetLastError() != ERROR_SUCCESS) 
{
    out[0]=4;
	//printf("AdjustTokenPrivileges disable failed.\n"); 
}
out[0]=0;
	}
	
return 0;
}
// Формирует указатель на описание FBD-модуля
void zFBD_DLL_info( void *buf )
{
DO_DEFAULT *dd;
dd=(DO_DEFAULT *)buf;
 
strcpy( dd->name, "Reset" );
strcpy( dd->fname, "Reset" );
dd->q_in  = 3;
dd->q_out = 1;
dd->type  = 17;
dd->q_int = 0;
}
// Формирует указатель на имена входов и выходов. 
// На каждое имя отводится 8 байт
void zFBD_DLL_varname( char *varname )
{
strcpy( varname+0, "RUN" );
strcpy( varname+8, "RCMD" );
strcpy( varname+16, "TM" );
strcpy( varname+24, "RES" );
}