Original Post
Oh Goody, Code Time!
Alright recruits, we’re about to test your compiling and linking skills. I’ve added a zipfile called BASECODE1 on my website that I’d like you to download now (don’t unzip it yet though!). The zipfile contains the following files:
- Globals.h – the main header file for the game template
- WinBase.cpp – the windows application overhead we’ve discussed
- InitTerm.cpp – the initialization/shutdown functions
- GameMain.cpp – where the game code goes
- Utils.h – prototypes for our helper functions
- Utils.cpp – the helper functions themselves
- Resource.bmp – a sample bitmap
- Sample.wav – a sample WAV file
- DDRAW.H
- DINPUT.H
- DSOUND.H
- DDRAW.DLL
- DINPUT.DLL
- DSOUND.DLL
- DDRAW.LIB
- DINPUT.LIB
- DSOUND.LIB
Compiling... GameMain.cpp c:\gdn\basecode\globals.h(87) : error C2146: syntax error : missing ';' before identifier 'lpDD' c:\gdn\basecode\globals.h(87) : error C2501: 'LPDIRECTDRAW7' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(87) : error C2501: 'lpDD' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(88) : error C2146: syntax error : missing ';' before identifier 'lpDDSPrimary' c:\gdn\basecode\globals.h(88) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(88) : error C2501: 'lpDDSPrimary' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(89) : error C2146: syntax error : missing ';' before identifier 'lpDDSBack' c:\gdn\basecode\globals.h(89) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(89) : error C2501: 'lpDDSBack' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(90) : error C2146: syntax error : missing ';' before identifier 'lpDDSRes' c:\gdn\basecode\globals.h(90) : error C2501: 'LPDIRECTDRAWSURFACE7' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(90) : error C2501: 'lpDDSRes' : missing storage-class or type specifiers c:\gdn\basecode\globals.h(94) : error C2146: syntax error : missing ';' before identifier 'lpDI' c:\gdn\basecode\globals.h(94) : error C2501: 'LPDIRECTINPUT7' : missing storage-class or type specifiers(…on and on…) then you probably need to make sure that you’re pointing the IDE to the DirectX header files (look in Tools|Options|Directories ). If you have other compile errors, try to get ahold of me (teej@gdnmail.net or 70816765 on ICQ) or post a reply to this article with your questions. As for the linking, well, that’s primarily the job of the LIB list we prepared under Project|Settings|Link. Here’s an example of having it entered incorrectly:
Linking... InitTerm.obj : error LNK2001: unresolved external symbol _DirectDrawCreateEx@16 InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectDraw7 InitTerm.obj : error LNK2001: unresolved external symbol _c_dfDIKeyboard InitTerm.obj : error LNK2001: unresolved external symbol _GUID_SysKeyboard InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectInputDevice7A InitTerm.obj : error LNK2001: unresolved external symbol _DirectInputCreateEx@20 InitTerm.obj : error LNK2001: unresolved external symbol _IID_IDirectInput7A InitTerm.obj : error LNK2001: unresolved external symbol _DirectSoundCreate@12 Debug/basecode.exe : fatal error LNK1120: 8 unresolved externals Error executing link.exe. basecode.exe - 9 error(s), 0 warning(s)As you can see, since the libraries weren’t included properly, the poor linker was lost when it came to including these symbols. Once again, let us know if you’re stumped. NOTE: When we added the libraries in for the linker, you may have noticed on the left side of the screen that there was a box that had ‘Settings for: Win32 Debug ’. Keep in mind that these libraries that you’re adding are only valid when in Debug mode. You can either change this box to read ‘All Configurations ’ before entering your libraries, or enter them a second time when in Release mode. So Far So Good… If you managed to reach the finish line, ‘0 errors, 0 warnings ’, run the program (CTRL-F5) and hopefully you’ll be rewarded with some text on the screen. The space bar will cause a sound to play, and ESCAPE will exit the program. If you aren’t here yet, don’t bother continuing in the forum! That’s why this is called the ‘Readiness Test’… if you can’t get this stuff to run you need to let us know so that we can help rectify the situation. What about the program itself? On the surface, it doesn’t seem to do much. In fact, it uses DirectDraw, DirectInput and DirectSound in proper form (initialization, use and shutdown), so it’s a good learning example. In later articles we will be using and building on this framework, so it’s a good idea to get your DirectX online documentation ready and try going through the code. Of course, the documentation provides excellent introductory material on each of these components, and if you take the time to read some of it you’ll be ahead of the game. The Ladder series was designed to represent ‘prerequisite knowledge’. You know have everything you need to start on your path to enlightenment:
- An introduction to game development
- A basic windows application framework
- C language resources
- A quick overview of some of the basic tools required
- Some insight into how a game might be written
- Information on resolutions, colors and pixel plotting
- The role of DirectX in our games
- A first run with some game template code