Results 1 to 6 of 6

Thread: CopyMemory confusion !!!!

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2005
    Posts
    43

    CopyMemory confusion !!!!

    Hi,

    the code below uses the CopyMemory API to copy the address of the variable X to a variable Y.

    after carrying out the copying of memory, the variable Y should contain the value in X.

    Then , if I change the value in X, the variable Y SHOULD now contain the new X value BUT that's not the case as the following test code shows :


    VB Code:
    1. Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    2. (pDst As Long, pSrc As Long, ByVal ByteLen As Long)
    3.  
    4.  
    5. Sub test()
    6.  
    7.     Dim x As Long
    8.     Dim y As Long
    9.    
    10.     x = 123
    11.     CopyMemory y, x, LenB(x)
    12.    
    13.     MsgBox y ' this show 123 as expected
    14.     x = 888
    15.     MsgBox y ' this should show 888 but shows 123 instead !!!!
    16.  
    17. End Sub


    Why is Y - in the second MsgBox - still showing (123) instead of showing the new value in X ie(888)?!

    Am I missing something ?

    Any help much appreciated .
    Last edited by BLUE_SEA; Jan 22nd, 2006 at 07:24 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width