Solved

Header directive error

Posted on 1998-08-26
10
198 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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.
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.

911 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

21 Experts available now in Live!

Get 1:1 Help Now