Re: Struck with CopyMemory API
- From: "Mike D Sutton" <EDais@xxxxxxxx>
- Date: Thu, 21 Jul 2005 21:24:23 +0100
> Sounds like you either forgot a ByVal or used one where it shouldn't be. If you're
> copying data where you shouldn't be, that's a pretty classic *KaBoom!* scenario. (On
> NT systems, any address <&10000 is definitely off-limits, btw.)
You may want to try validating your read/write pointers:
'***
Private Declare Function IsBadReadPtr Lib "Kernel32.dll" (ByRef lp As Any, ByVal ucb As Long) As Long
Private Declare Function IsBadWritePtr Lib "Kernel32.dll" (ByRef lp As Any, ByVal ucb As Long) As Long
....
Private Function IsValidReadPtr(ByVal inPtr As Long, Optional ByVal inSize As Long = 1) As Boolean
IsValidReadPtr = IsBadReadPtr(ByVal inPtr, inSize) = 0
End Function
Private Function IsValidWritePtr(ByVal inPtr As Long, Optional ByVal inSize As Long = 1) As Boolean
IsValidWritePtr = IsBadWritePtr(ByVal inPtr, inSize) = 0
End Function
'***
Use them something like this:
'***
Dim MyVar As Long
Debug.Print IsValidReadPtr(VarPtr(MyVar)) ' True
Debug.Print IsValidWritePtr(VarPtr(MyVar)) ' True
Debug.Print IsValidReadPtr(0) ' False
Debug.Print IsValidWritePtr(0) ' False
'***
Hope this helps,
Mike
- Microsoft Visual Basic MVP -
E-Mail: EDais@xxxxxxxx
WWW: Http://EDais.mvps.org/
.
- Follow-Ups:
- Re: Struck with CopyMemory API
- From: Thorsten Albers
- Re: Struck with CopyMemory API
- From: Karl E. Peterson
- Re: Struck with CopyMemory API
- References:
- Struck with CopyMemory API
- From: Electronic Screw
- Re: Struck with CopyMemory API
- From: Karl E. Peterson
- Struck with CopyMemory API
- Prev by Date: Re: "Invalid handle" when accessing a file created by CreateFile
- Next by Date: Re: The Windows directory location from VB6
- Previous by thread: Re: Struck with CopyMemory API
- Next by thread: Re: Struck with CopyMemory API
- Index(es):
Relevant Pages
|
Loading