News:

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

embedded file export

Started by timertik, March 31, 2007, 04:08:29 AM

Previous topic - Next topic

timertik

I need to have a text file embedded in my app and when user presses a button it is exported to the current folder

I know this can be done and think i need to add hex values of the file into .data and use WriteFile api

but i cant  figure this one out I have done it before and it was simple but i cant seem to figure it out this time

can someone lead me in the right direction or show me an example?

ramguru

with poasm this would be very simple:

.data
ptr_file: ; use this as param to WriteFile
INCBIN res\my_file.txt

with masm it's just simple:
1) generate data with bintodb.exe tool included in masm32 then copy it to your app .data section
2) define your file as resource, then .. FindResource -> LoadResource -> LockResource

Vortex

timertik,

To embed your text file in the main application, you can convert it to a linkable MS COFF object module :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib

EXTERN pText:PTR BYTE

SIZE_OF_TEXT_FILE = 53

.data
msg         db 'Hit OK to save the text file',0
capt        db 'Extractor',0
filename    db 'text1.txt',0

.data?
hOutput     dd ?
size1       dd ?

.code

start:

    invoke  MessageBox,0,ADDR msg,ADDR capt,MB_OK
    invoke CreateFile,ADDR filename,GENERIC_WRITE,\
            0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,0
    mov     hOutput,eax
    invoke  WriteFile,eax,ADDR pText,SIZE_OF_TEXT_FILE,ADDR size1,0
    invoke  CloseHandle,hOutput
    invoke  ExitProcess,0

END start

[attachment deleted by admin]

timertik

thanks I knew it was something simple, you guys have really helped me alot!  :U

I found that a mixture of both methods works best for me  :wink

oh and to the author of bintodb , this tool is amazing great idea
i was doing it manualy before on other projects   :P

im gonna have a closer look at the examples now especially the ones in the main folder