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,lpByte sPerSector ;
lpdword lNumberOfFreeClusters,lpTo talNumberO fClusters;
bool RetVal;
double FreeSpace;
lpRootPathName = _getdrive();
RetVal = GetDiskFreeSpace(lpRootPat hName,lpSe ctorsPerCl uster, lpBytesPerSector, lNumberOfFreeClusters, lpTotalNumberOfClusters);
FreeSpace = *lpSectorsPerCluster * *lpBytesPerSector *
*lpTotalNumberOfClusters;
return FreeSpace;
}
"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,lpByte
lpdword lNumberOfFreeClusters,lpTo
bool RetVal;
double FreeSpace;
lpRootPathName = _getdrive();
RetVal = GetDiskFreeSpace(lpRootPat
FreeSpace = *lpSectorsPerCluster * *lpBytesPerSector *
*lpTotalNumberOfClusters;
return FreeSpace;
}
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.
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,BytesPer Sector;
dword NumberOfFreeClusters,Total NumberOfCl usters;
RetVal = GetDiskFreeSpace(&RootPath Name,&Sect orsPerClus ter, &BytesPerSector,&lNumberOf FreeCluste rs,&TotalN umberOfClu sters);
dword SectorsPerCluster,BytesPer
dword NumberOfFreeClusters,Total
RetVal = GetDiskFreeSpace(&RootPath
Put an extra newline at the end of your .h file.
Put
#pragma hdrstop
after
#include <windows.h>
#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 :-)
#include "stdafx.h" to the top.
If you're not using MFC, then don't :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That did it.
Thanks everybody.
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. ™
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. ™