Re: CFileDialog drives me insane. Handle Problem ?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Mon, 13 Nov 2006 07:39:13 -0500
That seems remarkably silly. Why not just pass folderPath directly? All you did was a
complicated way of saying
CString fileUrl = folderPath;
and that accomploishes practically nothing
*****
On 13 Nov 2006 02:54:33 -0800, "dawjdh@xxxxxxxxxxxxxx" <dawjdh@xxxxxxxxxxxxxx> wrote:
Oh, Sorry:****
CString fileUrl;
fileUrl.Format("%s",folderPath);
I try'd several way's to get the fileSize:
/* #### Variante 1 ####*/
long GetFileSizeInByte(char *fileName){
ULONGLONG GetFileizeInByte(LPCTSTR filename)
Two serious errors and you haven't even started to write the code!
****
****
long sz = -1;
ULONGLONG, not long!
****
FILE* f;****
f = fopen (fileName, "rb");
if (f)
{
fseek (f, 0, SEEK_END);
sz = ftell (f);
fclose (f);
}
So it appears that if the file is not found, its length is 0xFFFFFFFF, which is something
over 4.2 gigabytes? Really? Why does this make sense?
****
****
return sz;
}
/* #### Variante 2 ####*/
long GetFileSizeInByte(const char* sFileName){
ULONGLONG GetFileSizeInByte(LPCTSTR filename)
Why do you ignore the actual specification of a file length and insist on throwing away
half the value, thus guaranteeing the code is erroneous?
*****
****
std::ifstream f;
f.open(sFileName, std::ios_base::binary | std::ios_base::in);
if (f.eof()) { return 0; }
//if (!f.good()) { return -1; }
if (!f.is_open()) { return -2; }
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
f.seekg(0, std::ios_base::end);
return static_cast<long>(f.tellg() - begin_pos);
See my previous crtique. Exceptionally poor coding style, produces an incorrect result,
and does it in a needlessly complex way.
****
****
}
/* #### Variante 3 ####*/
long GetFileSizeInByte( const char * szFileName )
ULONGLONG GetFileSizeInByte(LPCTSTR filename)
****
{****
struct __stat64 fileStat;
int err = _stat64( szFileName, &fileStat );
if (0 != err) return 0;
return (long)fileStat.st_size;
It was correct up to the point where you, for reasons that cannot possibly make sense,
throw away half the bits of the length!
****
}*****
/* #### Variante 4 ####*/
long GetFileSizeInByte( const char * szFileName )
ULONGLONG GetFileSizeInByte(LPCTSTR filename)
*****
{****
struct stat fileStat;
Uses the obsolete 32-bit version, so nothing can salvage this code
****
int err = stat( szFileName, &fileStat );****
if (0 != err) return 0;
AfxMessageBox(fileStat.st_size);
return (long)fileStat.st_size;
}
Thats all ok, the Problem is the FileOpenDialog, when i do
GetFileSizeInByte( const char * szFileName ) with a static parameter it
works in all Variants but not if i first call that Dialog.
No, it fails because you have used GetBuffer erroneously. See my earlier comments. There
is nothing wrong with CFileDialog, but you made so many errors in handling the strings
that it is amazing that you have ONLY these few problems!
****
Joseph M. Newcomer [MVP]
Why not just use the GetFileSize API?
So why would you recommend me to use the GetFileSize API instead of
other's ?
best Regards,
David
David Lowndes schrieb:
1. Problem:
CFileDialog FileDlg(true);
INT_PTR nResponse = FileDlg.DoModal();
if (nResponse == IDOK){}else{return;}
LPSTR file = FileDlg.GetFileName().GetBuffer();
LPSTR folderPath = FileDlg.GetPathName().GetBuffer();
ULONGLONG fSize = GetFileSizeInByte(fileUrl.GetBuffer());
What is fileURL ?
long GetFileSizeInByte(const char* sFileName)
Why not just use the GetFileSize API?
Dave
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: CFileDialog drives me insane. Handle Problem ?
- From: dawjdh@xxxxxxxxxxxxxx
- Re: CFileDialog drives me insane. Handle Problem ?
- References:
- CFileDialog drives me insane. Handle Problem ?
- From: dawjdh@xxxxxxxxxxxxxx
- Re: CFileDialog drives me insane. Handle Problem ?
- From: David Lowndes
- Re: CFileDialog drives me insane. Handle Problem ?
- From: dawjdh@xxxxxxxxxxxxxx
- CFileDialog drives me insane. Handle Problem ?
- Prev by Date: Re: Change style Problem in CEdit
- Next by Date: Re: CFileDialog drives me insane. Handle Problem ?
- Previous by thread: Re: CFileDialog drives me insane. Handle Problem ?
- Next by thread: Re: CFileDialog drives me insane. Handle Problem ?
- Index(es):