我这样做是否正确?
[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);
}
答案 0 :(得分:3)
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,所以失败不是沉默。
答案 1 :(得分:0)