【问题标题】:WPF-button show msg of bootmodeWPF 按钮显示引导模式的消息
【发布时间】:2013-07-30 20:10:57
【问题描述】:

我有一个WPF 项目,其中包含一个简单的button,当点击时会向用户显示他们所处的启动模式。

我从微软的网站上找到了一些代码,但它可能已经过时了? http://support.microsoft.com/kb/291664

这是我的代码:

Class MainWindow


 Private Declare Function GetSystemMetrics Lib "user32" _
   (ByVal nIndex As Long) As Long
    Const SM_CLEANBOOT& = 67
    Private Sub DetectModeButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles DetectModeButton.Click
    Dim result As Long

    result = GetSystemMetrics(SM_CLEANBOOT)

    Select Case result
        Case 0
            MsgBox("System started in normal mode.")
        Case 1
            MsgBox("System started in safe mode.")
        Case 2
            MsgBox("System started in safe mode with networking.")
        Case Else
            MsgBox("Unknown value returned from GetSystemMetrics.")
    End Select
End Sub
End Class

我在运行时收到以下错误:

A call to PInvoke function 'BootModeTest!BootModeTest.MainWindow
::GetSystemMetrics' has unbalanced the stack. This is likely 
because the managed PInvoke signature does not match the 
unmanaged target signature. Check that the calling 
convention and parameters of the PInvoke 
signature match the target unmanaged signature

有人知道怎么解决吗?

对此的任何见解也表示赞赏。

【问题讨论】:

    标签: wpf vb.net detect boot


    【解决方案1】:

    签名错误,看起来该页面的代码不正确。将其更改为:

    Private Declare Function GetSystemMetrics Lib "user32" _
      (ByVal nIndex As Integer) As Integer
    

    (可能与在 32 位和 64 位机器上运行有关)

    【讨论】:

    • 感谢工作!是的,您在 32 位和 64 位以上是正确的。
    • 没问题,从微软网站复制粘贴代码总是有点不安,最后出现这么可怕的错误=)。
    猜你喜欢
    • 2017-03-24
    • 2020-05-28
    • 2017-09-25
    • 2020-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多