News:

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

WriteFile using virtual memory buffer

Started by mfprogrammer, January 21, 2007, 03:44:02 PM

Previous topic - Next topic

mfprogrammer

Hello,
  I am new to MASM, trying to come across from the mainframe environment(IBM/zOS HLA). I am learning how to allocate virtual memory, accumulate varied information in the virtual memory and want to write that memory to a file. I have successfull allocated the memory, and believe I have successfully accumulated data in the allocated space, but have been unable to figure out the required syntax to pass the virtual memory address to the WriteFile function.
  I would have to assume that this can be done - I spend a lot of time reading various topics from MSDN Library and have corssed comments that direct you to use buffers allocated in virtual memory.
  I would appriciate any insite into solving this.

Thanks

TNick

Hello, mfprogrammer!

I don't use Virtual functions, so I con't help you there, but I can tell you how I do this:

- create a heap using HeapCreate; this will return a handle to that heap
- allocate memory from this heap using HeapAlloc; this function returns a pointer to a block of memory that has requested size. Let's say you store the returned pointer in pMemory. Fill this block of memory with meaningful infos and then use
INVOKE WriteFile, hFile, pMemory, SizeOfBlock,ADDR ECHOVar,NULL
this will write SizeOfBlock to your file.
- free that block of memory if you see fit, using HeapFree
- When you are done, destroy the heap using HeapDestroy

I usually create the heap before the creating any windows and I call HeapDestroy when my app has exited message loop.

HTH
Nick

mfprogrammer

I guess I should thank TNICK for taking the time to reply to my post. I have been a programmer for over thirty years and when I begin learning a new language, I go through this process of trying to use the various features. So, thank you.

I have already solved my own problem. Too many years as a mainframe programmer makes it difficult to keep MASM's syntax in focus.