The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: rkwill on February 13, 2007, 06:12:10 PM

Title: how to extract bytes from arrays and print those bytes to disk files
Post by: rkwill on February 13, 2007, 06:12:10 PM
I have a problem, where I need to extract bytes from an array and then print those bytes to a disk file.
A simple operation of

mov wcnt, fwrite(hout,pdata,flen)

if the output were to be in the same order as the input.
As it is, specific bytes are to be extracted and written, byte by byte, to the disk file.

How do I do this in masm32?

Richard
Title: Re: how to extract bytes from arrays and print those bytes to disk files
Post by: dsouza123 on February 13, 2007, 11:50:45 PM
Use
invoke CreateFile, with various parameters
invoke WriteFile, with various parameters

There are many examples of these two functions in the example code that comes with MASM32.
Also if you have a copy of the file Win32.hlp, available for download at various sites,
lookup the functions for an explanation of all the parameters.

A snippet from the file writdisk.asm from the M32LIB directory:

invoke CreateFile,lpName,GENERIC_WRITE,NULL,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL

invoke WriteFile,hOutput,lpData,fl,ADDR bw,NULL

The CREATE_ALWAYS can be replaced with OPEN_ALWAYS.
Title: Re: how to extract bytes from arrays and print those bytes to disk files
Post by: MichaelW on February 14, 2007, 02:05:18 PM
This could be done byte by byte, but it would be easier to extract the bytes and store them in a buffer, and then write the buffer to the output file.