DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: CopyMemory

Hybrid View

  1. #1
    Jack Guest

    CopyMemory


    Hi,
    I tried to use CopyMemory to copy Variant to String, but it did not work,
    can you help me?

    The Code:
    ---------------------
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination
    As Any, Source As Any, ByVal Length As Long)

    Private Sub Command1_Click()
    Dim sDes As String, vSou As Variant
    vSou = "abc"
    sDes = Space$(3)
    CopyMemory ByVal sDes, ByVal VarPtr(vSou), 6
    Debug.Print sDes
    End Sub
    -----------------

    Thanks


  2. #2
    Anthony Jones Guest

    Re: CopyMemory

    Jack,

    Use StrPtr instead of VarPtr.

    Can I ask why you would want to do this?

    sDes = vSou does the same thing.

    --
    Anthony Jones
    Nuesoft Ltd




  3. #3
    crystone Guest

    Re: CopyMemory


    "Jack" <jackyyin@netease.com> wrote:
    >
    >Hi,
    >I tried to use CopyMemory to copy Variant to String, but it did not work,
    >can you help me?
    >
    >The Code:
    >---------------------
    >Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination
    >As Any, Source As Any, ByVal Length As Long)
    >
    >Private Sub Command1_Click()
    >Dim sDes As String, vSou As Variant
    >vSou = "abc"
    >sDes = Space$(3)
    >CopyMemory ByVal sDes, ByVal VarPtr(vSou), 6

    please try replace it by this:
    CopyMemory sDes,vSou,3

    >Debug.Print sDes
    >End Sub
    >-----------------
    >
    >Thanks
    >



  4. #4
    Anthony Jones Guest

    Re: CopyMemory

    > CopyMemory sDes,vSou,3

    Booomm!! :-)

    --
    Anthony Jones
    Nuesoft Ltd




  5. #5
    Anthony Jones Guest

    Re: CopyMemory

    Jack,

    Use StrPtr instead of VarPtr.

    Can I ask why you would want to do this?

    sDes = vSou does the same thing.

    --
    Anthony Jones
    Nuesoft Ltd




  6. #6
    crystone Guest

    Re: CopyMemory


    "Jack" <jackyyin@netease.com> wrote:
    >
    >Hi,
    >I tried to use CopyMemory to copy Variant to String, but it did not work,
    >can you help me?
    >
    >The Code:
    >---------------------
    >Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination
    >As Any, Source As Any, ByVal Length As Long)
    >
    >Private Sub Command1_Click()
    >Dim sDes As String, vSou As Variant
    >vSou = "abc"
    >sDes = Space$(3)
    >CopyMemory ByVal sDes, ByVal VarPtr(vSou), 6

    please try replace it by this:
    CopyMemory sDes,vSou,3

    >Debug.Print sDes
    >End Sub
    >-----------------
    >
    >Thanks
    >



  7. #7
    Anthony Jones Guest

    Re: CopyMemory

    > CopyMemory sDes,vSou,3

    Booomm!! :-)

    --
    Anthony Jones
    Nuesoft Ltd




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center