Solved

Header directive error

Posted on 1998-08-26
10
199 Views
Last Modified: 2011-09-20
I keep getting:
     "unexpected end of file while looking for precompiled header directive"

for a cpp I am putting together as a simple GetDiskSpace function. Here's what I put together.....

#include "myfx.h"   (declares the function GetDiskSpace)
#include <direct.h>
#include <windows.h>

double GetDiskSpace(void)
{
 lpctstr lpRootPathName;
 lpdword lpSectorsPerCluster,lpBytesPerSector;
 lpdword lNumberOfFreeClusters,lpTotalNumberOfClusters;
 bool RetVal;
 double FreeSpace;
        
 lpRootPathName = _getdrive();

 RetVal = GetDiskFreeSpace(lpRootPathName,lpSectorsPerCluster,          lpBytesPerSector, lNumberOfFreeClusters, lpTotalNumberOfClusters);

FreeSpace = *lpSectorsPerCluster * *lpBytesPerSector *
               *lpTotalNumberOfClusters;

return FreeSpace;
}
0
Comment
Question by:jtm082698
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1171287
This doesn't sound like a C++ language problem.  This sounds like your complier is having problems with the precompiled header files it manages.  If you do a complete rebuild it may fix the problem.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1171288
If not, what compiler are you using and is there an error number for this error messsage?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1171289
However, you do have a serious problem here (this is a run-time problem so you haven't encountered it yet.)

The GetDiskFreeSpace() procedure must be passed pointers to word variables that you have allocated in some way.  Windows will "fill in" these words using the pointers you pass.  You aren't doing that.  You are allocatign pointers that are not initialized, that is, they don't point to wordes that can be altered, and are passing those pointers.  When windows uses those pointers to change the words they point to, you will crash.
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 22

Expert Comment

by:nietod
ID: 1171290
For example,
dword SectorsPerCluster,BytesPerSector;
dword NumberOfFreeClusters,TotalNumberOfClusters;

    RetVal = GetDiskFreeSpace(&RootPathName,&SectorsPerCluster,          &BytesPerSector,&lNumberOfFreeClusters,&TotalNumberOfClusters);
0
 
LVL 2

Expert Comment

by:duneram
ID: 1171291
Put an extra newline at the end of your .h file.  
0
 
LVL 2

Expert Comment

by:JYoungman
ID: 1171292
Put
#pragma hdrstop
after
#include <windows.h>

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1171293
If you're using MFC then add:
#include "stdafx.h" to the top.

If you're not using MFC, then don't :-)
0
 
LVL 1

Accepted Solution

by:
Bonev earned 50 total points
ID: 1171294
This problem is usually with MS VC++
The error message means that in the project you have a file that uses precompiled headers, but the header used for its creation and use is not at the top of the source file.
To resolve that, open the project settings, pick any source file that compiles ok, switch to the C/C++ tab, select Precompiled Headers category. Look at the Through Header field under Use Precompled Header File (.pch) - this is the header file name that you need to include at the top of your source code. Usually this is "stdafx.h" (look at thresher_shark's comment).
0
 

Author Comment

by:jtm082698
ID: 1171295
That did it.
Thanks everybody.
0
 

Expert Comment

by:busisoft121799
ID: 8040562
I have tested every solution found on this page but nothing works.

First of all this is due to the fact, that you have created the class manually and not with the ClassWizard, thats why you are getting this error.

Since ClassWizard put the precompiled information automatically thats why the error not occured.

Now you are trying to compile this and the compiler spits out the error. The solution is to simply change the option under Project->Settings->C/C++ Tab->Precompiled Headers combo->No using precompiled headers or Automatic use of precompiled headers and leave the Through header empty.
And Rebuild it, the compiler compiles silently.

Thanks.

The Phantom is Tracking Bullets. ™
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C Language combined operators 28 109
C++ Language error 28 214
How to convert MFC::CString to UTF8 wchar_t* 10 200
max float value 3 39
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now