News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GetFileSize

Started by shankle, April 27, 2015, 02:22:26 AM

Previous topic - Next topic

shankle

In this program I key in data that creates a file in memory.
This program also needs to use the scrolling function.
GetFileSize does not work with a memory file because
the  "type" is not known for a memory file.
GetFileType does not solve the problem for me as I can
not fill out the 1st parameter as I do not know what it is.
Any suggestions would be appreciated.

jj2007

How do you "create a file in memory"?

fearless

You could use memory mapped files, but you would still need to know what size your dealing with.

If your creating the data, and allocating a block of memory for it, and writing to that block, then you would need to know this anyhow.

Really depends on how your creating the data, the file and what your doing with it before someone could give a best practice scenario on how to go about doing whatever.

In the past for handling memory mapped files, i created my own data structure and stored all relevant data, hMapFile, pMapFile, SizeFile, OpenMode etc etc. this data i use as a "handle" to my file in my own functions, where i can retrieve the various info if needed. Maybe post some code so we can understand the context.

shankle

#3
        4-26-2015

The keyed input can be from 5 to 99
I assume you know what atodw/dwtoa is

BufAdd           dq  0
HeapH            dq  0  ; heap handle
MemoryFileSize   dq  0  ; input1 x 40
PtrMem           dq  0  ; pointer to memory
input2            dq  0  ; in hex

input1  db '  ',0
tmsg1   db 'value after Heap',0
tvalue  db '   ',0

    LOCAL scr:SCROLLINFO

    lea ecx,input1      ; keyed input - decimal
    invoke atodw,ecx    ; decimal string to DWORD(now in Hex)
    xor rdx,rdx
    mov rcx,10
    mul rcx
    mov [input2],rax    ; value in hex
                        ; controls screen listing
; -------------------------
;        Set vertical scroll bar range & page size
    mov D[scr.cbSize],sizeof scr
    mov D[scr.nMin],3
    mov eax,[input2]
    mov [scr.nMax],eax
    mov D[scr.fMask],(SIF_RANGE or SIF_PAGE)
    mov D[scr.nPage],30   ; Load # of visible lines of text
    mov rax,[input2]   ; # input2 x 40 for memory size
    mov rcx,40
    mul rcx
    mov [MemoryFileSize],rax
   invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS,[MemoryFileSize],0
   mov [HeapH],rax
   invoke HeapAlloc, [HeapH],HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,\
           [MemoryFileSize]
    mov [PtrMem],rax
;      -----------------------------

   
; test code begin - I added this to try and see if the scroll features
; would work and they didn't.
; The Add 1 line and the Subtract 1 line worked but nothing else.
    mov rax,[MemoryFileSize]
    mov [HeapH],rax
    invoke GetFileSize, [HeapH],NULL
    xor rdx,rdx
    mov rcx,40
    div rcx
    mov rcx,rax                 ; # records in memory
    lea rbx,input2
    mov [BufAdd],rbx
    invoke dwtoa, rcx,[BufAdd]  ; Hex DD to string
                                ;output is in tvalue
    invoke MessageBox, [hWnd],addr tmsg1,addr tvalue,MB_OK ;true
; test code end

I hope this makes sense.
Thanks guys.....
   

dedndave

well - it's 64-bit code, so i can't be too much help - lol

however, a couple points....

1) when you start a process (program), the OS assigns a "default heap"
no need to create one, just use GetProcessHeap and store that handle for future use

2) the handle returned is HHEAP - it's not a file
you cannot "get the size" of the heap, as if it was a file

3) if i wanted to get the size of a file, i would use GetFileAttributesEx

sinsi

Does goasm treat these two lines the same?

    mov eax,[input 2]
    mov eax,[input2]


Tá fuinneoga a haon déag níos fearr :biggrin:

shankle

It's a typo that I missed. sorry

shankle

Problem has been solved.
Thanks everyone