1

我正在尝试捕获屏幕保护程序事件,但是当我运行我的应用程序时,它会引发以下异常;

在 DLL“user32.dll”中找不到名为“SystemParametersinfo”的入口点。

到目前为止,这是我的代码,任何和所有的帮助将不胜感激=D

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NLog;
using Topshelf;
using OsWatch;
using Microsoft.Win32;
using System.Runtime.InteropServices;


namespace NotifyIcon
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            SystemEvents.SessionSwitch += SystemEvents_SessionSwitch;

        }

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SystemParametersinfo(int uAction, int uParam, ref int ipvParam, int fuWinini);

        const int SPI_GETSCREENSAVERRUNNING = 114;
        static int screenSaverRunning = -1;
        int ok = SystemParametersinfo(SPI_GETSCREENSAVERRUNNING, 0, ref screenSaverRunning, 0);

        private void ScreenSaver()
        {
            if (ok == 0)
            {
                Logger.Trace("SCREENSAVER OFF");
            }

            if (screenSaverRunning != 0)
            {
                Logger.Trace("SCREENSAVER ON");

            }
        }
4

0 回答 0