Solved

Header directive error

Posted on 1998-08-26
10
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

751 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