Re: trouble converting CFileDialog to CFile to get size
From: Ravi Ambros Wallau (nospam_at_nospam.com)
Date: 10/20/04
- Next message: David Lowndes: "Re: Browsing local variables does not work..."
- Previous message: Bonj: "Windows authentication on SQL server"
- In reply to: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Next in thread: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Reply: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 20 Oct 2004 08:19:29 -0300
It's really not a member of CFileDialog.
GetFileSize is a Windows API in the global namespace (GetFileSize and
::GetFileSize are the same thing).
You should get the file name using the method CFileDialog::GetFilePath, open
this file using the API CreateFile and, using the handle returned by this
method, call the API GetFileSize to get file size. After all this process,
you must make a call to CloseHandle, passing as parameter the handle
returned when you first call CreateFile.
It's really pretty simple.
CFileDialog is a class with only one purpose: give you an easy way to
determine which file(s) the user wants to open or save. That's all - it does
not implement any stuff to open the file or get it's size.
--
Ravi Ambros Wallau
r w a l l a u @ s p r i n g w i r e l e s s . n e t
"Wayne..." <w.robson@oneteldsl.net> wrote in message
news:4175911d@212.67.96.135...
>
>> GetFileSize works on a handle of some opened file - you should open
> this
>> file using the CreateFile API. I don't know how to get the file size in a
>> closed one. Use the method CFileDialog::GetPathName() to get the complete
>> name of the file.
>> CreateFile isn't scarring as it looks.
>>
>> CFileDialog dlg(TRUE);
>> if(dlg.DoModal() == IDOK) {
>>
>> HANDLE file = CreateFile(dlg.GetFilePath(), GENERIC_READ,
>> FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
>> DWORD size = GetFileSize(file, NULL);
>> CloseHandle(file);
>> }
>>
>> Pretty simple.
>
> I created a new project [as well as testing on the current one] to test
> this
> and it gives the following:-
>
> errorC2039: 'GetFileSize' : is not a member of 'CFileDialog'
>
> Which basically encapsulates the whole problem I've been having with
> GetFileSize.
>
> Wayne...
>
>
- Next message: David Lowndes: "Re: Browsing local variables does not work..."
- Previous message: Bonj: "Windows authentication on SQL server"
- In reply to: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Next in thread: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Reply: Wayne...: "Re: trouble converting CFileDialog to CFile to get size"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|