I've been trying to achieve this for several hours now but it don't work :( I want a dynamic buffer to recieve the filenames from GetOpenFileName so that I can select alot of files. The ofn structure flags are set to OFN_ENABLEHOOK + some more. That part is working OK, the thing is that I can't select any files if their length is above the original ofn.nMaxFile-value (here 32). This is what I have tried:




.data
ofn OPENFILENAME <sizeof OPENFILENAME,0,400000h,NULL,0,0,0,NULL,\
256,0,0,0,0,\
OFN_ENABLEHOOK or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_ALLOWMULTISELECT or OFN_FILEMUSTEXIST or OFN_EXPLORER or OFN_HIDEREADONLY,\
0,0,0,0,offset OFNHookProc,0>

...


invoke HeapCreate,HEAP_NO_SERIALIZE,0,0
mov hHeapen,eax
invoke HeapAlloc,hHeapen,HEAP_ZERO_MEMORY or HEAP_NO_SERIALIZE,32
mov lpHeapPointer,eax
mov ofn.lpstrFile, eax
mov hHeapSize,32
mov ofn.nMaxFile, 32
invoke GetOpenFileName,offset ofn

...
OFNHookProc PROC hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hh:HANDLE

.if uMsg==WM_NOTIFY
mov eax,lParam


.if [eax].NMHDR.code==CDN_SELCHANGE
invoke GetParent,hWin
mov hh,eax
invoke SendMessage,hh,CDM_GETSPEC,0,0
push eax
invoke SendMessage,hh,CDM_GETFOLDERPATH,0,0
pop ecx
add eax,ecx

.if eax>=hHeapSize


inc eax
mov hHeapSize,eax
mov ofn.nMaxFile,eax
invoke HeapReAlloc,hHeapen,HEAP_REALLOC_IN_PLACE_ONLY or HEAP_ZERO_MEMORY or HEAP_NO_SERIALIZE,lpHeapPointer,eax
; mov lpHeapPointer,eax

.endif

.endif


.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
OFNHookProc endp

Posted on 2003-06-15 09:13:38 by Delight
Are you sure the problem is nMaxFile? Then,

nMaxFile

Specifies the size, in bytes (ANSI version) or characters (Unicode version), of the buffer pointed to by lpstrFile. The GetOpenFileName and GetSaveFileName functions return FALSE if the buffer is too small to contain the file information. The buffer should be at least 256 characters long.
Posted on 2003-06-15 16:49:39 by cakmak
When calling GetOpenFileName, you must allocate a a memory enough to hold the files selected. If you expect that you need to have 1 kb for the files that user will select, then allocate such memory for lpstrFile and specify this also in nMaxFile.

Hope it will help you
Posted on 2003-06-15 21:18:43 by rxbagain
CakMak: Yep, it returns FALSE :(

rxbagain: That is what I did before, but what if the user selects 2000 files? That would require a very large buffer. That's why I'm trying to have a dynamic buffer. I've found an example that does what I'm trying to do but it's in C++ and I don't understand that language, so if anyone could translate parts of it to ASM, I would be very happy:

here is the link: http://www.codeproject.com/dialog/PJA_MultiSelect.asp
Posted on 2003-06-16 04:36:39 by Delight
I'm not sure that you can select that big a buffer anyway, I always thought that the maximum size of the buffer was fixed at 65535 bytes (0FFFFh) because the returned buffer size is limited to 2 byte :
If the buffer is too small, the function returns FALSE and the CommDlgExtendedError function returns FNERR_BUFFERTOOSMALL. In this case, the first two bytes of the lpstrFile buffer contain the required size, in bytes or characters.
Posted on 2003-06-16 04:48:50 by donkey