1
的味精我有一個WPF
項目用一個簡單的button
,當點擊會顯示他們是在什麼啓動模式的用戶。WPF的按鈕顯示引導模式
我發現從微軟的網站上的一些代碼,但它可能會出約會? 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
任何一個知道如何解決這個問題?
在相同的任何瞭解還讚賞。
感謝那些工作!是的,您在32位和64位之間是正確的。 –
沒問題,從Microsoft網站複製粘貼代碼總是有點令人不安,最終會出現這樣一個可怕的錯誤=)。 –