DelphiFAQ Home Search:

fatal error C1010 - unexpected end of file while looking for precompiled header directive

 

comments56 comments. Current rating: 4 stars (22 votes). Leave comments and/ or rate it.

Question:

I try to compile a program with Visual C++ .NET (dot-net) which was originally written for the Apple Macintosh for Objective-C. I keep getting the following error message:

"fatal error C1010 - unexpected end of file while looking for precompiled header directive"

I looked into the header file but cannot find anything to be missing.

Answer:

MFC programs use many libraries, requiring the use of many header files. To save time, the compiler tries to precompile most of these header files, and use the predigested data instead of reading through all of these header files on every compilation. There are a number of ways to do this. The standard method for MFC programs is to lump all of these common header file references into one header file ("stdafx.h"). If you just have to ask what "stdafx" means, it comes from the early name of MFC, which was AFX (application framework).

When compiling each source (.cpp) file, the compiler skips through the source code, looking for the directive:

#include "stdafx.h"

Once it finds this directive, it substitutes the precompiled header information and then begins compiling the rest of the file. If your source file doesn't contain this directive, you get the C1010 error described above.

The simple solution is to insert the include directive to your source file, before any other library references or other code.


Content-type: text/html

Comments:

You are on page 2 of 4, other pages: 1 [2] 3 4
2006-09-09, 04:34:22
anonymous from India  
rating
//This code can be used to determine when PDF995 has completed printing. It has not been tested and is not warranted.



#include 'stdafx.


///////////////////////////////////////////////////////////
//Gets the path to the executable.
CString GetPathToSelf()
{

HMODULE hmod = GetModuleHandle(NULL);
char lpszFilename[512];
GetModuleFileName(hmod, lpszFilename, 512);
CString path = lpszFilename;

retupath;
}

/////////////////////////////////////////////////////////////
//Gets the path to the pdf995 folder.
CString GetPdf995Path()
{
HKEY hkey1;
int rc;
CString szpath = 'c:\\';
CString KEYz = 'Software\\Pdf995';
if ((rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, KEYz, 0,
KEY_READ, &hkey1)) == ERROR_SUCCESS)
{
DWORD cbData;
DWORD type1 = REG_DWORD;
//dwlen = 4;

cbData = 10000;
type1 = REG_SZ;
BYTE *buf = new BYTE[cbData];
memset (buf, NULL, cbData);
if (!RegQueryValueEx(hkey1, 'Path', NULL, &type1,
(LPBYTE)buf, &cbData) == ERROR_SUCCESS)
{
delete [] buf;
return szpath;
}

szpath = buf;
delete [] buf;
}
retuszpath;
}
////////////////////////////////////////////////////////////
//This code is run immediately before printing. It tells pdf995 to call GetPathToSelf() + ' deleteflag' when the PDF is complete.

char szprocesspdf[1024];
CString szDefaultProcessPDF;
GetPrivateProfileString(TEXT('Parameters'),TEXT('ProcessPDF'), '', szprocesspdf, sizeof(szprocesspdf), GetPdf995Path() + 'pdf995\\res\\pdf995.ini');
szDefaultProcessPDF = szprocesspdf;
WritePrivateProfileString(TEXT('Parameters'),TEXT('ProcessPDF'), GetPathToSelf() + ' deleteflag', GetPdf995Path() + 'pdf995\\res\\pdf995.ini');

HANDLE hndFlag = CreateFile(GetPdf995Path() + 'pdf995\\flag', GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
CloseHandle(hndFlag);

////////////////////////
///print here
///////////////////////

//This code waits for the flag file to be deleted before proceeding

CFileStatus status;
CString szRoot = GetPdf995Path();
while(CFile::GetStatus( szRoot + 'pdf995\\flag', status ))
{
Sleep(100);
}

///////////////////////////////////////
//The processpdf handler will call an application. The applications should delete the flat file if the parameter is delete flag.

if (cmdln == 'deleteflag')
{
DeleteFile(GetPdf995Path() + 'pdf995\\flag');
return FALSE;
}


C:\Documents and Settings\Administrator\Desktop\prabhakar\pd\pdf995printing.cpp(5) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory


what shold i have to do..when i am going to complile it...pls reply me on....
prabhakar@dewsofindia.com
2006-09-09, 05:11:49
anonymous from India  
i read it and implemt it all but i am not able to compile it..that why
asking u for more suggession...is there any other solution...thanks for
quick reply..
prabhakar
2006-09-21, 01:59:35
anonymous from India  
Hi guys,
I am just learning to use MFC. I was also getting the same problem. But after seeing the discussion here, i thought not not including #include 'stdafx.h' was the problem.But when i include this, 102 errors (syntax errors C2143 and fatal error C1003) were generated.My code is below:

#include 'stdafx.h'
#include<AFXWIN.H>

class CMainwin:public CFrameWnd
{
public:
    CMainWin();
  &nbsDECLARE_MESSAGE_MAP( )
};
CMainWin::CMainWin()
{
Create(NU(NULL,'An MFC program');
}

class CApp:public CWinApp
{
public:
    BOOL InitInstance();
};

BOOL CApp::InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}


BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
END_MESSAGE_MAP()

CApp App;


Can anyone kindly help me out? I couldn't see anything wrong with code.I am using Microsoft Visual c++ 6.0 on Windows XP platform.

Guneshwor
2006-09-21, 02:04:55
anonymous from India  
Oops! Problem with the web.My code was:

#include 'stdafx.h'
#include<AFXWIN.H>

class CMainwin:public CFrameWnd
{
public:
    CMainWin();
    DECLARE_MESSAGE_MAP()
CMainWin::CMainWin()
{
Create(NULL,'An MFC program');
}

class CApp:public CWinApp
{
public:
    BOOL InitInstance();
};

BOOL CApp::InitInstance()
{
m_pMainWnd=new CMainWin;
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}


BEGIN_MESSAGE_MAP(CMainWin,CFrameWnd)
END_MESSAGE_MAP()

CApp App;



Guneshwor
2006-09-26, 02:56:50
anonymous from United Kingdom  
rating
2006-09-26, 03:29:32
anonymous from United Kingdom  
rating
Thanks
2006-09-28, 08:59:10
anonymous from United States  
excellent, by adding '#include 'stdafx.h' resolved my problem. Thanks.
I am wondering though, why can't Microsoft compiler lists the true meaning of the problem rather than display a cryptic compiler error code and leaving us holding the bags...
2006-10-14, 17:47:27
anonymous from United States  
rating
hello. I've just started C++ . I've got the same error but cant figuor out. this is school assiginment and due in a day.. I really need somebody's help. please help me.


/*
Title: ISDS 371 Assignment #1
Due date: 11:55pm,15th October,2006

Discription: - This program is for an insurance company to calculate the
            automobile insurance premiums using functions.
            - Insurance premiums are based on:
                        Type of automobile
                        # of tickets on record within the past 18 months.
Author: Kenny Nishizaki
        Masashi Yanagisawa
Starting date: 10/3/06
Complete on:
*/

# include <iostream>
# include <iomanip>
# include <cctype>


using namespace std;

//function prototype
double basicCharge(char);
double Extracharge(int, double);
int deductibleLevel (void);
int validdeduct(int);
double deductibleAmount (int);
double reduceDeductible (double, int);
char getCarType(void);
int validCar(char);
double getValidNumTicket(void);
double Insurance(double, double);
double Monthly(double, double);

int main()
{
    char carType;
int numTicket;
    double bCharge;
    int dedLevel;
    double adCharge4ded;
double dedAmt;
    double ExCharge;
double INScharge;
    double MONTcharge;
   
    //solution
    char cartype;
    int dLevel;
    int tickt;
    double insurance;
    double value;
    double Exxtra;
    double excharge;
   
   
carType=getCarType();
    numTicket=getValidNumTicket();
bCharge=basicCharge(cartype);
    dedLevel=deductibleLevel();
    adCharge4ded=reduceDeductible (insurance, dLevel);
    dedAmt=deductibleAmount(dLevel);
ExCharge=Extracharge(tickt, value);
    MONTcharge=Monthly(Insurance, Exxtra);
    INScharge=Insurance(value, excharge);


return 0;
}//end main

//function: Valid Vehicle Type

char getCarType(void)
{
    char cartype;
    cout<<'Type of Car:';
    cin>>cartype;
    cartype=toupper(cartype);
    while(!validCar(cartype))
    {
        cout<<'Invalid Car Type'<<endl;
        cout<<'Type of Car:';
    cin>>cartype;
    cartype=toupper(cartype);
}//end while
    return cartype;
}//end cartype


int validCar(char type)
{
    int valid;
    switch(type)
    {
    case 'P': case 'S': case 'T': case 'V': case 'Z':
        {
        valid=1;
        }
        break;
    default:
        {
            valid=0;
        }
        break;
    }//end switch
    return valid;
}//end function 'validCar'

// function: basic charge
double basicCharge(char cartype)
{
    double value;
    switch(cartype)
    {
        case 'P':
            {
                value=50.00;
            }
            break;
        case 'S':
            {
                value=75.00;
            }
            break;
        case 'T':
            {
                value=100.00;
            }
            break;
        case 'V':
            {
                value=120.00;
            }
            break;
        default: //not 'P','S','T'or'V'
            {
                cout<<'Invalit car type. Please enter the car type again.';
            }
            break;
    }//end switch
    return value;
}//end function 'basicCharge'



//Insurance Charge
double Insurance(double value, double excharge)
{
    return value+excharge;
}

//Monthly Charge
double Monthly(double Insurance, double Exxtra)
{
    return Insurance+Exxtra;
}




double Extracharge(int tickt, double value)
{    
    double excharge;
    cout<<'How many tickets do you have?';
    cin>>tickt;
    if (tickt=1)
    {
        excharge=.10*value;
    }
    else if (tickt=2)
    {
        excharge=.15*value;
    }
    else if (tickt>=3)
    {
        excharge=.40*value;
    }
    else
    {
        cout<<'invalid number'<<endl;
    }

    return excharge;
}//end function 'Extracharge'


//function: valid deductible level

int validdeduct(int dLevel)
{
    return (dLevel>0 && dLevel<=4);
}

int deductibleLevel ()
{ int dLevel;
cout<<'what is the deductible level?';
cin>>dLevel;
while(!validdeduct(dLevel))
{
    cout<<'Not a deductibe level'<<endl;
    cout<<'what is the deductible level?';
cin>>dLevel;
}
        return dLevel;
}//end function 'deductibleLevel'



//function: Deductible Amount
double deductibleAmount (int dLevel)
{
    double dAmt; //deductible amount
    switch (dLevel)
    {
        case '1':
            {
            dAmt=1000;
            cout<<'Deductible amout: $'<<dAmt;
            }
            break;
        case '2':
            {
                dAmt=750;
                cout<<'Deductible amout: $'<<dAmt;
            }
            break;
        case '3':
            {
                dAmt=500;
                cout<<'Deductible amout: $'<<dAmt;
            }
            break;
        case '4':
            {
                dAmt=250;
                cout<<'Deductible amout: $'<<dAmt;
            }
            break;
        default:
            {
                cout<<'Deductible amount not defined'<<endl;
            }
    }//end switch

return dAmt;
}//end function 'deductibleAmount'


//function: Adtl deductibele charge
double reduceDeductible (double insurance, int dLevel)
{
double Exxtra;
    if (dLevel=1)
    { Exxtra= insurance*0.0;
    }
    else if (dLevel=2)
    { Exxtra= insurance*0.5;
    }
    else if (dLevel=3)
    { Exxtra= insurance*0.10;
    }
else if (dLevel=4)
    { Exxtra= insurance*0.20;
    }
else
{
    cout<<'wrong Deductibe level'<<endl;
}
return Exxtra;
}// end if loop -- end function 'reduceDeductible'







double getValidNumTicket (void)
{
    int numTicket;
    cout<<'Number of tickets: ';
    cin>>numTicket;
    while (numTicket=0 || numTicket<0)
    {
        cout<<'Invalid input. Please try again.'<<endl;
    }
    return numTicket;
}//end function: 'getValidNumTicket'
2006-12-19, 00:54:21
rammohan@india.com from United States  
rating
Hi,
The above problem doesn't fix with adding .h file.
This problem is related with the settings not any other...
Just Follow as like this and definelty it will fix your problem...

How to Fixing the problem

Steps are given below just carefully do the following:

There are two ways to get rid of the error, depending on the file you are trying to compile:

The direct solution is to add the include directive to your source file, before any other library references or other code. This solution is appropriate when the module you are compiling needs to make use of MFC classes (e.g., CString).
If your module is 'pure' C++ code (for example, your own 'Date' class), with no need to reference MFC at all, then you may prefer not to add the 'stdafx.h' include directive. In this case, you can change the project settings to inform MSVC that you are not making use of the precompiled header files. Here's how to do it:
From the Project menu, select Settings ....
Make sure the Settings for selection reflects the project you are building. By default, this will likely be 'Win32 Debug'.
Expand the Source Files folder in the list on the left, and click once on the source file that you don't want to use precompiled headers.
On the right, select the C/C++ tab.
In the Category combo box, select Precompiled headers.
Select the Not using precompiled headers option.
Repeat for any other files for which you wish to disable precompiled headers (but not for any files created by the Developer Studio AppWizard).
Click OK to close the project settings dialog.
2007-02-24, 13:44:02
anonymous from India  
hi get an error like
FrameWnd' : base class undefined
E:\visual\a7\aa.cpp(13) : error C2504: 'CWinApp' : base class undefined
Error executing cl.exe.

how so solve it
guide me
2007-02-27, 12:36:21
anonymous from Barbados  
rating
EXCELLENT!!! I was trying for so long to get rid of that retarded error. MSDN was telling me stuff about /Yu that i couldn't understand. It had me frustrated the entire day. Thanks a lot guy.
2007-02-27, 12:36:54   (updated: 2007-02-27, 12:39:15)
anonymous from Barbados  
rating
2007-03-23, 05:00:22
anonymous  
rating
bored
2007-04-17, 09:43:18
anonymous from Malaysia  
solution from RAMMOHAN worked
bow to u dude thx so much
2007-04-25, 15:01:21
anonymous from Dayton in Ohio, United States  
Thanks a lot Ram, for your solution.
It hardly took a minute to resolve this, once I applied your suggestions.
You are on page 2 of 4, other pages: 1 [2] 3 4

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: