Link to home
Start Free TrialLog in
Avatar of jtm082698
jtm082698

asked on

Header directive error

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;
}
Avatar of nietod
nietod

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.
If not, what compiler are you using and is there an error number for this error messsage?
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.
For example,
dword SectorsPerCluster,BytesPerSector;
dword NumberOfFreeClusters,TotalNumberOfClusters;

    RetVal = GetDiskFreeSpace(&RootPathName,&SectorsPerCluster,          &BytesPerSector,&lNumberOfFreeClusters,&TotalNumberOfClusters);
Put an extra newline at the end of your .h file.  
Put
#pragma hdrstop
after
#include <windows.h>

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

If you're not using MFC, then don't :-)
ASKER CERTIFIED SOLUTION
Avatar of Bonev
Bonev

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jtm082698

ASKER

That did it.
Thanks everybody.
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. ™