?
Solved

Header directive error

Posted on 1998-08-26
10
Medium Priority
?
204 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 200 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

718 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