Is the Screensaver running?
-
All I want to know is, "is the screensaver running or not?". This problem seems to be much harder than it should be. I'm attempting to use SystemParametersInfo api call to determine if it is running or not, but I keep getting an err.LastDllError. Language: VB.Net Platform: Win XP Can anybody stop this coder from suiciding over something that should be fairly easy?
-
All I want to know is, "is the screensaver running or not?". This problem seems to be much harder than it should be. I'm attempting to use SystemParametersInfo api call to determine if it is running or not, but I keep getting an err.LastDllError. Language: VB.Net Platform: Win XP Can anybody stop this coder from suiciding over something that should be fairly easy?
Could you post the code your using? It would make determining what's wrong much easier. I've done this in the past using VB6 and never had a problem. It translates easily into VB.NET. The article I've based my code on can be found http://support.microsoft.com/default.aspx?scid=kb;en-us;Q315725&ID=kb;en-us;Q315725&SD=MSDN[^]. RageInTheMachine9532
-
Could you post the code your using? It would make determining what's wrong much easier. I've done this in the past using VB6 and never had a problem. It translates easily into VB.NET. The article I've based my code on can be found http://support.microsoft.com/default.aspx?scid=kb;en-us;Q315725&ID=kb;en-us;Q315725&SD=MSDN[^]. RageInTheMachine9532
Thanks for replying Rage. This is the code I am using and am getting back an error code (lastDllError code I think) of 998. I can't seem to find any information on the error codes for SystemParametersInfoA. Also, as VB.Net doesn't have any "Any" type I have used the VariantType, Object type, and boolean type all to no avail. 'My Code Private Declare Function SystemParametersInfo _ Lib "user32" _ Alias "SystemParametersInfoA" _ (ByVal uiAction As Long, _ ByVal uiParam As Long, _ ByRef pvParam As VariantType, _ ByVal fWInIni As Long) As Boolean Private Const SPI_GETSCREENSAVEACTIVE As Long = &H10 Private Const SPI_GETSCREENSAVERRUNNING As Long = &H72 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim p_lngRtn As Long p_lngRtn = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, bRunning, False) If bRunning Then Beep() End If If p_lngRtn = 0 Then Debug.WriteLine(Err.LastDllError) End If End Sub
-
Thanks for replying Rage. This is the code I am using and am getting back an error code (lastDllError code I think) of 998. I can't seem to find any information on the error codes for SystemParametersInfoA. Also, as VB.Net doesn't have any "Any" type I have used the VariantType, Object type, and boolean type all to no avail. 'My Code Private Declare Function SystemParametersInfo _ Lib "user32" _ Alias "SystemParametersInfoA" _ (ByVal uiAction As Long, _ ByVal uiParam As Long, _ ByRef pvParam As VariantType, _ ByVal fWInIni As Long) As Boolean Private Const SPI_GETSCREENSAVEACTIVE As Long = &H10 Private Const SPI_GETSCREENSAVERRUNNING As Long = &H72 Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim p_lngRtn As Long p_lngRtn = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, bRunning, False) If bRunning Then Beep() End If If p_lngRtn = 0 Then Debug.WriteLine(Err.LastDllError) End If End Sub
OK. All of your code is good except for one thing. Change all of your 'Long's to Integers. Long's in VB.NET are 64-bit integers and 32-bit in VB6. This is one of your problems. The other is that your VariantType just needs to be an integer. All the pvParam is returning is a boolean value saying True or False. When you call a function that has an ANy type in it, you have to think ahead and replace the Any with the type that you EXPECT to get back. In this case, a 32-bit Integer would work. The corrected code look like this:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" \_ (ByVal uiAction As Integer, \_ ByVal uiParam As Integer, \_ ByRef pvParam As Integer, \_ ByVal fWInIni As Integer) As Boolean Private Const SPI\_GETSCREENSAVEACTIVE As Integer = &H10 Private Const SPI\_GETSCREENSAVERRUNNING As Integer = &H72 Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim p\_lngRtn As Integer Dim bRunning As Boolean p\_lngRtn = SystemParametersInfo(SPI\_GETSCREENSAVERRUNNING, 0, bRunning, False) If p\_lngRtn = 0 Then Debug.WriteLine(Err.Description) End If If bRunning Then Beep() End If End Sub
Also, when calling into the API, exceptions will not be thrown, and the Err object will not be set at all. You would have to use the return value, 'p_lngRtn' is your code, to determine that an error HAS occured, then you would have to call the API function GetLastError to get the actual error that occured. Your's was probably something like '87 - The parameter is incorrect'. RageInTheMachine9532
-
OK. All of your code is good except for one thing. Change all of your 'Long's to Integers. Long's in VB.NET are 64-bit integers and 32-bit in VB6. This is one of your problems. The other is that your VariantType just needs to be an integer. All the pvParam is returning is a boolean value saying True or False. When you call a function that has an ANy type in it, you have to think ahead and replace the Any with the type that you EXPECT to get back. In this case, a 32-bit Integer would work. The corrected code look like this:
Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" \_ (ByVal uiAction As Integer, \_ ByVal uiParam As Integer, \_ ByRef pvParam As Integer, \_ ByVal fWInIni As Integer) As Boolean Private Const SPI\_GETSCREENSAVEACTIVE As Integer = &H10 Private Const SPI\_GETSCREENSAVERRUNNING As Integer = &H72 Private Sub Timer1\_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim p\_lngRtn As Integer Dim bRunning As Boolean p\_lngRtn = SystemParametersInfo(SPI\_GETSCREENSAVERRUNNING, 0, bRunning, False) If p\_lngRtn = 0 Then Debug.WriteLine(Err.Description) End If If bRunning Then Beep() End If End Sub
Also, when calling into the API, exceptions will not be thrown, and the Err object will not be set at all. You would have to use the return value, 'p_lngRtn' is your code, to determine that an error HAS occured, then you would have to call the API function GetLastError to get the actual error that occured. Your's was probably something like '87 - The parameter is incorrect'. RageInTheMachine9532
Yup!.. that's solved it alright! I don't think I woulda ever thought about the difference between vb6 and vb.net integers.. :confused: Thanks! Just one question though, you don't happen to know where the error codes are listed for api errors? I was getting an error code of 998 and couldn't find out what it meant to be able to fix this problem.. Thanks again!
-
Yup!.. that's solved it alright! I don't think I woulda ever thought about the difference between vb6 and vb.net integers.. :confused: Thanks! Just one question though, you don't happen to know where the error codes are listed for api errors? I was getting an error code of 998 and couldn't find out what it meant to be able to fix this problem.. Thanks again!