Author Topic: Referencing the GetOpenFileName Wiki Example...  (Read 670 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Referencing the GetOpenFileName Wiki Example...
« on: May 14, 2020, 09:32:25 am »
So the other day I was browsing the forum, hoping to find someone with a solution for how to use GetOpenFileNameA or SaveFileNameA in a 64 bit QB64 program. I had no such luck. I had seen where some people offered suggestions about making some of the declarations _INTEGER64 or LONG but nothing I did worked. I saw where @SierraKen had made an inquiry about it back in August of last year, I think, and he had the same issue I did as with all of the examples. No 64 bit compatibility. I wasn't about to tackle ALL of the examples but I, too, had been irked about not being able to have an open or save dialog in a 64 bit program. Not that it was a major issue, since 32 bit works on a 64 bit machine, but it still bugged me. So, I pulled out ol' reliable.... PowerShell. I used it before for making my custom message boxes and my date picker. I worked on making up two PowerShell scripts that are called in the command line from SHELL and can use a custom title, start directory, and filter... Just like how GetOpenFileNameA and SaveFileNameA did.....without having to have all those constants and TYPE declarations. Just a simple function to build a SHELL command that could call the script with the custom data you entered. I had a heck of a time getting the custom filter and start directory to work. I have made a Github with the 64 bit functions (they also work in 32bit because PowerShell is the same either way but I put them in an $IF 32BIT block so you can use the native 32 bit dialog in the 32 bit IDE).
Here is the link to my Github repository for the functions:
https://github.com/SpriggsySpriggs/Open-Savex64

A couple of screenshots to show the dialogs in action:
 
qb64 open file demo.png

 
qb64 save file demo.png

And here is the bundle. Either download here or from my link:
 
« Last Edit: May 14, 2020, 09:34:18 am by SpriggsySpriggs »
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Referencing the GetOpenFileName Wiki Example...
« Reply #1 on: May 14, 2020, 01:03:50 pm »
The issue is with Windows data packing, and the difference in 32-bit file structures and 64-bit file structures.

This is for 32-bit:

TYPE FILEDIALOGTYPE
  lStructSize AS LONG '        For the DLL call
  hwndOwner AS LONG '          Dialog will hide behind window when not set correctly
  hInstance AS LONG '          Handle to a module that contains a dialog box template.
  lpstrFilter AS _OFFSET '     Pointer of the string of file filters
  lpstrCustFilter AS _OFFSET
  nMaxCustFilter AS LONG
  nFilterIndex AS LONG '       One based starting filter index to use when dialog is called
  lpstrFile AS _OFFSET '       String full of 0's for the selected file name
  nMaxFile AS LONG '           Maximum length of the string stuffed with 0's minus 1
  lpstrFileTitle AS _OFFSET '  Same as lpstrFile
  nMaxFileTitle AS LONG '      Same as nMaxFile
  lpstrInitialDir AS _OFFSET ' Starting directory
  lpstrTitle AS _OFFSET '      Dialog title
  flags AS LONG '              Dialog flags
  nFileOffset AS INTEGER '     Zero-based offset from path beginning to file name string pointed to by lpstrFile
  nFileExtension AS INTEGER '  Zero-based offset from path beginning to file extension string pointed to by lpstrFile.
  lpstrDefExt AS _OFFSET '     Default/selected file extension
  lCustData AS LONG
  lpfnHook AS LONG
  lpTemplateName AS _OFFSET
END TYPE

Notice that several of these elements are being transfered as LONG variable types:

  lStructSize AS LONG '        For the DLL call
  hwndOwner AS LONG '          Dialog will hide behind window when not set correctly
  hInstance AS LONG '          Handle to a module that contains a dialog box template.

For 64-bit Windows, all these handles would need to be_INTEGER64 before they could possibly work.

And since data is packed in 8-byte fields usually, you may need to add some Filler to the data structure.  For example, let's say I have a data structure like this:

TYPE Example Structure
     X AS LONG
     Y AS _INTEGER64
END TYPE

In 32-bit, data is packed in 4-byte fields generally, for Window's API Functions, so it's fine as written.

In 64-bit, data is generally packed in 8-byte fields, so your structure would need to become:

TYPE Example Structure
     X AS LONG
     Filler AS LONG '4 bytes of nothing but space so data fields align properly.
     Y AS _INTEGER64
END TYPE



I ran into this same issue with the windows Printer Selection routines, and talked about the issue here, previously: https://www.qb64.org/forum/index.php?topic=1859.msg110961#msg110961
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Referencing the GetOpenFileName Wiki Example...
« Reply #2 on: May 14, 2020, 01:08:17 pm »
I'm wondering how QB64 does cross platform, separate instructions for each OS?

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: Referencing the GetOpenFileName Wiki Example...
« Reply #3 on: May 14, 2020, 02:29:21 pm »
I've tried about everything.... Looking through old VB forums and trying your suggestions here but nothing is working for doing this in 64 bit. There must be more to it than just making LONGs be _INTEGER64s and adding a filler/padding. Sometimes it crashes and closes the program, other times it just doesn't call up the dialog but fails more "gracefully".
Shuwatch!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • Steve’s QB64 Archive Forum
Re: Referencing the GetOpenFileName Wiki Example...
« Reply #4 on: May 14, 2020, 02:36:18 pm »
My PC died, and the new one I ordered won't be here for another week, or so.  Once I get it, I'll see if I can sort out what's needed for the 64-bit usage. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • GitHub
Re: Referencing the GetOpenFileName Wiki Example...
« Reply #5 on: May 14, 2020, 02:39:42 pm »
You're awesome, man. It's been something I've been fighting since I found the Windows Libraries page on the Wiki, haha. I've been also looking into a 64 bit MYSQL option as well. Perhaps after all this coronavirus stuff is over I can focus more since I'll have my desk back and be living in my house rather than a hotel.
Shuwatch!