开发者

when calling GetProductInfo gets an PInvokeStackImbalance error [VB.NET]

I am testing this on Win 7 Ultimate and it generates an error:

PInvokeStackImbalance was detected Message: A call to PInvoke function 'WindowsApplication1!WindowsApplication1.Form1::GetProductInfo' 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.

Public Class Form1


   Private Const PRODUCT_STARTER As Integer = &HB                            'Starter
   Private Const PRODUCT_HOME_BASIC As Integer = &H2                         'Home Basic
   Private Const PRODUCT_HOME_BASIC_N As Integer = &H5                       'Home Basic N
   Private Const PRODUCT_HOME_PREMIUM As Integer = &H3                       'Home Premium
   Private Const PRODUCT_HOME_PREMIUM_N As Integer = &H1A                    'Home Premium N
   Private Const PRODUCT_BUSINESS As Integer = &H6       开发者_如何转开发                    'Business
   Private Const PRODUCT_BUSINESS_N As Integer = &H10                        'Business N
   Private Const PRODUCT_ENTERPRISE As Integer = &H4                         'Enterprise
   Private Const PRODUCT_ENTERPRISE_N As Integer = &H1B                      'Enterprise N
   Private Const PRODUCT_ULTIMATE As Integer = &H1                           'Ultimate
   Private Const PRODUCT_ULTIMATE_N As Integer = &H1C                        'Ultimate N

   Private Declare Function GetProductInfo Lib "kernel32" _
      (ByVal dwOSMajorVersion As Long, ByVal dwOSMinorVersion As Long, _
      ByVal dwSpMajorVersion As Long, ByVal dwSpMinorVersion As Long, _
      ByRef pdwReturnedProductType As Long) As Long

   Public Function GetOSProduct() As String
      Dim os As OperatingSystem = Environment.OSVersion
      Dim prodType As Long
      GetOSProduct = ""
      If GetProductInfo(os.Version.Major, os.Version.Minor, 0, 0, prodType) Then
         Select Case prodType
            Case PRODUCT_ULTIMATE
               GetOSProduct = "Ultimate"
            Case PRODUCT_ULTIMATE_N
               GetOSProduct = "Ultimate N"
            Case Else
               GetOSProduct = "unknown"
         End Select
      End If
   End Function

   Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
      MsgBox(GetOSProduct)
   End Sub
End Class

can anyone help me out?


just replace Long (used in VB6) with Integer (used in VB.NET)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜