Windows Embedded does not honor ShutdownBlockReasonCreate -
the following program works on windows 7 not on windows 7 embedded standard service pack 1. not prevent shutdown (e.g. shutdown /r /t 0) happening.
this similar question 1 linked duplicate. question has accepted answer of "it not work". provide sourcecode working solution in windows 7 needs adjustment windows embedded.
any ides how working on embedded? or @ least hint windows docu points difference out?
#include <windows.h> #include <stdio.h> const char g_szclassname[] = "mywindowclass"; // step 6: window procedure lresult callback wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam) { switch(msg) { case wm_queryendsession: outputdebugstr("got wm_queryendsession message\n"); char buf[1024]; sprintf(buf, "callback %d %d\n", wparam, lparam); outputdebugstr(buf); return false; // false should prevent reboot break; case wm_endsession: outputdebugstr("got wm_endsession message\n"); sleep(5000); // should never here! break; case wm_close: outputdebugstr("got wm_close message\n"); destroywindow(hwnd); break; case wm_destroy: outputdebugstr("got wm_destroy message\n"); postquitmessage(0); break; default: return defwindowproc(hwnd, msg, wparam, lparam); } return 0; } int winapi winmain(hinstance hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) { wndclassex wc; hwnd hwnd; msg msg; //step 1: registering window class wc.cbsize = sizeof(wndclassex); wc.style = 0; wc.lpfnwndproc = wndproc; wc.cbclsextra = 0; wc.cbwndextra = 0; wc.hinstance = hinstance; wc.hicon = loadicon(null, idi_application); wc.hcursor = loadcursor(null, idc_arrow); wc.hbrbackground = (hbrush)(color_window+1); wc.lpszmenuname = null; wc.lpszclassname = g_szclassname; wc.hiconsm = loadicon(null, idi_application); if(!registerclassex(&wc)) { messagebox(null, "window registration failed!", "error!", mb_iconexclamation | mb_ok); return 0; } // step 2: creating window hwnd = createwindowex( ws_ex_clientedge, g_szclassname, "the title of window", ws_overlappedwindow, cw_usedefault, cw_usedefault, 240, 120, null, null, hinstance, null); if(hwnd == null) { messagebox(null, "window creation failed!", "error!", mb_iconexclamation | mb_ok); return 0; } showwindow(hwnd, ncmdshow); updatewindow(hwnd); // step 3: provide reason shutdown prevention bool ret = shutdownblockreasoncreate(hwnd, l"preventshutdown running prevents shutdown"); if(ret == false) { messagebox(null, "shutdownblockreasoncreate failed!", "error!", mb_iconexclamation | mb_ok); return 0; } // step 4: elevate program asked possible inhibit shutdown ret = setprocessshutdownparameters(0x4ff, shutdown_noretry) if(ret == false) { messagebox(null, "shutdownblockreasoncreate failed!", "error!", mb_iconexclamation | mb_ok); return 0; } outputdebugstr("now starting message loop\n"); // step 5: message loop while(getmessage(&msg, null, 0, 0) > 0) { translatemessage(&msg); dispatchmessage(&msg); } return msg.wparam; }
we have canonical answer question, you'll find it here. 7 hundred views , half year of researching make best known answer, can't done.
keep eye on your existing question on msdn forums.
i'll close few graphical explanations why kind of feature not implemented on embedded operating system:
Comments
Post a Comment