CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Posts
    112

    How to add .h and .cpp files to MFC project?

    I'm using VC++6 and I've created MFC dialog,and now I want to add functionallity.

    I have 3 classes already made,but cant add them to project and compile.

    I've added files in file view and included .h files in stdafx.h and here is what I get:

    Code:
    #if !defined(AFX_STDAFX_H__6BF529B9_3795_4AE3_9A72_3FADC2FA5C53__INCLUDED_)
    #define AFX_STDAFX_H__6BF529B9_3795_4AE3_9A72_3FADC2FA5C53__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    
    #define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
    
    #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
    
    //========================================
    
    #include <Main.h> // I INCLUDED 3 HEADERS HERE
    #include <Mail.h>
    #include <Mail1.h>
    
    //========================================
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_STDAFX_H__6BF529B9_3795_4AE3_9A72_3FADC2FA5C53__INCLUDED_)

    here's the error:

    Code:
    fatal error C1083: Cannot open include file: 'Main.h': No such file or directory
    I copied .h and .cpp files in project directory.

  2. #2
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: How to add .h and .cpp files to MFC project?

    Code:
    #include <>
    is for system files... for your own files you need to use
    Code:
    #include ""

  3. #3
    Join Date
    Feb 2010
    Posts
    112

    Re: How to add .h and .cpp files to MFC project?

    Thank you!

    I have win32 project with 3 classes and winmain() func

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)


    and I want to add functionality of those classes to MFC app for which I made dialog GUI.

    How should I do it?

    I see there is a lot of redefinitions like windows.h etc...

  4. #4
    Join Date
    Dec 2008
    Posts
    144

    Re: How to add .h and .cpp files to MFC project?

    Why do you actually want to add your own WinMain into the MFC application?

  5. #5
    Join Date
    Feb 2010
    Posts
    112

    Re: How to add .h and .cpp files to MFC project?

    No I dont want to ad winmain() to MFC app.

    I already have win32 console app source made of 3 classes.

    And now I created MFC dialog app with GUI but no functionality.

    And I want now to add those 3 classes functionality to MFC app.

    here are the errors I get now:

    Code:
    
    #ifndef _MAIL_H_
    #define _MAIL_H_
    
    //#include <fstream>
    //#include <iostream>
    //#include <winsock2.h>
    
    
    //using namespace std;
    
    const int VERSION_MAJOR = 1;
    const int VERSION_MINOR = 1;
    
    #define CRLF "\r\n"
    
    #pragma comment(lib, "ws2_32.lib")
    //#pragma once
    
    class Mail
    {
    public:
      Mail(void);
      ~Mail(void);
    
      bool Send(char* smtpServerName, char* recvrAddr, char* senderAddr, 
    
    char* fileName, char* user, char* password);
    
    private:
      bool Check(int iStatus, char *szFunction);
    
      int protocolPort;
      char buffer[4096];
      char line[255];
      char msgLine[255];
      SOCKET      hServer;                           // HERE FIRST ERROR
      WSADATA     wsaData;
      LPHOSTENT   lpHostEntry;
      LPSERVENT   lpServEntry;
      SOCKADDR_IN sockAddr;
    };
    
    #endif


    Code:
    microsoft visual studio\myprojects\m1\mail.h(39) : error C2501: 'SOCKET' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(39) : error C2501: 'hServer' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(40) : error C2146: syntax error : missing ';' before identifier 'wsaData'
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(40) : error C2501: 'WSADATA' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(40) : error C2501: 'wsaData' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(41) : error C2146: syntax error : missing ';' before identifier 'lpHostEntry'
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(41) : error C2501: 'LPHOSTENT' : missing storage-class or type specifiers
    c:\program files\microsoft visual studio\myprojects\m1\mail.h(41) : error C2501: 'lpHostEntry' : missing storage-class or type specifiers

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to add .h and .cpp files to MFC project?

    You've got your include for "winsock2.h" commented out.

  7. #7
    Join Date
    Feb 2010
    Posts
    112

    Re: How to add .h and .cpp files to MFC project?

    No you aren't right,I tried that and than it says "WINDOWS.H already included. MFC apps must not #include <windows.h>"
    Last edited by suncica2222; June 9th, 2010 at 09:42 AM.

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to add .h and .cpp files to MFC project?

    You need a definition for SOCKET. Try adding it to the end of stdafx.h. If you create a MFC app with the wizard and select socket support, you'll get this line in stdafx.h:
    Code:
    #include <afxsock.h>            // MFC socket extensions
    Maybe try that first.

  9. #9
    Join Date
    Feb 2010
    Posts
    112

    Re: How to add .h and .cpp files to MFC project?

    #include <afxsock.h> I've tried this,nothing changes,completely the same.

    And that wizard option is in VC++2008,and Im using VC++6


    here's my Mail.h:

    Code:
    #ifndef _MAIL_H_
    #define _MAIL_H_
    
    #include <fstream>
    #include <iostream>
    //#include <winsock2.h>
    
    
    using namespace std;
    
    const int VERSION_MAJOR = 1;
    const int VERSION_MINOR = 1;
    
    #define CRLF "\r\n"
    
    #pragma comment(lib, "ws2_32.lib")
    #pragma once
    Last edited by suncica2222; June 9th, 2010 at 11:39 AM.

  10. #10
    Join Date
    Feb 2005
    Posts
    2,160

    Re: How to add .h and .cpp files to MFC project?

    It's been 8 years since I used VC6 so I'm afraid you're on your own.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured