Thread: using templates

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    161

    using templates

    I have started a win32 simple application. I created a template of a window with a button on it. In the WinMain() function how do I code for the template to apears. I get the error of "base class undeclared" when I include the "frmmain.h" file.

    Thanx in advance!

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    please be more specific
    and post your code if you want

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    I have a dialog with just one button on it.

    Code:
    #include "stdafx.h"
    
    #include "resource.h"
    #include "FrmMain.h"
    
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	CFrmMain d;
    	d.DoModal();
    
    	return 0;
    }
    In the stdafx.h file I have this in it.

    Code:
    #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
    #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    #define VC_EXTRALEAN
    //#define WIN32_LEAN_AND_MEAN		// Exclude rarely-used stuff from Windows headers
    
    //#include <windows.h>
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #include <afxdisp.h>        // MFC Automation classes
    #include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>			// MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    
    
    // TODO: reference additional headers your program requires here
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
    And this is the errors that I get;

    c:\program files\microsoft visual studio\myprojects\test\test2\frmmain.cpp(52) : fatal error C1010: unexpected end of file while looking for precompiled header directive

    Any one know how to fix the problems?

    Thanx in advance!
    Last edited by Benzakhar; 11-23-2003 at 06:07 PM.

  4. #4
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Post Maybe you should ...

    I am thinking you need to "#include" the "stdafx.h" header file to the dialog class's source/header file.

    Code:
    // In CFrmMain.h
    #include "stdafx.h"
    
    ///////////////////////////
    /* Other stuff here */
    ///////////////////////////
    Code:
    // In CFrmMain.cpp
    #include "stdafx.h"
    
    ///////////////////////////
    /* Other stuff here */
    ///////////////////////////
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  5. #5
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    Thanx. I don't know if that is the correct thing to do but after puting that header I get the following errors;
    Code:
    FrmMain.obj : error LNK2005: "public: __thiscall CFrmMain::CFrmMain(class CWnd *)" (??0CFrmMain@@QAE@PAVCWnd@@@Z) already defined in test2.obj
    FrmMain.obj : error LNK2005: "protected: virtual void __thiscall CFrmMain::DoDataExchange(class CDataExchange *)" (?DoDataExchange@CFrmMain@@MAEXPAVCDataExchange@@@Z) already defined in test2.obj
    FrmMain.obj : error LNK2005: "protected: virtual struct AFX_MSGMAP const * __thiscall CFrmMain::GetMessageMap(void)const " (?GetMessageMap@CFrmMain@@MBEPBUAFX_MSGMAP@@XZ) already defined in test2.obj
    FrmMain.obj : error LNK2005: "protected: void __thiscall CFrmMain::OnButtonClick(void)" (?OnButtonClick@CFrmMain@@IAEXXZ) already defined in test2.obj
    FrmMain.obj : error LNK2005: "protected: static struct AFX_MSGMAP const CFrmMain::messageMap" (?messageMap@CFrmMain@@1UAFX_MSGMAP@@B) already defined in test2.obj
    FrmMain.obj : error LNK2005: "private: static struct AFX_MSGMAP_ENTRY const * const CFrmMain::_messageEntries" (?_messageEntries@CFrmMain@@0QBUAFX_MSGMAP_ENTRY@@B) already defined in test2.obj
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    Debug/test2.exe : fatal error LNK1120: 2 unresolved externals

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    as u see youve already defined some stuff
    so you should remove one

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    Thanx. That worked. But then other problems came;

    Code:
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    Debug/test3.exe : fatal error LNK1120: 2 unresolved externals
    How can I fix those errors?

    Thanx in advance!

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Search

    gg

  9. #9
    Registered User
    Join Date
    Nov 2003
    Posts
    161
    Thank you very much! I finaly got it to work. This is the first forum that helped me this much in C++. I have another question. How do I start a class. I know I have to first declare a variable of a class and then create and instance. I think that is how to do it but Im not sure. Could someone please direct me to the correct way to start this?

    Thanx in advance!

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    In my opinion, the correct way to start is with a good book.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates from DLL or static library problem
    By mikahell in forum C++ Programming
    Replies: 2
    Last Post: 01-01-2008, 01:49 AM
  2. Questions about Templates
    By Shamino in forum C++ Programming
    Replies: 4
    Last Post: 12-18-2005, 12:22 AM
  3. templates and inheritance problem
    By kuhnmi in forum C++ Programming
    Replies: 4
    Last Post: 06-14-2004, 02:46 AM
  4. When and when not to use templates
    By *ClownPimp* in forum C++ Programming
    Replies: 7
    Last Post: 07-20-2003, 09:36 AM