Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用C中的系统参数信息(SPI_GETSCREENREADER SPI_SETSCREENREADER)_C#_User32 - Fatal编程技术网

C# 使用C中的系统参数信息(SPI_GETSCREENREADER SPI_SETSCREENREADER)

C# 使用C中的系统参数信息(SPI_GETSCREENREADER SPI_SETSCREENREADER),c#,user32,C#,User32,我这样做对吗 [DllImport("user32", CharSet = CharSet.Auto)] internal static extern long SystemParametersInfo(long uAction, int lpvParam, ref bool uParam, int fuWinIni); ... public static bool IsScreenReaderRunning() { long SPI_GETSCREENREADER = 70L;

我这样做对吗

[DllImport("user32", CharSet = CharSet.Auto)]
internal static extern long SystemParametersInfo(long uAction, int lpvParam, ref bool uParam, int fuWinIni);

...

public static bool IsScreenReaderRunning()
{
    long SPI_GETSCREENREADER = 70L;
    bool bScreenReader = false;
    long retVal;

    retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);

    //uint iParam = 0;
    //uint iUpdate = 0;
    //bool result = false;
    //bool bReturn = SystemParametersInfo(SPI_GETSCREENREADER, iParam, &bScreenReader, iUpdate);
    return bScreenReader;
}

public static void ScreenReaderOn()
{
    long SPI_GETSCREENREADER = 71L;
    bool bScreenReader = true;
    long retVal;

    retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}

public static void ScreenReaderOff()
{
    long SPI_GETSCREENREADER = 71L;
    bool bScreenReader = false;
    long retVal;

    retVal = SystemParametersInfo(SPI_GETSCREENREADER, 0, ref bScreenReader, 0);
}
基于此,SystemParametersInfo的最后一个参数应为:

int SPIF_SENDCHANGE = 0x02;

更改值时。

pinvoke声明完全错误,它是从VB6代码复制的。返回类型和参数的长度不是VB6 int32类型,而是int。Pinvoke.net是获得良好声明的理想站点

[DllImport("user32.dll", SetLastError = true)]
static extern bool SystemParametersInfo(int uiAction, int uiParam, IntPtr pvParam, int fWinIni);

当您得到错误返回时,不要忘记抛出Win32Exception,这样失败就不会沉默。

以上代码对您不起作用吗?Hans,非常感谢您的回复。我还是不能让它工作。我所需要的只是一个工作的SPI_GETSCREENREADER方法——只是一个检查阅读器的C方法。你有一个有效的例子吗?我似乎无法从C中得到它的任何变体。我在IntPtr中传递什么?你可以在pinvoke声明中撒谎,并将其设为ref int。如果安装了读卡器,你会得到1。