Re: Struck with CopyMemory API



> 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/


.



Relevant Pages

  • Re: Struck with CopyMemory API
    ... > Private Declare Function IsBadReadPtr Lib "Kernel32.dll" (ByRef lp As ... ByVal ucb As Long) As Long ... > Private Declare Function IsBadWritePtr Lib "Kernel32.dll" (ByRef lp As ... ....but remember that these may say that a pointer is a good pointer even if ...
    (microsoft.public.vb.winapi)
  • Re: Impersonation using Microsoft Visual C# .NET and Windows 2000
    ... Dim fCapabilities As Integer ... Private Structure SecHandle ... "RtlMoveMemory" (ByRef Destination As SecBuffer, ... Private Declare Function NT4QuerySecurityPackageInfo Lib ...
    (microsoft.public.dotnet.security)
  • Re: current user validation
    ... Type SecHandle ... Private Declare Function NT4QuerySecurityPackageInfo Lib "security" Alias ... ByRef pPackageInfo ... Dim g_NT4 As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: IntersectRect Problem
    ... Rectangle moves over (or even around the PictureBox, ... >> What I want is to able to detect whether the mouse RECT ... >Private Declare Function IntersectRect Lib "User32.dll" ( ... > ByRef lpDestRect As RECT, ByRef lpSrc1Rect As RECT, _ ...
    (microsoft.public.vb.winapi)
  • Re: Select polygon on EMF on MouseOver
    ... Private Declare Function SetWindowExtEx Lib "GDI32.dll" (ByVal hDC As Long, ... ByVal nX As Long, ByVal nY As Long, ByRef lpPoint As Any) As Long ...
    (microsoft.public.vb.general.discussion)

Loading