Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MFC beginner problem

Options
  • 11-04-2006 6:53pm
    #1
    Registered Users Posts: 1,997 ✭✭✭


    I'm trying to mess around with the MFC but having some problems. I've gone to a few tutorial sites but end up with the same problem when I try to compile the code.

    Here's the code I've used
    #include <AFXWIN.H>
    
    class CExerciseApp : public CWinApp
    {
    public:
      virtual BOOL InitInstance();
    };
    
    class CMainFrame : public CFrameWnd
    {
    public:
      CMainFrame();
    };
    
    CMainFrame::CMainFrame()
    {
      Create(NULL, "MFC Fundamentals");
    }
    
    BOOL CExerciseApp::InitInstance()
    {
      m_pMainWnd = new CMainFrame;
      m_pMainWnd->ShowWindow(SW_NORMAL);
    
      return TRUE;
    }
    
    CExerciseApp theApp;
    

    and the error message
    Compiling...
    test.cpp
    WINVER not defined. Defaulting to 0x0502 (Windows Server 2003)
    d:\workspace\c++\visualcpp\mfc3\mfc3\test.cpp(17) : error C2664: 'CFrameWnd::Create' : cannot convert parameter 2 from 'const char [17]' to 'LPCTSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    The tutorials suggested that I go into the project properties and set the "Use of MFC" option to "Use MFC In A Shared DLL" which I did - but no joy :(

    I'm using Visual Studio 2005 on XP

    Any ideas?


Comments

  • Registered Users Posts: 7 Devoy


    I'm trying to mess around with the MFC but having some problems. I've gone to a few tutorial sites but end up with the same problem when I try to compile the code.

    Here's the code I've used
    #include <AFXWIN.H>
    
    class CExerciseApp : public CWinApp
    {
    public:
      virtual BOOL InitInstance();
    };
    
    class CMainFrame : public CFrameWnd
    {
    public:
      CMainFrame();
    };
    
    CMainFrame::CMainFrame()
    {
      Create(NULL, "MFC Fundamentals");
    }
    
    BOOL CExerciseApp::InitInstance()
    {
      m_pMainWnd = new CMainFrame;
      m_pMainWnd->ShowWindow(SW_NORMAL);
    
      return TRUE;
    }
    
    CExerciseApp theApp;
    
    and the error message


    The tutorials suggested that I go into the project properties and set the "Use of MFC" option to "Use MFC In A Shared DLL" which I did - but no joy :(

    I'm using Visual Studio 2005 on XP

    Any ideas?

    It's been a while since I did any MFC stuff but you could try changing:
    Create(NULL, "MFC Fundamentals");
    
    To
    Create(NULL, _T("MFC Fundamentals"));
    
    Or
    Create(NULL, _TEXT("MFC Fundamentals"));
    


  • Registered Users Posts: 1,997 ✭✭✭The_Bullman


    Devoy wrote:
    It's been a while since I did any MFC stuff but you could try changing:
    Create(NULL, "MFC Fundamentals");
    
    To
    Create(NULL, _T("MFC Fundamentals"));
    

    Did that and it worked. Thanks for the help :)

    Now to figure out why that worked :s


  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    The _T and _TEXT Macro converts a string into the unicode character set if its defined by the compiler or code. If it's not defined then the string is left as it is and the macro is stripped just leaving the string.

    The reason that you're getting the error is more than likely because you have unicode defined either in your code or in the compiler. Since the string does not have a _T macro or L outside the quotes it is not converted to a unicode string and the compiler complains.


Advertisement