News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Standalone exe

Started by nelsson, April 09, 2006, 12:51:52 AM

Previous topic - Next topic

nelsson

Just looked at the great examples of openGL in this forum.
Can anyone tell me how to modify the code in for example Alpha_Blend_Texture so
that the bmp is included in the exe file after compiling it ?

Mark Jones

Hello Nelsson, one way to do this might be to include the file as a resource of type RT_FILEDATA. Then in the code, write the resource out to a temporary file at runtime. This will work, but it's not terribly efficient (and bloats the executable.) Here is some code to do this with a midi file:

Quote from: rsrc.rc
MIDI_FILE   RT_FILEDATA   DISCARDABLE   "Res\\turk.mid"


GetMIDIHandle Proc                                    ; get handle of MIDI resource
    Invoke FindResource, App.Instance, MIDI_FILE, RT_FILEDATA ; locate midi resource
    Mov hMIDIres, Eax                                 ; store location in hMIDIres var
    Invoke SizeofResource, App.Instance, hMIDIres     ; how big is the midi resource?
    Mov hMIDISize, Eax                                ; save size
    Invoke LoadResource, App.Instance, hMIDIres       ; load resource, valid handle in EAX
    Invoke LockResource, Eax                          ; lock resource
    Mov hMIDIres, Eax                                 ; save good handle
    Ret
GetMIDIHandle EndP

MakeMIDIfile Proc                  ; output midi file from internal raw data resource
    Local fhandle1:DWord
    Local numchar:DWord

    Invoke GetTempPath, MAX_PATH, Addr path           ; get the temporary folder path
szText tempfile, "\~tmp.mid"                          ; name of our temporary file to create
    Invoke lstrcat, Addr path, Addr tempfile          ; append our filename to the path
    Invoke CreateFile, Addr path, GENERIC_WRITE, FILE_SHARE_WRITE, 0, \
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
    Mov fhandle1, Eax                                 ; save EAX, our file handle
    Invoke WriteFile, fhandle1, hMIDIres, hMIDISize, Addr numchar, 0      ; write midi file
    Invoke CloseHandle, fhandle1                      ; close our file
    Ret
MakeMIDIfile EndP
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

hitchhikr

You'll have to modify the function Load_File located in Common_Src/Files.asm
it should return a pointer to the location of the file in memory, change the code so that it loads from a resource instead of a file.

Another possibility is to create a .obj containing the data files and using their labels as memory pointers, nasm is handy for such stuff because it provides the incbin directive which must be used that way:


global _IDR_MYDATAS
_IDR_MYDATAS: incbin "pathnameandfilenamegohere"


Use:

nasmw.exe -f win32 "data.asm" -o "datas.obj" -s -O9

to create a win32 obj file that you can link with the main program's obj.

Just use something like:


externdef IDR_MYDATAS:dword

lea esi, [IDR_MYDATAS]


to retrieve the address of the datas.

Vortex

Hi nelsson,

Welcome on board.

You can easily display embedded bitmaps in your executable.

Displaying bitmaps from memory :

http://www.masmforum.com/simple/index.php?topic=2802.0