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

    I am thinking/ guessing that some of the workings being examined here may be involved in the workings that cause the issues/ problems that are the subject of this page 2
    I am thinking there seems to be a some similarity in the back end workings / storings of the ANSI and Unicode Byte arrays suggested and a string itself, a sort of 1 to 1 matching to Byte and character, which we are exposing.
    For learning and explaining convenience, 3, -4 things could be considered,
    _ Hacks/ possibilities when using a declarations and assignments involving Byte() type arrays. This seems to be slightly more useful than the next two, even though this is not a specific function but arises due to the 1 to 1 matching of Byte and character idea
    _ the StrConv(string, conversion:= vbFromUnicode, LCID)
    _ the StrConv(string, conversion:= vbUnicode, LCID)
    (_ Tricks involving user defined Types and the LSet statement. These mainly give us a simpler alternative to using some api functions )

    Here are some coding experiments, remembering a few important things and/or some gut feelings:
    _ that the 32 bit pointer in the variable BSTR, points to the beginning of the character array, not to the 4-byte length field that precedes the array.
    _ The strConv is a fairly simple ignorant thing. I am thinking that argument names have some meaning: That does occasionally happen with Microsoft, especially for older things such as this function
    _ I am thinking that the strConv() function is a bit simple / ignorant, something like a cross wire or short circuit allowing, amongst other things, a conversion between ANSI and Unicode to work depending on how we organise things. Think of it as a crude junction between two transport mechanisms. One that is made by simply arranging that they come together. Something else will usually need to be done to make the transfer work. When using a declarations and assignments involving Byte() type arrays, perhaps some similar processes go on.
    Regardless of if any of those ideas are any good, they may match or help to remember the important useful results, so let’s get on with looking at those:

    Rem 2 "Unicode To ANSI"
    According to the documentation …
    vbFromUnicode ' Converts the string from Unicode to the default code page of the system.
    This sounds not so inaccurate considering the results. At least initially: A typical result from something like
    Dim ByteArr() As Byte
    ByteArr() = StrConv("Alan", vbFromUnicode)

    , suggests perhaps that an array of Bytes separated by a vbNullChar is looked for, after which in such a case it may , deep down see something that (in its decimal interpretation), would look like
    65 0 108 0 97 0 110 0 or perhaps interpreted as an array {65, 0, 108, 0, 97, 0, 110, 0}
    , so a reasonable return could be considered as what we do indeed get ,
    {65, 108, 97, 110}
    ( I am not sure why a decimal code point is given, perhaps that is just the convention of VBA and the VB editor. But it is what we get: https://i.postimg.cc/fytpYm4V/Byte-Array.jpg )
    However, it seems quite easy to trick the StrConv(string, conversion:= vbFromUnicode, LCID) In ' 2d we feed it a string "A" & vbNullChar & "E" & vbNullChar and perhaps it somehow sees a sort of character set like deep inside which in some form or another is pseudo like [65 0] & vbNullChar & [69 0] & vbNullChar or [65 vbNullChar] & vbNullChar & [69 vbNullChar] & vbNullChar. So maybe it interprets that as an array of two things that have a non used byte (vbNullChar ) separating them which is how a "ANSI" looks, and so removes the separating vbNullChar, but VB and VBA now see 65 0 69 0, and this is recognised as a valid Unicode UTF-16 2 Byte string representation of AE

    Rem 1 … Unicode? ToUnicode?
    We consider here the StrConv(string, conversion:= vbUnicode, LCID) , a slightly rather curious thing, considering …we note that the documentation suggests some sort of opposite of the previous example, VbUnicode ' Converts the string to Unicode using the default code page of the system , whereas the argument name is not quite the opposite, since the opposite would suggest ToVbUnicode, which it isn't.
    Based on the discussions so far, we might have expected that feeding it something like "Alan" would return us something that perhaps could be got in a Byte array looking something like this.
    {65, 0, 108, 0, 97, 0, 110, 0}
    It does not do that. That would be showing how VB holds "Alan" in memory. ( Rem 0 seems to do that !!!)
    However we can’t seem to get that directly, and the results suggest it does nothing more than add a vbNullChar to each character.
    However interesting is the result in ' 1b which appears to be doing some thing like we expected, but doing on the modified string coming from the initial StrConv(BSTR, vbUnicode). This appears to come from a string assignment to the Byte array ' ### !!!

    ' 1d We can only get some opposite idea to conversion:= vbFromUnicode if we apply conversion:= vbUnicode to what we think , based on Rem 2, has been converted to ANSI, from like StrConv("Alan", vbFromUnicode)
    Let vTemp = StrConv(StrConv(BSTR, vbFromUnicode), vbUnicode) ' "Alan"
    Let ByteArr() = StrConv(StrConv(BSTR, vbFromUnicode), vbUnicode) ' 65 0 108 0 97 0 110 0


    ( ' 1e Before leaving this Rem 1 section, we note, the curious behaviour does give us a useful one line code line to get the characters of a text sting to a 1 dimensional array of those characters, which can help get other interesting approaches to solutions , example https://eileenslounge.com/viewtopic....323516#p323516 https://www.excelfox.com/forum/showt...ge53#post22623 )


    Rem 0 !!! ' ###
    Working backwards from the last two sections, it appears that the assignment of a text string to a Byte array shows us how a VB / VBA string is actually represented internally. It could be regarded as converting from the string to a representation of the Unicode encoding, specifically here, Microsoft’s UTF-16 2 byte LE Unicode encoding.
    ' 0b It is perhaps important here to do an example which includes a large code point.
    Example in the second half and towards the end of the over next post





    Full coding is here
    https://www.excelfox.com/forum/showt...ll=1#post24938
    https://www.excelfox.com/forum/showt...ge19#post24938
    ( Also in code module MikeWombatstrConv in uploaded file )


    Ref
    https://www.eileenslounge.com/viewto...297326#p297326 https://www.eileenslounge.com/viewto...297329#p297329
    https://eileenslounge.com/viewtopic....297332#p297332
    https://eileenslounge.com/viewtopic....297500#p297500
    https://eileenslounge.com/viewtopic....323085#p323085
    Attached Files Attached Files
    Last edited by DocAElstein; 02-20-2025 at 04:03 PM.
    ….If you are my competitor, I will try all I can to beat you. But if I do, I will not belittle you. I will Salute you, because without you, I am nothing.
    If you are my enemy, we will try to kick the fucking shit out of you…..
    Winston Churchill, 1939
    Save your Forum..._
    KILL A MODERATOR!!

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
  •