MinnisotaFreezing
Programmer
Hi all,
I am learning to program Windows using Charles Petzolds book Programming Windows Fifth Edition, and so far, so good. However, he writes all of his programs in C, and I want to use C++ functions and constructs, specifiacally, fstream functions. However, I cannot use these functions, as I get an error "eh.h is for C++ only!" I did some research, and it turns out VS compils .c files with its C compiler and .cpp files with its C++ compiler. So I figured I would just change the .c files to .cpp. Now things like this:
DWORD dwNeeded, dwReturned ;
HDC hdc ;
PRINTER_INFO_4 * pinfo4 ;
PRINTER_INFO_5 * pinfo5 ;
if (GetVersion () & 0x80000000) // Windows 98
{
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo5 = malloc (dwNeeded) ;
fails, because pinfo5 = malloc (dwNeeded)
cannot convert from void * to PRINTER_INFO_5 *, it requres an explicit cast. So even though the C++ mantra is "Anything written in C will compile in C++", it doesn't seem to work in this case, possibly a peculirarity of VS. Anyway, I changed "malloc (dwNeeded)" to "new (PRINTER_INFO_5)" and it now compiled, but I got a different error when I tried to print.
My question is, what do you Windows programmers use, C or C++, and for thoes of you who use C++, do you run into many compatability problems? I know this forum usually deals with specific code questions, and this is more general, but I like Windows programming, and at the same time want to use C++, I just don't know exactly how to go about it. Is there a way I can force VS to use its C++ compiler, even though the file is .c? Or do you all do it a different way?
I am learning to program Windows using Charles Petzolds book Programming Windows Fifth Edition, and so far, so good. However, he writes all of his programs in C, and I want to use C++ functions and constructs, specifiacally, fstream functions. However, I cannot use these functions, as I get an error "eh.h is for C++ only!" I did some research, and it turns out VS compils .c files with its C compiler and .cpp files with its C++ compiler. So I figured I would just change the .c files to .cpp. Now things like this:
DWORD dwNeeded, dwReturned ;
HDC hdc ;
PRINTER_INFO_4 * pinfo4 ;
PRINTER_INFO_5 * pinfo5 ;
if (GetVersion () & 0x80000000) // Windows 98
{
EnumPrinters (PRINTER_ENUM_DEFAULT, NULL, 5, NULL,
0, &dwNeeded, &dwReturned) ;
pinfo5 = malloc (dwNeeded) ;
fails, because pinfo5 = malloc (dwNeeded)
cannot convert from void * to PRINTER_INFO_5 *, it requres an explicit cast. So even though the C++ mantra is "Anything written in C will compile in C++", it doesn't seem to work in this case, possibly a peculirarity of VS. Anyway, I changed "malloc (dwNeeded)" to "new (PRINTER_INFO_5)" and it now compiled, but I got a different error when I tried to print.
My question is, what do you Windows programmers use, C or C++, and for thoes of you who use C++, do you run into many compatability problems? I know this forum usually deals with specific code questions, and this is more general, but I like Windows programming, and at the same time want to use C++, I just don't know exactly how to go about it. Is there a way I can force VS to use its C++ compiler, even though the file is .c? Or do you all do it a different way?