Menu

How to create Binary Files

2004-05-18
2012-09-26
  • Nobody/Anonymous

    Hi

    I'm not using Dev-C++ so long, but i need to create .bin Files. Can somebody help me ?

     
    • Wayne Keen

      Wayne Keen - 2004-05-18

      Please do not re-post messages.  They do not appear instantly - be patient.

      Wayne

       
    • Nobody/Anonymous

      fopen ("my_file.bin", "wb");

      But seriously, you question is rather vague.

      Is your issue with basic file operations?

      There are a few ways to deal with it:

      (1) io streams (the preferred C++ way) - causes an initial big hit in executable size though

      (2) standard C file operations found in <stdio.h>: fopen(), fread(), fwrite(), etc

      (3) Windows WIN32API file I/O functions.

      Personally, I always stick with the standard C file operations (because I am very long in the tooth).

      rr

       
    • Wayne Keen

      Wayne Keen - 2004-05-18

      In the older days, a .bin file was an executable file...

      Wayne

       
      • Nobody/Anonymous

        Hi

        I don't meant how to write .bin files in a source code. I meant how can specifiy a .bin files as output not .exe or .dll

         
    • Nobody/Anonymous

      Hi!
      Well, from my point of view every file is binary after all...

      upCASE

       
    • Anonymous

      Anonymous - 2004-05-19

      "I meant how can specifiy a .bin files as output not .exe or .dll"

      What would you expect this .bin file to contain?

      You can override the output file name via Project|Project options...|Build options. However while the name may change, it would still be an exe or a dll. This is probably only useful for screen savers (.scr) and control panel applets (.cpl) that are specialised executables. The other area it may be useful is if you are using a cross-compiler for an embedded system, where you may indeed creat a .bin file, but the default MinGW compiler knows only how to make Win32 executables, so there is no real benefit in changing the extension, it would render it non-executable!

      Clifford.

       
    • Anonymous

      Anonymous - 2004-05-19

      If registered me.
      So the Mingw just knows the basic PE-File Format ?
      Is there another linker which can compile to .bin (it is the older PE-File as Wayne Keen said) ?

       
    • Kip

      Kip - 2004-05-19

      I think he means flat binary output. A com file is an example of a flat binary output. A bootsector is also another example.

      This is tricky and I am too lazy to look in my VOS makefile. lol

      Kip

       
    • Anonymous

      Anonymous - 2004-05-19

      What are you going to execute such a file on? Windows would not understand it. I don't recall .bin being a recognised executable file extension in any version of DOS or Windows

      .COM files are specific to 16bit DOS. They are non-relocatable executables of less that 64Kb code+data (tiny model), and run at a specific address in memory, and therfore need no relocation information, so are simple binaries as Kip said. MinGW32 does not support that, it is a Win32 compiler.

      I think you would get much further if you explained exactly what you wanted, how you expect to use it, and why.

      Nice to see you registered, welcome sourceharvester.

      Clifford.

       
    • Kip

      Kip - 2004-05-19

      MinGW does support it. You just have to tinker with the linker and pass a million switches. Most people don't know about it because most have no need for it.

      ld -o program.o thing1.o thing2.o thing3.o
      objcopy -R .note -R .comment -S -O binary program.o program.bin

      Kip

       
      • Anonymous

        Anonymous - 2004-05-20

        I understand objcopy, because I use it all the time for embedded systems. But it still begs the question of what can you do with the resultant file?

        This would be the way to generate a bootloader for an operating system.

        I wish he'd just tell us what he was doing so we could stop guessing and help him.

        Clifford.

         
    • Nobody/Anonymous

      Well, as you have probably noticed, my forum philosophy is very different. I like to give people exactly what they ask for, if I can, and let them do as they please with it. But perhaps having him give us more details may be advantageous.

      Kip

       
    • Anonymous

      Anonymous - 2004-05-20

      Ok.....I'll be more precious:

      Kip Warner is right. The Boot.bin File is written to the first Sector of a Floppy Disk. It calls the File Kernel.bin. It's my first Low-Level Project. It's name is Lynx. But where should I put this command line? As i mentioned above I'm really new at Dev-C++. I used Visual Studio 7.0 before

      MFG
      Source-Harvester

       
    • Nobody/Anonymous

      This type of thing is a little too sophisticated for Dev to handle. I would place this in your own custom makefile and just use dev as a text editor. Is Kernel.bin in the adjacent sector (relative sector 2) or is the disk fat12 formatted?

      Kip

       
    • Nobody/Anonymous

      lol, I almost forgot...

      You cannot write the bootsector in C / C++. Well, you can try, but it will not fit. Remember, the BIOS will only load the first sector off the disk. That means the entire thing must be a total of 512 bytes (including bootsector signature at the end). There is too many details that you must be in control of, such as the bootrecord offsets, etc. You should do it in nasm.

      Kip

       
    • Anonymous

      Anonymous - 2004-05-20

      The File System is FAT

       
    • Anonymous

      Anonymous - 2004-05-20

      Arghhh.....I forgot to tell. The Boot.bin is written in Assembler and compiled with NASM

       
    • Nobody/Anonymous

      VOS... vision of speed?

       
    • Nobody/Anonymous

      VOS: Vertigo Operating System.

      Can I see your bootsector code? I am having difficulty loading my kernel. The FAT12 code is very tricky.

      Kip

       
    • Anonymous

      Anonymous - 2004-05-21

      Now it is more clear. I just wanted to be sure we ern't wasting our time assisting someone to do something either impossible or best done another way - your initial post was not very enligntening.

      Kip seems to have all the answers and more experience, the only bootstrap code I have written is for custom diskless systems booting from ROM. I'll leave you in his capable hands.

      Be aware Source-Harvester that there is already an OS called Lynx (http://www.lynuxworks.com/rtos/lynxos.php3) - you may want to change the name to avoid confusion.

      Clifford.

       
    • Kip

      Kip - 2004-05-21

      Thanks Clifford,

      I assure you, I am as incompetent as they come. I just know a few arcane little facts here and there from my efforts with VOS.

      Kip

       
    • Anonymous

      Anonymous - 2004-05-21

      Thanks Guys. *grml* Why me ??? All great names I use for projects are used by licensed other *grml*.

      Kip:
      I'm currently still working on the Bootsector Code but as soon as it is possible i'll show you the code

       
    • Kip

      Kip - 2004-05-22

      Awesome. Thanks.

      Kip

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.