Author Topic: Base64 Encoding/Decoding with Windows, Mac, and Linux  (Read 5729 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Base64 Encoding/Decoding with Windows, Mac, and Linux
« Reply #15 on: November 05, 2020, 02:19:44 pm »
@Dav You might want to modify the message so that the code you are pasting for the win.h is set for C++ or something that way it doesn't fail compilation. Since RETURN is capitalized it fails. The code seems to work in 32 but not in 64. WOW. It's amazing! I've been trying to get that to work forever but I just never could figure out how to make it work!

I’d say the difference in 32 and 64 bit Windows has to do with the packing of the data structures.  32-bit windows data is packed in 4-byte structures; 64-bit data is packed in 8-byte structures.

So, for example, let’s say the win type is something like:

TYPE WinData
       x AS LONG
       y AS LONG
END TYPE

In 32-bit windows, that’ll work just fine.  In 64-bit windows, it’d need to be:

TYPE WinData
    x AS LONG
    padding as LONG ‘4 bytes padding to align to 8-byte structure
    y AS LONG
    padding2 AS LONG ‘4 more bytes padding to align to 8-byte structure
END TYPE

With both, you’re only passing long values back and forth for x and y, but 64-bit windows has that padding so things align as 8-byte structures instead of 4-byte.  (64-bit vs 32-bit)

Now, with that said, here’s the head scratcher part:  From my personal experience, sometimes, it seems that windows will group items together to make those 8 bytes.

TYPE Example
    x AS LONG
    y AS LONG
    z AS LONG
    padding AS LONG
END TYPE

x and y might be packed together, so they don’t need padding, but z would...

Translating 32-bit structures over to 64-bit structures has always been an exercise in trial-and-error and patience for me.  If there’s some secret logic behind what gets grouped together, and what gets padding, I haven’t figured it out yet.  Generally speaking, my knowledge on the packing rules is just enough that I know they’re the problem, but I’m not positive of the solution, so I just try everything over and over, until something sticks.  :P
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Dav

  • Forum Resident
  • Posts: 792
    • View Profile
Re: Base64 Encoding/Decoding with Windows, Mac, and Linux
« Reply #16 on: November 05, 2020, 02:37:22 pm »
Looks like Michael posted an update to this, and amazingly it's still viewable on the old forum...

/forum/index_topic_7038-0]http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index_topic_7038-0

EDIT: Looks like several DECLARE LIBRARY tidbits from the old form are still viewable, for a while....
/forum/index_board_18-0/]http://www.[abandoned, outdated and now likely malicious qb64 dot net website - don’t go there]/forum/index_board_18-0/

And @SpriggsySpriggs , I'm very sorry this stuff hijacked your original topic - I should have posted that code in a new topic. Next time I'll be better...

 - Dav
« Last Edit: November 05, 2020, 03:19:34 pm by Dav »