Thread: Assert error when using CFileDialog Constructor

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    11

    Question Assert error when using CFileDialog Constructor

    Hi,

    I have the following line in one of my C++ functions:

    Code:
    CFileDialog fileDlg( FALSE, "prg", "program.prg", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Program (*.prg)|*.prg||", NULL);
    I get the error message as seen in the attached file.

    I include the following files:
    #include "afxwin.h"
    #include "afxdlgs.h"
    #include "atlbase.h"

    and everything compiles and runs fine, except for the fact that I get an assert error when getting to the line using CFileDialog.

    What might be the problem?

    Thanks,
    Torbjørn

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Are you creating the CFileDialog on the stack or heap? It should be created on the heap as all MFC Classes should except for those like CString, because CString does not represend a window in anyway.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    That line of code by itself isn't causing the assertion (thrown by AfxGetResourceHandle()). It has to be caused by something else that happens before you create the file dialog object. At least that's the way it looks to me.

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Did you jump into the debugger ? What did it tell you ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 06-10-2008, 08:38 PM
  2. Customized assert question...
    By Raigne in forum C++ Programming
    Replies: 10
    Last Post: 02-21-2008, 04:28 AM
  3. C++ have a constructor call another constructor
    By QuestionC in forum C++ Programming
    Replies: 4
    Last Post: 05-17-2007, 01:59 AM
  4. Replies: 3
    Last Post: 03-26-2006, 12:59 AM
  5. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 04:50 AM