Hi,
I am not saying that Fred is wrong when he talks about constants starting with %EWX_ , they should be used as he said. But there are these undocumented features of Windows to which constants starting with %EW_ belong and they, if used with ExitWindowsEx, are used differently. And they exist.
MS documentation and examples are useless here because these are undocumented features.
If anybody is interested,I have a code sample which shows how to call an undocumented API function RestartDialog, which uses these constants. And the code sample I supplied and PB's sample also show that these constants should be used differently. If you place them where %EWX_ constants are placed, you get totally different result.
Lasse Rantanen
[email protected]
Announcement
Collapse
No announcement yet.
Problems with 32-bit PB/DLL API Call
Collapse
X
-
Guest replied
-
Guys --
1) To understand who is right - PB or Fred, open Win32.Hlp or/and msdn.microsoft.com + Win32Api.Inc.
2) You can find good sample, how to reboot NT on http://support.microsoft.com/support.../Q176/6/95.ASP
(perhaps, EB used it; in any case his code works under Win2000)
------------------
Leave a comment:
-
Guest repliedReboot (%EWX_REBOOT) and Restart Windows (%EW_RESTARTWINDOWS) are different things.
Lasse Rantanen
[email protected]
Leave a comment:
-
Guest repliedSee ResWin on my site (+ code)
------------------
Leave a comment:
-
The following code works fine on Win95
IF (ExitWindowsEx(%EWX_REBOOT,%NULL)=%FALSE) THEN
FUNCTION = %FAILED
END IF
------------------
Leave a comment:
-
Guest repliedFred,
I am not talking about 16-bit Windows but 32-bit ones (Win95, Win98, haven't tried in NT).
Try PB's sample Restart.bas or following small program. Both make call ExitWindowsEx(0,%EW_RESTARTWINDOWS) and it works. However, as I tried to explain, this feature is undocumented by Microsoft and they suggest thunking to 16-bit.
Should we use undocumented features of Windows is another question.
Lasse Rantanen
[email protected]
Code:$COMPILE EXE #INCLUDE "WIN32API.INC" %RESTART = 1000 %CANCEL = 1001 %LABEL1 = 1002 DECLARE CALLBACK FUNCTION RestartProc FUNCTION WINMAIN (BYVAL CurInst AS LONG, _ BYVAL PrvInst AS LONG, _ CmdLine AS ASCIIZ PTR, _ BYVAL CmdShow AS LONG) EXPORT AS LONG LOCAL hDlg AS LONG DIALOG NEW 0, "Restart Windows?", , , 140, 60, %WS_CAPTION , TO hDlg CONTROL ADD LABEL, hDlg, %LABEL1, "", 5, 10, 130, 28 CONTROL ADD BUTTON, hDlg, %RESTART, "Restart", 25, 40, 40, 14 CONTROL ADD BUTTON, hDlg, %CANCEL, "Cancel", 75, 40, 40, 14 DIALOG SHOW MODAL hDlg, CALL RestartProc END FUNCTION CALLBACK FUNCTION RestartProc SELECT CASE CBMSG CASE %WM_COMMAND SELECT CASE CBWPARAM CASE %CANCEL DIALOG END CBHNDL CASE %RESTART CONTROL SET TEXT CBHNDL, %LABEL1, "Restarting Windows 'cause you asked" CALL ExitWindowsEx(0, %EW_RESTARTWINDOWS) CONTROL SET TEXT CBHNDL, %LABEL1, "Windows has been restarted" END SELECT END SELECT END FUNCTION
Leave a comment:
-
Lasse,
Originally posted by Clay Clear:
I am trying to write a Freeware 32-bit program that allows the user to rebbot his machine, power down, force power down, logoff, regular shutdown, and restart Windows. My problem arises when I try to use the Restart Windows options The code I'm trying follows:
CALL ExitWindowsEx(0, %EW_RESTARTWINDOWS)
It seems that you are talking about 16 bit code
Dr. GUI replies:
Sounds like kind of a shifty thing to do, no? But as it turns out, the 32-bit ExitWindowsEx() API does not allow one
to "restart" Microsoft Windows 95. However, if you were to write a 16-bit program and call the 16-bit
ExitWindows() API with the EW_RESTARTWINDOWS parameter, you can restart Windows 95.
You should be able to spawn a 16-bit application to do this. Or,
if you need to do the same from a 32-bit program,
then you will have to thunk down to a 16-bit DLL which calls the 16-bit API.
See the Microsoft Platform SDK (formerly called the Win32 SDK) for documentation on how to write a flat thunk under Windows 95.
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
[This message has been edited by Fred Oxenby (edited February 24, 2000).]
Leave a comment:
-
Guest repliedFred,
First of all, in my systems, PB's sample program Restart.bas works as expected. What might be problem in Clay's case - I must leave that to those who are better informed.
Then to the matter self. This has to do with undocumented features of Win9x. You are right about EWX_ constants, but not about EW_ constants, which do exists.
MS most probably uses them, too. They have (forgotten?) following defines in Winuser.h (my version of VC++ is 5.0)
#if(WINVER >= 0x0400)
#define EW_RESTARTWINDOWS 0x0042L
#define EW_REBOOTSYSTEM 0x0043L
#define EW_EXITANDEXECAPP 0x0044L
#define ENDSESSION_LOGOFF 0x80000000
#endif /* WINVER >= 0x0400 */
Then there is an undocumented function RestartDialog which is exported from SHELL32.DLL and the C declaration seems to be
int WINAPI RestartDialog(HWND hwndOwner, LPCSTR lpstrReason, UINT uFlags);
See http://www.geocities.com/SiliconValley/4942/index.html and then Function Index -> RestartDialog.
http://www.mvps.org/vbnet/code/shell/undocshelldlgs.htm has a Visual Basic example of how to use this function - their reasoning about parameters might not be exactly true (they don't mention these EW_ constants).
I don't know for sure but that function probably calls ExitWindowsEx placing one of the EW_ flags to the second, reserved parameter as PB's sample program does. As always, it is difficult to find out the arguments undocumented functions expect.
BTW, MS advices you to thunk down to a 16-bit DLL, which calls ExitWindows with EW_RESTARTWINDOWS parameter as the first parameter.
Just my $0.02
Lasse Rantanen
[email protected]
------------------
Leave a comment:
-
I did not intend to be rude.
Just wanted to say that you had your parameters switched.
First parameter should be one of those:
Code:%EWX_LOGOFF = &H0 %EWX_SHUTDOWN = &H00000001 %EWX_REBOOT = &H00000002 %EWX_FORCE = &H00000004 %EWX_POWEROFF = &H00000008 %EWX_FORCEIFHUNG = &H00000010 EWX_FORCE AND EWX_FORCEIFHUNG IS MUTUALLY EXCLUSIVE Cannot be used together
Could be anything!
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
Originally posted by Fred Oxenby:
Your code is wrong
Bool = ExitWindowsEx(uFlags,dwReserved)
Your code means that you want to "LOGOFF" windows
Where have you found %EW_RESTARTWINDOWS ?
Try this.
<font face="Courier New, Courier" size="3"><pre>
%EWX_REBOOT = &H00000002
If IsFalse ExitWindowsEx(%EWX_REBOOT,0) Then
result& = GetLastError
'check why it doesn't work...
End if
</pre></font>
If my code is wrong, then the example RESTART.BAS that PowerBASIC supplies with PB/DLL 6.0 is in error. That's where I got the source code. %EW_RESTARTWINDOWS is an equate in the WIN32API.INC file. It is also the equate used in the RESTART.BAS. But, yeah, I determined that by using "CALL ExitWindowsEX(0, %EW_RESTARTWINDOWS) was telling it to logoff of Windows, because of the first parameter in the brackets. So, i tried -1, instead. When I did that, it ALWAYS rebooted, even though I had applications running, which is how I tested it, first. Then, when it rebooted Windows with that option, I couldn't use the icons, and the programs in my System Tray that usually boot at startup weren't running. The Start button on the Taskbar worked, Thank God! At least I could do a power down to restore the settings. However, I never thought of using an error handling routine to see if I can find the error. I'll try that next. Thanks for the idea!
Sincerely,
Clay Clear
Leave a comment:
-
Your code is wrong
Bool = ExitWindowsEx(uFlags,dwReserved)
Your code means that you want to "LOGOFF" windows
Where have you found %EW_RESTARTWINDOWS ?
Try this.
Code:%EWX_REBOOT = &H00000002 If IsFalse ExitWindowsEx(%EWX_REBOOT,0) Then result& = GetLastError 'check why it doesn't work... End if
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
[This message has been edited by Fred Oxenby (edited February 23, 2000).]
Leave a comment:
-
Problems with 32-bit PB/DLL API Call
I am trying to write a Freeware 32-bit program that allows the user to rebbot his machine, power down, force power down, logoff, regular shutdown, and restart Windows. My problem arises when I try to use the Restart Windows options The code I'm trying follows:
CALL ExitWindowsEx(0, %EW_RESTARTWINDOWS)
This is the same calling line as listed in the the RESTART.BAS supplied with PB/DLL. When I run this part of the code WITHOUT Client for Microsoft Network or Client for Netware Network, installed, it simply doesn't work. if I put the full source code as found in RESTART.BAS in the program, it ALWAYS says that "An pplication has refused to quit.". If I don't include that error checking, the program screws up my desktop (i.e., I can no longer select icons on the desktop - I have to cold boot to resotre the staus quo). If I *do* have one of the Clients installed, it works, BUT, after Windows restarts, I get that asinine "Click here to start." message by my Start button, which I *never* get normally. Also, every time I test it with a Client installed, it ALWAYS asks me for my logon password, even though I never put a password in it. That particular dialog says that, if I don't enter a password, the prompt won't appear, again. Well, it lied. So, my questions are: how do I stop those two happenings from occurring when I have a Client installed? Is there any way to tell IF a Client is installed? If there is, I can make the suitable branches in my program, dependent on the status of an installed Client. But, even if I can do that, that still doesn't fix the aforementioned problems I have when a Client is installed.
My platform is a Dell 486SX-33 with 32MB of RAM. My OS is Windows 95 OSR-2. I have memory managers loading in my CONFIG.SYS (I need them because of my DOS-based BBS).
Tags: None
Leave a comment: