Results 1 to 3 of 3

Thread: CopyMemory

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Question

    Why does the API CopyMemory behave in a variant of ways?

    Eg

    If I want to move a type to a string then I have to use

    Code:
        sTemp = Space$(Len(ETU7CallType))
        
        CopyMemory ByVal sTemp, SomeCallType, Len(sTemp)

    but if I want to copy a string to a type then I have to use

    Code:
    CopyMemory guETU7Type, ByVal sTGB, Len(guETU7Type)
    I know there are reasons and I would just like to know why - cos I'm fed up of having to reload the project after vb crashes!
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    IT's crashes because you don't know how a string is stored. Strings in vb are unicode by default, so the memory space needed for a string is 2*the length of the string. Therefore either convert the string first or feed a smaller string.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Knowledge

    I know that byval sends the value of the stated variable, but that still hasn't really explained *why* in the first example the source is sent byref and not byval.
    Matt G
    VS6 Ent SP5 @ Work
    VS6 Ent SP5 & VB.Net @ Home
    [email protected]



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