Megalith
Well-known member
- Joined
- Aug 21, 2006
- Messages
- 66
- Programming Experience
- 10+
I have been working on an application in VB.NET 2005, essentially the routine i'm currently developing finds the handle of a window then it is meant to locate the desktop location and size of this window. I decided that GetWindowRect would probably be the best way to achieve my desired result however i get the following exception:-
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I have declared the API function like this
The Subroutine that causes the violation is
the line in red is the one that throws the exception. The routine to find the handle is correct and the correct handle is passed to the Sub. I think it is to do with the Rectangle but i'm at a loss i have tried a few things but always get the same error. I'm overlooking something obvious i feel, can anybody point me in the right direction?
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
I have declared the API function like this
VB.NET:
Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Integer, _
ByVal lpRect As Rectangle) _
As Integer
VB.NET:
Private Sub DesktopSize(hWndParent)
' first define a rectangle
Dim RECT As Rectangle
'Now a point for the mouse location
Dim Pnt As Point
' Get the coordinates for the box on the screen
[COLOR=Red]GetWindowRect(hWndParent, RECT) [/COLOR]
' set Pnt to equal just inside bottom left corner
Pnt.X = RECT.Left + 8
Pnt.Y = RECT.Bottom - 24
' set the mouse to this location
'SetCursorPos(Pnt.X, Pnt.Y)
End Sub