Results 1 to 10 of 570

Thread: Tests Copying, Pasting, API Cliipboard issues. and Rough notes on Advanced API stuff

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10
    String Long And Bytes RtlMoveMemory

    This follows on from the last posts, using similar coding, and only "touches" at the edge strings, because we want to remain cautious and develop slowly coding that experiments with strings and the win32 API
    We will use the 3 character string example already discussed in a few places previously
    A…e
    We will put the copied bytes into a byte array, and to be on the safe side for now we will use our second version of the RtlMoveMemory which takes a pointer of the source memory location. That way we will avoid a direct use of a string variable.
    Because we want to be careful initially we will consider the string as we are fairly sure that it appears in memory:
    https://i.postimg.cc/RhmXzjq7/6A-e0.jpg
    6A…e0.jpg

    We are fairly sure of the 12 byte total length structure, and that the pointer that we use is going to the start of the character array. So we will make the byte array 12 bytes, and pass the memory location of 4 less than that given by StrPtr( )
    Code:
    Option Explicit
     #If VBA7 Then
      Private Declare PtrSafe Sub VBGetTarget Lib "kernel32" Alias "RtlMoveMemory" (ByRef  Target As Byte, ByVal lPointer As LongPtr, ByVal cbCopy As LongPtr)
     #Else
      Private Declare Sub  VBGetTarget Lib "kernel32" Alias "RtlMoveMemory" (ByRef Target As Byte, ByVal lPointer As Long, ByVal cbCopy As Long)
     #End If
    Sub StringLongsCopyMemory()        '  https://www.excelfox.com/forum/showthread.php/2824-Tests-Copying-Pasting-API-Cliipboard-issues-and-Rough-notes-on-Advanced-API-stuff?p=17885&viewfull=1#post17885
    Dim strBSTR As String
     Let strBSTR = "A" & "…" & "e"     '  Three characters, ( the middle one is Unicode ChrW(8230) and also it is in most Window Code Pages also AASI Chr(133)    https://i.postimg.cc/jjpq36WF/6A-e0.jpg
    
    Dim ByteArray(0 To 11) As  Byte      ' 4 bytes for length indicator, then 6 bytes for 3 characters then the ladt two bytes fir the trailing  Null Character
    VBGetTarget ByteArray(0), StrPtr(strBSTR) - 4, 12 '  The  StrPtr  takes us to the start of the character array, so  -4  will takes us to the start of the  12  bytes that we are interested in
    Call DBugPrntArr(ByteArray())      ' {6, 0, 0, 0, 65, 0, 38, 32, 101, 0, 0, 0}
    End Sub
    The final results
    ______________ {6, 0, 0, 0, 65, 0, 38, 32, 101, 0, 0, 0}
    , tie up very well with our prediction.
    Note that the 4 byte 32 bit length indicator held in memory is the byte length of the character array, and the order follows the same "back to front byte order" as we saw for the long variable. In other words, the 32 digit binary that normal school maths and most other conventional things for the value of 6 would look like this
    00000000 00000000 00000000 00000110 = decimal 6
    , but in the "back to front byte order" as held in memory, we have
    00000110 00000000 00000000 00000000
    ( As ever, remember that it is the 4 bytes that are shuffled/ reordered, it is not the entire bits in reverse order )
    Last edited by DocAElstein; 02-15-2025 at 01:31 PM.

Similar Threads

  1. Some Date Notes and Tests
    By DocAElstein in forum Test Area
    Replies: 5
    Last Post: 03-26-2025, 02:56 AM
  2. Replies: 116
    Last Post: 02-23-2025, 12:13 AM
  3. Replies: 21
    Last Post: 12-15-2024, 07:13 PM
  4. Replies: 42
    Last Post: 05-29-2023, 01:19 PM
  5. Replies: 11
    Last Post: 10-13-2013, 10:53 PM

Posting Permissions

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