openfilename

General FreeBASIC programming questions.
paul doe
Moderator
Posts: 1733
Joined: Jul 25, 2017 17:22
Location: Argentina

Re: openfilename

Post by paul doe »

jj2007 wrote:...
Under the hood it becomes clear that there are no nullbytes around. Probably I just have a very old version: FreeBASIC Compiler - Version 1.07.1 (2019-09-27), built for win32 (32bit)
...
Unlikely, since I'm compiling with the same 'official' version (portable), with the 'vanilla' toolchain (GCC 5). Tested with both gcc and gas, 32 and 64-bit, no switches.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: openfilename

Post by jj2007 »

So it remains a mystery why the same code with the same compiler produces different results on different machines.

Btw a Google search for site:freebasic.net string null embedded finds only 329 hits, so it's apparently not a big problem.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: openfilename

Post by VANYA »

VANYA wrote:
jj2007 wrote:So it remains a mystery why the same code with the same compiler produces different results on different machines.
jj2007!

I suspect that you save the file in the UTF-16 encoding, and Paul DoE saves in ASCII. Therefore, you have different results.

If you use UTF-16 encoding, the Type of String also swallows zero characters, which is why your strings merge:

Code: Select all

#define chNull chr( 0 )
#define chNullNull chr( 0, 0 )

Dim filter As string = "Sources" + chNull + "*.bas"
  
for i as Long = 0 to len(filter)
	  ? filter[i] , chr(filter[i])
Next

sleep

Code: Select all

83            S
111           o
117           u
114           r
99            c
101           e
115           s
42            *
46            .
98            b
97            a
115           s
0
Last edited by VANYA on May 08, 2021 17:36, edited 1 time in total.
VANYA
Posts: 1834
Joined: Oct 24, 2010 15:16
Location: Ярославль
Contact:

Re: openfilename

Post by VANYA »

To the PAUL DOE code worked when the file is saved in UTF-16, you can do this:

Code: Select all

#include "Windows.bi"
#Include Once "win\commdlg.bi"

#define chNull chr( 0 )
#define chNullNull chr( 0, 0 )

Dim ofn As OPENFILENAME
Dim buffer As string * MAX_PATH = "testme.bas"
Dim filter As string = _
  str("Sources (*.bas)") + chNull + str("*.bas") + chNull + _
  str("Includes (*.bi)") + chNull + str("*.bi") + chNullNull

with ofn
  .lStructSize=sizeof( OPENFILENAME )
  .hwndOwner=GetForegroundWindow()
  .lpstrFilter=strPtr( filter )
  .lpstrFile=strPtr( buffer )
  .nMaxFile=MAX_PATH
  .lpstrTitle=strptr( "Grab a file" )
  .Flags=OFN_FILEMUSTEXIST or OFN_EXPLORER or OFN_NOCHANGEDIR
  .lpstrDefExt=strPtr( "asm" )
end with

GetOpenFileName( @ofn )
MessageBox( 0, strPtr( buffer ), "Your choice:", MB_OK or MB_SETFOREGROUND )

jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: openfilename

Post by jj2007 »

VANYA wrote:
VANYA wrote:
jj2007 wrote:So it remains a mystery why the same code with the same compiler produces different results on different machines.
jj2007!

I suspect that you save the file in the UTF-16 encoding, and Paul DoE saves in ASCII. Therefore, you have different results.
I checked twice now, and you are right indeed! So if the source is in UTF-16, then FB codes strings a little bit different... they are still ANSI (otherwise GetOpenFileNameA would not work), but string concatenation works a little bit different. Great! Thanks, VANYA, for solving the mystery.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: openfilename

Post by aurelVZAB »

Something is strange to me with this filter ..
it looks similar to what i use in o2 but not work like there
so i will check any member of ofn structure
because what i see in explorer is not proper.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: openfilename

Post by aurelVZAB »

Ok
it looks that i found solution even i am not much used to FB...shame on me!
After i set sizeOf of structure to 76 i got proper FileDialog
and also looks that bitmap file is in explorer
i changed buffer from string to zstring type..

I still dont know how to kill console in background ?? ..it is so annoying ...
Image

Code: Select all

#include "Windows.bi"
#Include Once "win\commdlg.bi"

#define chNull chr( 0 )
#define chNullNull chr( 0, 0 )

Dim ofn As OPENFILENAME
Dim retVal As Long
Dim sep as string : sep = chr(0)
Dim buffer As zstring * 255 
Dim filter As string = "All files "+ sep + "*.*"+ sep + "Bitmap files" + sep + "*.bmp"

with ofn
  .lStructSize= 76     'sizeof( OPENFILENAME )
  .hwndOwner=GetForegroundWindow()
  .hInstance = GetModuleHandle(0)
  .lpstrFilter=strPtr( filter )
  .lpstrFile=strPtr( buffer )
  .nMaxFile= 255
  .lpstrTitle=strptr( "Open file" )
  .Flags=OFN_FILEMUSTEXIST or OFN_EXPLORER or OFN_HIDEREADONLY
  .lpstrDefExt=strPtr( "bmp" )
end with

retval = GetOpenFileName( @ofn ) 
MessageBox( 0, strPtr( buffer ),str(retval) + " Your File:", MB_OK or MB_SETFOREGROUND )
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Re: openfilename

Post by Ed Davis »

aurelVZAB wrote:Ok
I still dont know how to kill console in background ?? ..it is so annoying ...
When you compile, use the "-s gui" option, as in:

fbc -s gui toy.bas

This tells FreeBasic you don't want that annoying console :)
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: openfilename

Post by D.J.Peters »

aurelVZAB wrote:I still dont know how to kill console in background ??
fbc -s gui blabla.bas
(default is -s console)

Joshy
UPS: @Ed Davis was faster :-)
badidea
Posts: 2591
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: openfilename

Post by badidea »

"I still dont know how to kill console in background ?? ..it is so annoying ..."

Are you using Geany as editor? It can be Geany doing that, but I cannot find the option to disable that at the moment. Do you also get the console when you run the program from the file explorer? And see also: Compiler Option: -s

(really too slow)
Last edited by badidea on May 29, 2021 9:26, edited 1 time in total.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: openfilename

Post by aurelVZAB »

Yes
Ed,dj,bad_idea... thanks!

oh ..i forgot to ask Kuan...i am using FB_Poseidon and i don't see that in Options
hmm ...maybe i really need to modify AurelEdit for FreeBasic , once again...

I have in plan to add OpenFile,SaveFile into Bitmap editor program ..i hope that should work!
Post Reply