Visual C++ and Precompiled Headers

Top  Previous  Next

When using the DTWAIN C++ classes and Visual C++, you may encounter an error similar to this:

 

fatal error C1010: unexpected end of file while looking for precompiled header directive

 

This is caused by the "use precompiled header" setting in the Visual C++ project.  The solution to this problem is to do one of the following:

 

Turn off precompiled headers. This can be done by going to your project settings, C++ | Precompiled Header option, and selecting that you are not using precompiled headers,

 

-- or if you do not want to turn off the precompiled headers,

 

Include "stdafx.h" by uncommenting a line from the DTWAIN C++ source files.  The files BUFTRANS.CPP, CACQUIRE.CPP, CEXTINFO.CPP and CDTWAIN.CPP contain this comment at the top of each file:

 

// #include "stdafx.h" // Only comment out if using Visual C++ precompiled headers.

 

Change this by uncommenting the line for each of the files specified above.  You should now have the following below.

 

#include "stdafx.h"

 

In addition to the change above:

If you continue to get errors (operator "new" errors, syntax errors, etc.), add the following set of include files the beginning of the stdafx.h file (after the "#pragma once" statement).

 

#pragma once   // This already should appear at the top of the stdafx.h file.

 

#include <math.h>

#include <iostream>

#include <fstream>

#include <algorithm>

#include <fstream>

#include <limits>

#include <map>

#include <string>

#include <vector>

 

 

The reason why the DTWAIN C++ classes cannot have by default #include "stdafx.h" is that the DTWAIN C++ classes can be used by any ANSI compatible C++ compiler, not just Visual C++.  Since "stdafx.h" is an optional file in Visual C++, and this file more than likely does not exist in other compilers, the decision to comment out usage of the "stdafx.h" file was done.