Qbasicnews.com
April 12, 2021, 06:43:58 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Include binaries...  (Read 7813 times)
fsw
Guru
**
Posts: 251


« on: May 03, 2005, 04:36:27 PM »

Found a little tool that can compile a *.res file into a *.bin file.

Is it possible to include binaries into the exe, and access them?
(not as normal resources...)

If so could somebody provide a little example?

Thanks
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #1 on: May 03, 2005, 06:10:18 PM »

It can be done with resources, but then it becomes Windows-dependent and FindResource/LoadResource will be needed, i never used 'em thought, nor i know how the resource compiler handles raw data.
Logged

fsw
Guru
**
Posts: 251


« Reply #2 on: May 03, 2005, 07:32:48 PM »

Quote from: "v3cz0r"
It can be done with resources, but then it becomes Windows-dependent and FindResource/LoadResource will be needed, i never used 'em thought, nor i know how the resource compiler handles raw data.


Resources are nice, but they can be changed afterwards...

It should be possible to do it without resources, and that's what I'm after...

I'm a "xxxxBasic" fugitive and there is a command called "IncludeBinary".
The IncludeBinary command should be placed into the data section like:
Code:

  Data
    Label1:
    IncludeBinary "MyData.bin" 'could be a image
    Label2:
    IncludeBinary "YourData.bin" ' could be something else
    Label3:
  End Data


Now the data resides between these labels (are LABELS available in FreeBASIC?) and can be accessed through different commands.

------
Example:
If you look at some programs the icons for the toolbar are sitting on the hd as normal files and loaded by start.
But what if the icons are missing?
A program like fbide (the fb version with wx-c.dll) starts without icons and the toolbar buttons are empty.

It would be nice to be able to add binary data into the program and access it if needed.
(without hd write/read)
Logged
rdc
Senior Member
**
Posts: 176



WWW
« Reply #3 on: May 03, 2005, 09:14:00 PM »

I haven't dome this with FB, but I have with Delphi. In one of my programs I append data to the end of the exe with a little utility program I wrote. The utility opens the exe, seeks t the end of the file and then appends data to it. It also adds the offset of the data start and a signature tag.

When the program runs, it opens the exe in Read Only mode, checks for a tag, and if it finds it, loads the offset to the start of the data and reads it in.

It is quite straight forward, and I would think you could do the same thing with FB.
Logged

DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #4 on: May 03, 2005, 11:26:07 PM »

You could also write a little utility to generate DATA statements from the binary file, insert them into your source code, and then READ them at run time.
Logged
fsw
Guru
**
Posts: 251


« Reply #5 on: May 06, 2005, 02:28:52 PM »

Quote from: "DrV"
You could also write a little utility to generate DATA statements from the binary file, insert them into your source code, and then READ them at run time.

This sounds like a good idea  Cheesy
Thanks

Didn't find an example of using data statements with fb, where can I find one?
If you have several data statements, how can you access the right one?

Thanks in advance...
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #6 on: May 06, 2005, 04:17:41 PM »

It would be better to use intialized arrays, ala in C:

Code:
''
'' bin2bas -- usage: bin2bas binaryfile.ext
''

declare function hStripExt( byval filename as string ) as string

dim as string filename
dim as integer filelen

filename = command$(1)

''
''
''
if( open( filename, for binary, access read, as #1 ) <> 0 ) then
print "Error: Binary file not found"
end 1
end if

filename = hStripExt( filename )
filelen = lof( 1 )

if( filelen = 0 ) then
print "Error: Empty file"
end 1
end if

''
''
''
if( open( filename + ".bi", for output, as #2 ) <> 0 ) then
print "Error: Cannot create the inc file"
end 1
end if

print #2, "dim shared " + filename + "_data(0 to " + str$( filelen ) + "-1) as ubyte = { _"

''
''
''
dim as ubyte ub
dim as integer bytes, cnt = 0

bytes = 0
cnt = 0
do while( not eof( 1 ) )

get #1, , ub
bytes += 1

if( cnt > 30 ) then
cnt = 0
print #2, " _"
end if

print #2, "&h" + hex( ub );
cnt += 1

if( bytes < filelen ) then
print #2, ",";
end if
loop

print #2, " }"

close #2

close #1


'':::::
function hStripExt( byval filename as string ) as string static
    dim p as integer, lp as integer

lp = 0
do
p = instr( lp+1, filename, "." )
   if( p = 0 ) then
    exit do
   end if
   lp = p
loop

if( lp > 0 ) then
function = left$( filename, lp-1 )
else
function = filename
end if

end function


An include file will be created, the array will have the same name as in the input file plus a _data suffix.

DATA's are converted to string's, what take a lot of space.. not taking READ into account, that can be quite slow to load..
Logged

fsw
Guru
**
Posts: 251


« Reply #7 on: May 06, 2005, 04:46:15 PM »

Thanks Vic.

Quote from: "v3cz0r"

DATA's are converted to string's, what take a lot of space.. not taking READ into account, that can be quite slow to load..

Ok, scrap this...  :wink:

Quote from: "v3cz0r"

It would be better to use extern's and an intialized array, ala in C, with a small tool to convert binary data to .bas it could be done as:

mybmp.bi:
extern mybmp_data(0 to filelen-1) as ubyte

mybmp.bas
#include mybmp.bi
dim mybmp_data(0 to filelen-1) as ubyte = { ... }

test.bas
#include mybmp.bi

dim mybmp as ubyte ptr = @mybmp_data(0)
...

fbc test.bas mybmp.bas

how is the data from the bmp file loaded and transfered into ?
here?:
Code:

dim mybmp_data(0 to filelen-1) as ubyte = {... hex data of bmp? like: 00, 4D, ...}

hmm, never used EXTERN before...
why is it needed?

Somehow you lost me here :Huh:
Sorry, sometimes I'm a real pain...

Quote from: "v3cz0r"

Btw, the lastest testing version is needed, before 0.14 extern's didn't support static arrays.. testing version can be download from FB's site.

downloaded :wink:

Almost got it  :oops:

EDIT
You are fast  :king:
went away for awhile and searched for examples of extern etc.

and you already coded an example.   :bounce:

Thanks, will look into it...
Logged
fsw
Guru
**
Posts: 251


« Reply #8 on: May 06, 2005, 06:21:38 PM »

Converted as a test the fblogo icon.

Used the "hello" windows gui example and added:
Code:

'...
#include once "fblogo.bi"
'...
'change app icon
dim mybmp as ubyte ptr = @fblogo_data(0)
SendMessage (hWnd, WM_SETICON, NULL, mybmp)
'...

also tried:
Code:

'change app icon
SendMessage (hWnd, WM_SETICON, NULL, @fblogo_data(0))

but the icon doesn't show up...

any thoughts?

BTW: fbc v14 pre-beta used...
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #9 on: May 06, 2005, 09:20:24 PM »

Last SendMessage()'s argument needs a BYVAL, it's declared as AS ANY.. byval @... should do it.
Logged

fsw
Guru
**
Posts: 251


« Reply #10 on: May 07, 2005, 01:05:03 AM »

nope...  :cry:
Logged
v3cz0r
I hold this place together
*****
Posts: 924



WWW
« Reply #11 on: May 07, 2005, 01:39:48 AM »

The Win API is a ..., if i remember the bitmaps had to be converted to DC's and such, but i don't know GDI too much, sorry.
Logged

DrV
Na_th_an
*****
Posts: 1553



WWW
« Reply #12 on: May 07, 2005, 04:34:02 PM »

As per the MSDN documentation (it's actually quite good Smiley ), you need to send an icon handle - not a pointer to the data.  See the CreateIcon function.
Logged
fsw
Guru
**
Posts: 251


« Reply #13 on: May 07, 2005, 06:02:57 PM »

Thank you both.

looked a little deeper and yes, the raw data can't be used, have to use win API.

CreateIcon is used when creating a new empty icon, but in this case we have already the icon data in memory.

Found out a DIB image needs to be created with CreateDIBitmap.
This command is used for bitmaps, icons etc. and takes a memory address with the raw data (well actually a little more...).

Hope to get it going...

...why needs every thing to be so complicated :Huh:
Logged
PeterHarder
New Member

Posts: 23



WWW
« Reply #14 on: May 07, 2005, 07:20:59 PM »

Hallo fsw,

it's easy to show the application-icon:

Code:
~CreateWindow("STATIC", "#1", _
  WS_CHILD Or WS_VISIBLE Or SS_ICON, _
  26, 21, 32, 32, hWnd, 2, App.hInstance, 0)


To add the icon to the application just create a textfile with one line like this:

Code:
IDI_ICON1   ICON    DISCARDABLE     "MyIcon.ico"


Save it as with the Notepade as "*.rc", for example "MyIcon.rc". If you start "fbc.exe", then add the "MyIcon.rc" to the commandline like:

  fbc test.bas -s gui MyIcon.rc

For Icon-Programming-Examples download the api-guide here:

  http://www.mentalis.org/agnet/appdown.shtml

After installing let the programm search for all API-Function that included the word "Icon" and then click in "example" and you'll the how to use it (the examples are in Visual-Basic).

Kind regards from Germany

               Peter
Logged

erman freeBASIC-mailinglist: de.groups.yahoo.com/group/free-basic.
For subscribing send an empty e-mail to free-basic-subscribe@yahoogroups.de.
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!