locked
How to solve "Invalid Argument was encountered" Exception in VC++

    Question

  • Hi,

    I am migrating my VC++ 6.0 Application to Visual Studio 2005 for windows 7.Successfully i have migrated my application to Visual studio 2005 without any errors. But It throws an Exception Message box " Invalid Argument was encountered" while loading the application.Otherwise the application is working fine.The messagebox pops up everytime while opening the application.I have googled and tried out a lot of methods to identify the problem.But I can't be able to figure out the problem.I got the below message in output window while debugging,

    First-chance exception at 0x7589d36f in User Security Policy.exe: Microsoft C++ exception: CInvalidArgException at memory location 0x0012ed50..



    Is there any way to suppress the message box???

    Regards, Eshwar

    Monday, October 29, 2012 6:21 AM

Answers

  • You have commented control variable entry in your code at the same time you are used the same variable in OnInitDialog(). See corrected code below

    void CStartUpScreen::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStartUpScreen)

    DDX_Control(pDX, IDC_EDIT1, m_message);

    //}}AFX_DATA_MAP } BOOL CStartUpScreen::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_message.SetWindowText("Please wait while loading..."); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

    Thanks, Renjith V R



    Thursday, November 01, 2012 12:45 PM

All replies

  • I do not understand your question. Have you tried to debug your application and find out what the reason of the exception is?

    There are so many reasons for an exception after converting. VC6.0 and VC2005 are in some points very different. From the exception it seems one argument in an function is not valid. you should debug your application and see where this exception occurs.

    Monday, October 29, 2012 12:06 PM
  • Debugger points out the below line from "C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\crtexe.c" #ifdef WPRFLAG mainret = wWinMain( #else /* WPRFLAG */ mainret = WinMain( #endif /* WPRFLAG */ (HINSTANCE)&__ImageBase, NULL, lpszCommandLine, StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT ); #else /* _WINMAIN_ */

    Regards, Eshwar

    Monday, October 29, 2012 12:46 PM
  • Debugger points out the below line from "C:\Program Files\Microsoft Visual Studio 8\VC\crt\src\crtexe.c" #ifdef WPRFLAG mainret = wWinMain( #else /* WPRFLAG */ mainret = WinMain( #endif /* WPRFLAG */ (HINSTANCE)&__ImageBase, NULL, lpszCommandLine, StartupInfo.dwFlags & STARTF_USESHOWWINDOW ? StartupInfo.wShowWindow : SW_SHOWDEFAULT ); #else /* _WINMAIN_ */

    Regards, Eshwar

    This location is in CRT code. You should find the exception occurring location in your code. This can be done checking callstack.

    Thanks, Renjith V R

    Monday, October 29, 2012 2:06 PM
  • Call Stack shows only disassembly code.How to figure out the problem from that?

    Regards, Eshwar

    Tuesday, October 30, 2012 9:11 AM
  • Try debug version or enable Debug info in release. For this you can follow below steps

    1.Go Project->Properties->Configuration Properties->C++->Optimization :Disabled

    2. Go Project->Properties->Configuration Properties->Linker->Debugging->Generate Debug Info:Yes

    3. Rebuild solution.

    Then Start Debugging again


    Thanks, Renjith V R

    Tuesday, October 30, 2012 6:03 PM
  • I found the code that is causing the exception but i don't know why it's throwing the exception.

    In my Application i have created a startupscreen as a part of my app and loads it at application startup.

    In Mainframe.cpp:

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 

    {

    CStartUpScreen *m_startupscreen = new CStartUpScreen(this);

     m_startupscreen->Create(IDD_STARTUP_SCREEN); // "Invalid argument was encountered"                                                                                                          exception thrown from here.

    ..............

    ..............

    IDD_STARTUP_SCREEN is the dialog that i have created to load as a startup screen.I put break Point over there and found that,

    it calls the CDialog::Create function afxwin.inl and returns the exception.

    afxwin2.inl:

    _AFXWIN_INLINE BOOL CDialog::Create(UINT nIDTemplate, CWnd* pParentWnd)
    { return CDialog::Create(ATL_MAKEINTRESOURCE(nIDTemplate), pParentWnd); }

    Please help me to get rid of this problem....


    Regards, Eshwar

    Wednesday, October 31, 2012 7:13 AM
  • Refer below code

    CDialog* pStartUpScreen = new CDialog();
        pStartUpScreen->Create( IDD_DIALOG1,this);
        pStartUpScreen->ShowWindow(SW_SHOW);


    Thanks, Renjith V R

    Wednesday, October 31, 2012 11:25 AM
  • Instead of calling CDialog directly, I have created my own class CStartUpScreen derived from CDialog,

    I have added code StartUpScreen.h below,

    StartUpScreen.h:

    class CStartUpScreen : public CDialog
    {
    // Construction
    public:
    	CStartUpScreen(CWnd* pParent = NULL);   // standard constructor
    
    // Dialog Data
    	//{{AFX_DATA(CStartUpScreen)
    	enum { IDD = IDD_STARTUP_SCREEN };
    	CEdit	m_message;
    	//}}AFX_DATA
    
    
    // Overrides
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CStartUpScreen)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    	//}}AFX_VIRTUAL
    
    // Implementation
    protected:
    
    	// Generated message map functions
    	//{{AFX_MSG(CStartUpScreen)
    	virtual BOOL OnInitDialog();
    	afx_msg void OnPaint();
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STARTUPSCREEN_H__623147AA_545F_48E8_9CE0_65FC8C8E9854__INCLUDED_)
    

    StartUpScreen.cpp:

    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CStartUpScreen dialog
        
    
    CStartUpScreen::CStartUpScreen(CWnd* pParent /*=NULL*/)
    	: CDialog(CStartUpScreen::IDD, pParent)
    {
    	
    	//{{AFX_DATA_INIT(CStartUpScreen)
    	//}}AFX_DATA_INIT
    }
    
    
    void CStartUpScreen::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CStartUpScreen)
    //	DDX_Control(pDX, IDC_EDIT1, m_message);
    	//}}AFX_DATA_MAP
    }
    
    
    BEGIN_MESSAGE_MAP(CStartUpScreen, CDialog)
    	//{{AFX_MSG_MAP(CStartUpScreen)
    	ON_WM_PAINT()
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CStartUpScreen message handlers
    
    BOOL CStartUpScreen::OnInitDialog() 
    {
    	
    
    	CDialog::OnInitDialog();
    	
    	// TODO: Add extra initialization here
    	m_message.SetWindowText("Please wait while loading...");
    	return TRUE;  // return TRUE unless you set the focus to a control
    	              // EXCEPTION: OCX Property Pages should return FALSE
    }
    
    void CStartUpScreen::OnPaint() 
    {
    	
    	CPaintDC dc(this); // device context for painting
    	
    	// TODO: Add your message handler code here
    	
    	// Do not call CDialog::OnPaint() for painting messages
    }
    


    Then I am calling the startupscreen in MainFrame.cpp,

    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    
    CStartUpScreen *m_startupscreen = new CStartUpScreen(this);
    
     m_startupscreen->Create(CStartUpScreen::IDD,this); //"Invalid argument was encountered"                                                                                                          exception thrown from here.
    
    ..............
    
    ..............
    
    } 

    I don't know why it's throwing exception.?????



    Regards, Eshwar

    Thursday, November 01, 2012 6:36 AM
  • You have commented control variable entry in your code at the same time you are used the same variable in OnInitDialog(). See corrected code below

    void CStartUpScreen::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CStartUpScreen)

    DDX_Control(pDX, IDC_EDIT1, m_message);

    //}}AFX_DATA_MAP } BOOL CStartUpScreen::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_message.SetWindowText("Please wait while loading..."); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

    Thanks, Renjith V R



    Thursday, November 01, 2012 12:45 PM
  • Thanks a lot.. Now it's Working Fine...

    Regards, Eshwar

    Friday, November 02, 2012 4:47 AM