开发者

Why Does CascadeWindows win32 function throws an AccessViolationException on windows 7

开发者 https://www.devze.com 2023-01-14 10:36 出处:网络
Private Declare Function CascadeWindowsNative Lib \"user32\" Alias \"CascadeWindows\" ( _ ByVal hwndParent As Long, _
Private Declare Function CascadeWindowsNative Lib "user32" Alias "CascadeWindows" ( _
   ByVal hwndParent As Long, _
   ByVal wHo开发者_如何学JAVAw As Long, _
   ByVal lpRect As Long, _
   ByVal cKids As Long, _ 
   ByVal lpkids As Long) As Integer

calling:

CascadeWindowsNative(Nothing, &H4, 0, 0, 0)


The primary issues here is that you are passing handle values with the Long type. That is incorrect, they need to be passed via the IntPtr type. Under the hook handles are essentially pointers and vary in size based on whether or not the process is 32 or 64 bit.

I'm not familiar with that API so I don't know if the rest of the parameters are correct or not. The sample code on PInvoke.Net suggests that several of these should be typed to something other than Long

  • http://www.pinvoke.net/default.aspx/user32.cascadewindows

What's likely happening here is one of the computers you're running is 64 bit and the pinvoke call is working and the other is 32 bit and the call is failing due to the inherent stack imbalance.


This works:

Private Declare Function CascadeWindowsNative Lib "user32" Alias "CascadeWindows" (ByVal hwndParent As IntPtr,
                                                                                   ByVal wHow As UInt32,
                                                                                   ByVal lpRect As IntPtr,
                                                                                   ByVal cKids As UInt32,
                                                                                   ByVal lpkids() As IntPtr) As Integer
0

精彩评论

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