C2065 Error

M

Mike C#

Hi all,

Running into a little problem. I wrote a small app on VC++ 7.1 that calls
the GetDefaultPrinter() function. Now I have to "downgrade" it to VC++ 6,
but every time I compile I get the following error:

--------------------Configuration: enumprinters - Win32
Debug--------------------
Compiling...
CPrinters.cpp
C:\Store_BN_2\INSTORE\Bnutils\bin\enumprinters\CPrinters.cpp(67) : error
C2065: 'GetDefaultPrinter' : undeclared identifier
Error executing cl.exe.

enumprinters.dll - 1 error(s), 0 warning(s)

I'm including windows.h, winspool.h and have a #pragma comment(lib,
"Winspool.lib") line as well. Anyone have any ideas what else I should try?
Thanks.
 
M

Mike C#

BTW, the app compiles and runs fine on VC++ 7.1, but won't compile on VC++
6. I might not have made that clear before. Thanks
 
W

William DePalo [MVP VC++]

Mike C# said:
--------------------Configuration: enumprinters - Win32
Debug--------------------
Compiling...
CPrinters.cpp
C:\Store_BN_2\INSTORE\Bnutils\bin\enumprinters\CPrinters.cpp(67) : error
C2065: 'GetDefaultPrinter' : undeclared identifier
Error executing cl.exe.

enumprinters.dll - 1 error(s), 0 warning(s)

I'm including windows.h, winspool.h and have a #pragma comment(lib,
"Winspool.lib") line as well.

Look at the help entry for the function. It says that the function is
declared in <winspool.h> but that you should include <windows.>. It also
says that the function was introduced with 2K. So you should define the
version of NT that you target

#define _WIN32_WINNT 0x0500

either in the source as above or in the IDE.

If you are doing the compilation on an old box, it may be that it has stale
SDK headers and libraries. If that's the case, you may need to update the
Platform SDK there and point the IDE at the SDK's headers and libraries
rather than its own.

Regards,
Will
 
M

Mike C#

I'm already including <windows.h> and <winspool.h>. I'll add the #define
and see if the results are any better. I'm trying to compile it on the same
box where I have both VC++ 6 and VC++ 7.1. The code compiles and runs fine
on 7.1, but not on 6. Can I point my VC++ 6 source to use the 7.1 include
directories? I thought there would probably be some compatibility issues
there.

Thanks
 
W

William DePalo [MVP VC++]

Mike C# said:
I'm already including <windows.h> and <winspool.h>.

Go here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_0hma.asp

scroll down to take a look at the requirements section. If the docs say
I'll add the #define and see if the results are any better.

In case you don't know, there is nothing really special about
GetDefaultPrinter(). Unlike the case with the .Net platform where in effect
several versions of the platform exist on the same box, there is only one
copy of Windows on a system. Further, unlike .Net, a single tool can target
multiple platforms. That being the case, you have to tell your tools what
platform to target. VS6, because it was released earlier than 2K, can't
possibly make the definition of platform on its own where your copy of 7.1,
released later, just may be doing that.
I'm trying to compile it on the same box where I have both VC++ 6 and VC++
7.1. The code compiles and runs fine on 7.1, but not on 6. Can I point
my VC++ 6 source to use the 7.1 include directories?

No. Carl Daniel and others have posted here at length on the differences
between the libraries for various versions of the compiler. I can't believe
anything good can come of mixing and matching the C and C++ headers.

On the other hand, I would install the most recent Platform SDK on the box
and then adjust both IDEs do that each uses the same includes and libraries.
As I understand it, there are some corner cases where the PSDK is
incompatible with the old compiler. I'm not sure what they are. I think that
they have to do with things I rarely use like graphics or something. I might
be wrong.

You are welcome.

Regards,
Will
 
M

Mike C#

I'll eliminate the #include <winspool.h>, but I don't think that will fix
the issue as I've already tried it. I tried to install the Platform SDK but
received an error during installation that some of the files could not be
found during installation. I'll try again tomorrow and hope I have more
success.

Thanks.
 
W

William DePalo [MVP VC++]

Mike C# said:
I'll eliminate the #include <winspool.h>, but I don't think that will fix
the issue as I've already tried it.

I won't. You need

1) to add the #define so that the compiler knows that you target 2K and
later
2) to install the PSDK headers released after 2K, VC6's predate 2K

Regards,
Will
 
?

=?iso-8859-1?Q?Kim=20Gr=e4sman?=

Hi Will,
2) to install the PSDK headers released after 2K, VC6's predate 2K

The latest platform SDK to support VC6 is the one released in February, 2003.
I'm not sure how to get it anymore, though, casual googling didn't turn up
any links.
I still have it on disc, but I don't know about downloads.
 
M

Mike C#

Had to download the PSDK in pieces, but finally got it installed. Now it
compiles correctly (without the #define), but I'm encountering a new and
unrelated LNK1561 error when I try to add this particular project to another
project and compile. <Growl/>.

Thanks
 
M

Mike C#

Follow-up: Finally got it all working. It turns out the Platform SDK also
incorporates buffer overrun detection and I had to reference the
bufferoverflowU.lib library to get everything working in the end. Lawd I
can't wait until we move completely away from VC++ 6! :)

Thanks all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top