Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Is the Screensaver running?

Is the Screensaver running?

Scheduled Pinned Locked Moved Visual Basic
csharpjsonhelpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Roidzo
    wrote on last edited by
    #1

    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?

    D 1 Reply Last reply
    0
    • R Roidzo

      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?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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

      R 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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

        R Offline
        R Offline
        Roidzo
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • R Roidzo

          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

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • D Dave Kreskowiak

            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

            R Offline
            R Offline
            Roidzo
            wrote on last edited by
            #5

            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!

            D 1 Reply Last reply
            0
            • R Roidzo

              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!

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              998 wouldn't have told you what the problem was either. It means "Invalid access to memory location." The only thing it would have told you is that your passing an invalid reference to a variable, or memory location. The complete list of Win32 API errors can be found here[^]. RageInTheMachine9532

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups