Jump to content
  • Advertisement
Sign in to follow this  
Mooncinder

Unity (C++) Definitions in header file not being recognised?

This topic is 3967 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've been following the tetris tutorial at http://www.gamedev.net/community/forums/topic.asp?topic_id=192483. Unfortuantely, I was already a fair way in when I realised just how old it was so I thought I'd be better off starting a new topic with my problem rather than adding a reply to the original post. I've got two source files and one header file and copied the code just as the tutorial instructed. However, when I try to compile it I get the following error for both source files: "unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?" Fair enough, I added '#include "stdafx.h"' to both source files and thought that would fix it. Unfortunately, it didn't. There are a number of variables defined in the header file but the compiler doesn't seem to recognise them. For example, one error I get is "'BitmapObject' : is not a class or namespace name" but the class BitmapObject is clearly defined in the header file. This is my code for the header file: ========START OF CODE======== //BitmapObject.h #ifndef BITMAPOBJECT_H #define BITMAPOBJECT_H #pragma once #include <windows.h> //needed for windows stuff class BitmapObject { private: HDC hdcMemory; //handle to a device context. Refers to an output device HBITMAP hbmNewBitmap; //old bitmap HBITMAP hbmOldBitmap; //new bitmap int iWidth; //width and height of bitmap as integers int iHeight; public: BitmapObject(); //constructor ~BitmapObject(); //destructor //loads a bitmap from a file void Load(HDC hdcCompatible, LPCTSTR, lpszTetrisMap); //creates a blank bitmap void Create(HDC hdcCompatible, int width, int height); void Destroy(); //destroys bitmap and dc int getWidth(); //returns width int getHeight(); //returns height operator HDC(); //converts to HDC }; #endif ========END OF CODE======== I don't know if this makes any difference but the compiler can't find the definitions of hdcMemory, hbmNewBitmap, hbmOldBitmap iHeight and iWidth either. If anyone can shed some light on this, I'd be very grateful. The compiler I'm using is Microsoft Visual Cpp 2005 Express Edition. Thanks in advance, Mooncinder PS. I accidentally clicked on 'bookmark all' in the find and replace window when searching for something and I was wondering if anyone could tell me how to undo this. Thanks again!

Share this post


Link to post
Share on other sites
Advertisement
You need to disable Precompiled Headers. In the left-hand Solution Explorer, right-click on your project and click on Properties. Go to Configuration Properties->C/C++->Precompiled Headers. Select "Not using precompiled headers." Now, remove stdafx.h.

By not using precompiled headers, you will lose some of Visual Studio's Intellisense features and some speed in compiling.

Share this post


Link to post
Share on other sites
Quote:

By not using precompiled headers, you will lose some of Visual Studio's Intellisense features and some speed in compiling.

Not true; the PCH files aren't used by the Intellisense subsystem. And chances are, not using precompiled headers will improve compilation speed (precompiled headers are often misused) and help reduce dependencies on unnecessary headers.

Anyway, to the OP:

0) Remove that #include "stdafx.h" crap, go to the Project Options, under C++ option, find the option for Precompiled Headers and set it to "Not Using Precompiled Headers." They cause more trouble than they're worth, especially when you don't know how to properly use them to achieve any kind of real benefit (even when used properly... it's debatable). It's kind of unfortunate the option is on by default.

1) #pragma once is redundant with your include guards, you can remove it (the #ifndef guards are more standard compliant).

2) I don't think bookmarks are saved across sessions, so maybe close the IDE and reopen? There should be a clear bookmarks command under the view or edit menus, anyway.

3) Does the source file you're actually compiling #include "BitmapObject.h"? If so, post that source file. It simply sounds like you're trying to use BitmapObject in a source file without fully defining it. Headers must be explicitly included into every translation unit; headers are not automatically picked up by the IDE's project system and compiled by the compiler (and you don't want them to be, as it would cause lots of problems and wouldn't actually solve this one).

4) Also, is this error about BitmapObject the FIRST error? Because if the errors about HDC, etc, are that might imply you don't have the Platform SDK installed and/or configured properly.

Share this post


Link to post
Share on other sites
Thanks for your help. It did seem that having precompiled header enabled was the problem. Now I just get a few errors about conversions. This tutorial I'm following seems to use 'lpsz' and 'LPCWSTR' quite a bit (e.g. in the line "wcx.lpszClassName = WINDOWCLASS;" which causes the error "cannot convert from 'const char [13]' to 'LPCWSTR'") but I don't really understand what they are. Is there anywhere you would recommend where I could learn more about these?

Thanks again,
Mooncinder

Share this post


Link to post
Share on other sites

We surely can. I find the presentation concering different Win32 string literals are presented in Codeproject quite neatly by Michael Dunn and Nishant Sivakumar.

Basically LPCWSTR is a long pointer to constant wide string. There is a great pain in current C++ standard* on not having a standard presentation on Unicode strings. Since Microsoft has traditionally supported multiple cultures and languages, it has needed to develop some system to contain the characters encodings in those languages.

* Note that this is going to be standardised in C++09. If you are more interested, please see Unicode characters and strings [N2249].

Share this post


Link to post
Share on other sites
It all seems very confusing but I guess it's the same with anything when you come across it for the first time. Thanks, I'll be sure to have a look at that. :)

Mooncinder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!