Hi

Why this not work ok on win2k, but work ok on win95?
...
mov ofn.lpstrFileTitle,offset FileBuffer
...
invoke GetOpenFileName,addr ofn
invoke SetDlgItemText,hWin,IDC_EDT1,ofn.lpstrFileTitle

Thank you

stanks
Posted on 2002-03-23 04:30:25 by stanks


invoke SetDlgItemText,hWin,IDC_EDT1,ofn.lpstrFileTitle

That's because you trying do display pointer to needed string. Better that way:


invoke SetDlgItemText,hWin,IDC_EDT1,offset FileBuffer
Posted on 2002-03-23 06:50:38 by masquer
Hi masquer

Thank you for reply, but the result is same. Nothing in edit control. I try to change ofn.lpstrFileTitle with ofn.lpstrFile and i then i have the full path with the name of file. I don't understand where is the problem? Again everything work ok on win95.

stanks
Posted on 2002-03-23 07:05:10 by stanks
Post the lines of your code where you fill OPENFILENAME structure. Everything should work.
Run your program under debugger and try to figure what is happen with your strings :)
Posted on 2002-03-23 09:49:01 by masquer
Here's a snippet of code to write the filename of some opened file to an edit box in a dialog. The only difference i really see is that i have defined a maximum length for the file title (which otherwise returns a null if nMaxFileTitle=0).


mov ofn.lpstrFile, OFFSET buffer

mov ofn.nMaxFileTitle,256
...
invoke GetOpenFileName, ADDR ofn
;...code to check for errors & open the file
invoke SetDlgItemText,hWnd,1000,ofn.lpstrFileTitle ;where 1000=my edit control


hope this helps!edit: whoops: above should have been "mov ofn.lpstrFileTitle, OFFSET buffer"
Posted on 2002-03-23 09:54:09 by jademtech
Hi

I use piece of code from Iczelion tut about files (no. 13...i think). Here it is:

.const
MAXSIZE equ 260

.data
FileBuffer byte MAXSIZE dup(0)

.if eax==WM_INITDIALOG
...
mov ofn.lStructSize,SIZEOF ofn
push hWin
pop ofn.hWndOwner
push hInstance
pop ofn.hInstance
mov ofn.lpstrFilter,OFFSET FilterString
mov ofn.lpstrFile,offset FileBuffer
mov ofn.nMaxFile,MAXSIZE

.elseif eax==WM_COMMAND
...
mov ofn.Flags, OFN_FILEMUSTEXIST+OFN_PATHMUSTEXIST+
OFN_EXPLORER+OFN_HIDEREADONLY+
OFN_ALLOWMULTISELECT
invoke GetOpenFileName,addr ofn
invoke SetDlgItemText,hWin,IDC_EDT1,ofn.lpstrFile
...

I try to change IDC_EDT1 in 1002 (ID of my control) but the result is same. When it is lpstrFile it works ok. I have path with full filename, but when i want only filename i have problems. Why?
:confused:

stanks
Posted on 2002-03-23 11:20:31 by stanks
.data
FileBuffer byte MAXSIZE dup(0)
FileTitleBuffer byte MAXSIZE dup(0)
...
mov ofn.lpstrFilter,OFFSET FilterString
mov ofn.lpstrFile,offset FileBuffer
mov ofn.nMaxFile,MAXSIZE
mov ofn.lpstrFileTitle,offset FileBufferTitle
mov ofn.nMaxFileTitle,MAXSIZE

you tried that, right? lpstrFile is not optional; neither is nMaxFile. if you are using lpstrFileTitle, you must also use nMaxFileTitle.
Posted on 2002-03-23 12:53:21 by jademtech
...

1. After GetOpenFileName. Use the CreateFile API to get the handle of the file.
2. Save the handle of the file to memory location. Then use the GetFileSize
3. The value returned in EAX by GetFileSize will be the number of bytes you should allocate.
4. Allocate
5. Use ReadFile to read the contents of the file.
6. One of the parameters you pass when using ReadFile is the buffer/The allocated space.
7. You can then use SetDlgItemText...
8. Close the handle to the file
9. Deallocate memory.

Here's a snippet.



...
invoke CreateFile, OFFSET FName, GENERIC_READ, NULL, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
mov hFile, eax

invoke GetFileSize, eax, NULL
push eax

call GetProcessHeap
mov hPrcs, eax

pop edx
push edx
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, edx
mov hMem, eax

pop edx

;bRead is your buffer

invoke ReadFile, hFile, eax, edx, OFFSET bRead, NULL

;IDE_OUTPUT is the ID of your edit control

invoke SetDlgItemText, hWnd, IDE_OUTPUT, OFFSET hMem

invoke CloseHandle, hFile

invoke HeapFree, hPrcs, NULL, hMem
...
Can't gaurantee accuracy for the code above but this is basically what you should do after GetOpenFileName. :)
Posted on 2002-03-23 14:22:03 by stryker
correct me if i'm wrong, but stanks only wants the title of the file, right? not the contents?
Posted on 2002-03-23 14:37:03 by jademtech
Oh!!

so ofn.lpstrFileTitle,offset FileBufferTitle + other structure data your going to need for the open dialog box will do the trick. ;)
Posted on 2002-03-23 14:49:01 by stryker

correct me if i'm wrong, but stanks only wants the title of the file, right? not the contents?


Hi jademtech

Yes that is true...only the title not the contents. And yes with your help problem is solved. Thank you and thanks to all that reply.

stanks
Posted on 2002-03-23 17:17:37 by stanks