The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: elmo on March 27, 2011, 02:16:35 AM

Title: get the content of "application/octet-stream" 'file type
Post by: elmo on March 27, 2011, 02:16:35 AM
I make 1 file in MicrosoftWord2007. Say it file name file1.doc
In file1.doc, I write some string(example: MASM is good ) + I insert 1 picture bmp

In MASM, I use the following code to get the content of file1.doc and show it result on my hRICHEDIT1:


invoke CreateFile,
ADDR szDIR,     ;szDIR contain the directory of file1.doc
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL
mov hFile, eax
invoke GetFileSize,hFile,NULL
mov fsz,eax
.if fsz > 100000000
invoke CloseHandle,hFile
invoke MessageBox,hWin,SADD("Sorry, file is too large"),SADD("info"),MB_OK
xor eax, eax
ret
.endif
invoke SysAllocStringByteLen,0,fsz
mov fmem,eax
;invoke GlobalAlloc,GMEM_FIXED,fsz
;mov fmem,eax
invoke ReadFile,hFile,fmem,fsz,addr ByteRead,NULL
invoke SetWindowText,hEdit1,fmem
invoke SysFreeString,fmem
;invoke GlobalFree,fmem
invoke CloseHandle,hFile



But I get wrong result because in my hRICHEDIT1 appear this:
ÐÏࡱá

So, When I check type of file1.doc with PHP by doing this:
   $FileType = $HTTP_POST_FILES['File']['type'];

I get the type of file1.doc is "application/octet-stream"

The above code only work if the type of file is "plain/text" (file with extension *.TXT, *.PHP, *.ASP, *.ASM, *.INC). But we can only show the string.
I had try the example from \masm32\examples\exampl02\qikpad
It success to show strings from file1.doc in it's RICHEDIT
but fail when show picture from my file1.doc

How to modify the above code?. So, the above code can also show the file who contain a picture in RICHEDIT?
Thank you.

Sorry for my bad english.
Title: Re: get the content of "application/octet-stream" 'file type
Post by: Tedd on March 27, 2011, 11:53:22 AM
I'll guess that you have to decode the octet-stream, inspect it to find out what type of data it is, and then decide how to display it appropriately.
In this case, you'd find a "BMP" signature, and create an OLE object from that, then insert it into the richedit document.
Title: Re: get the content of "application/octet-stream" 'file type
Post by: donkey on March 27, 2011, 12:02:32 PM
The MSO DOC format is not compatible with RichEdit (RTF). For a detailed look at the format see here (http://msdn.microsoft.com/en-us/library/cc313105.aspx)