Re: trouble converting CFileDialog to CFile to get size

From: Ravi Ambros Wallau (nospam_at_nospam.com)
Date: 10/21/04


Date: Thu, 21 Oct 2004 09:34:11 -0300

Wayne:
    Don't be desesperated.
    Here is what I recommend to you:
    Place a breakpoint at the beginning of your method (navigate to the line
and press the F9 key). You should run your application using the F5 key, not
CTRL + F5, because F5 activates the debugger (your project should be in
debugging mode). And then you can check where your error is really
occurring. In C/C++ (as in other languages), a method can call another
method, that call another method, and so on. If one of these inner methods
generates an assertion error (your case), you should check the stack trace
to see where is the error in YOUR code, because this is what matters for
you. You can activate the stack trace in the Debug menu of your development
environment.

    By checking the MSDN help, I found that to use the method
CFileDialog::GetFolderPath, the dialog must be created with the OFN_EXPLORER
style. To do that, your code must look like this:
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
OFN_EXPLORER, NULL, this->m_hWnd, 0);

    But you don't need to use the solution above. Use the method
CFileDialog::GetPathName() to get the complete filename. I'm sure that this
method belongs to the CFileDialog class.
    Everybody had to learn all this someday.

-- 
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:417798ee@212.67.96.135...
>I didnt really want to stick a shed load of what could be extranious info 
>in
> my post but I'lll give you as much as I possibly can.
> Here goes:
>
> build window:
> --------------
>
> ------ Build started: Project: FileSizeTest, Configuration: Debug
> Win32 ------
> Compiling...
> FileSizeTestDlg.cpp
> Linking...
> Build log was saved at "file://c:\Documents and Settings\Tyranus1\My
> Documents\Visual Studio
> Projects\FileSizeTest\FileSizeTest\Debug\BuildLog.htm"
> FileSizeTest - 0 error(s), 0 warning(s)
> -------------------------------------------------------------------
> 1 - soon as I have browsed and hit 'Open' for my file I get:
>
> Debug Assertation Failed!
> Program :: ..dio Projects\FileSizeTest\Debug\FileSizeTest.exe
> File: dlgfile.cpp
> Line 338
>
> If I press retry to debug the app, this is line 338
>
> CString CFileDialog::GetFolderPath() const
> {
> ASSERT(::IsWindow(m_hWnd)); //line 338
> ASSERT(m_ofn.Flags & OFN_EXPLORER);
> CString strResult;
> if (GetParent()->SendMessage(CDM_GETFOLDERPATH, (WPARAM)MAX_PATH,
> (LPARAM)strResult.GetBuffer(MAX_PATH)) < 0)
> strResult.Empty();
> else
> strResult.ReleaseBuffer();
> return strResult;
> }
>
> Then I get :
> Unhandled exception at 0x7c207749 (mfc71d.dll) in FileSizeTest.exe: User
> breakpoint.
> If I continue I get another Debug Assertation Failed this time for
> afxwin2.ini at line 282
> messga eon break: Unhandled exception at 0x7c28f62b (mfc71d.dll) in
> FileSizeTest.exe: User breakpoint
> None of these files have been modified by myself, and ifg I carry on like
> this it does the same thing till I give up.  Also on a side note I have 
> set
> no break points in this app.
>
> I was aware how to use GetFileSize() but it seems my test program isn't! 
> it
> throws back errors to things I know are right.  Yes I do read the MSDN 
> info
> and look up what I use as I learn.  The odd thing is that when I used
> similar code in a console app ther was no problem at all.  Now noticing 
> that
> the exceptions were for mfc71d.dll I have to assume that it's something to
> do with that side of things or memory (this is where I get vauge as I
> haven't learned alot about that yet.....)
> Incedently its a swine learning C++ yourself from home with no help, it's
> not a winge by me just a fact.  I am sort of up against the wall on this 
> as
> I want to get my learning to a stable point before my baby is born next
> may......... at this rate it may be  years..LOL
>
> Wayne...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> "Arnaud Debaene" <adebaene@club-internet.fr> wrote in message
> news:16a4a8c7.0410210026.7f60f62@posting.google.com...
>> "Wayne..." <w.robson@oneteldsl.net> wrote in message
> news:<4176a10c@212.67.96.135>...
>> > OK here's the code I am using and from your description it should work
>> > (using .Net2003 btw)
>> > All it does is give a load of errors but compiles fine!
>>
>> ??? If there are errors, it doesn't compile, period! How on earth do
>> you want us to help you if you don't give some information? What
>> "errors" are you getting? At compile time? At link time? At run time?
>> At least copy and paste the output of the "Build" window so that we
>> can help.
>>
>> > moment I've opened
>> > the file it gives all sorts of errors.
>>
>> What kind of errors?? We can't help if you don't describe your
>> problem!
>>
>> > What am I doing wrong?
>> > Thanks for helping BTW I appreciate it :-)
>> >
>> > Wayne...
>> > P.S. I had to use another method instead of GetFilePath as it complains
> its
>> > not a member of CFileDialog.......
>>
>> It's CFileDialog::GetPathName().  Do you read the doc of the libraries
>> you're trying to use? It is all described in MSDN.
>>
>> >
>> > void CFileSizeTestDlg::OnBnClickedOk()
>> >
>> > {
>> >
>> > CFileDialog dlg(TRUE);
>> >
>> > if(dlg.DoModal() == IDOK) {
>> >
>> >
>> > CString m_filePath;
>> >
>> > m_filePath = dlg.GetFolderPath();
>> >
>> > m_filePath = m_filePath + (dlg.GetFileName());
>>
>> To do it simple :
>> CString m_filePath=dlg.GetPathName();
>>
>> >
>> > HANDLE file;
>> >
>> > file = CreateFile(m_filePath, GENERIC_READ,
>> >
>> > FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
>> >
>> > int size = GetFileSize(file, NULL);
>> >
>> > CloseHandle(file);
>> >
>> > SetDlgItemInt(IDC_EDIT1, size);
>> >
>> > }
>> >
>> > }
>> I suspect your problem was concatening GetFolderPath and GetFileName
>> would have missed the "\" between the last folder and the file name.
>> Otherwise, there is nothing wrong in this code.
>>
>> Arnaud
>> MVP - VC
>
> 


Relevant Pages

  • Re: Saving breakpoints
    ... I once considered to add a breakpoint ... Scheme 1: ... Const DebugNewCustomer As Boolean = True ... ' A compile time constant which is also set during testing ...
    (microsoft.public.vb.general.discussion)
  • Re: Break point persists after all breakpoints have been cleared
    ... VBA sometimes "remembers" a breakpoint even after being cleared. ... Compile the database again. ... the same line BUT only the first time Access encounters the line of code. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Breakpoints cleared but execution stops
    ... I clear all> breakpoints before I compile, save and distribute the new> version. ... Now and then a breakpoint doesn't clear in the> new version. ... The execution stops without any error and> you have to press F5 to continue execution. ... Changing> computer for development or reinstalling Office doesn't> help. ...
    (microsoft.public.access.modulesdaovba)
  • Re: C-programmer needs Forth advice
    ... I have no idea what your "guarantee compile order" ... the clueless programmer would scratch their head and actually *read* the code and understand the conventions being used. ... top of each of the functions that is called, set a breakpoint, and set one at the end. ... Your comment about not having source code and third-party functions also doesn't make sense. ...
    (comp.lang.forth)