Assert error when using CFileDialog Constructor

This is a discussion on Assert error when using CFileDialog Constructor within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have the following line in one of my C++ functions: Code: CFileDialog fileDlg( FALSE, "prg", "program.prg", OFN_HIDEREADONLY | ...

  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
    Attached Images Attached Images  

  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,138
    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, 03: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-25-2006, 11:59 PM
  5. Need help in classes
    By LBY in forum C++ Programming
    Replies: 11
    Last Post: 11-26-2004, 03:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21