Teej's Tutorial Questions
Here a group of us will go through the tutorial and ask questions.
Hope this doesn't annoy anyone.
me too hehe, well here is for the first question,
why does this not work?
errors:
why does this not work?
#include <windows.h>int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // The main loop. This will call Game_Main() repeatedly, stopping// only to process Windows messages, and terminating with WM_QUIT.while(TRUE){ // Grab any Windows messages that are for us if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // Send these messages to WindowProc if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } // Call our Game function else if (G.bActive) Game_Main();}//////////////////////////////////////////////////////////////////////////////// WindowProc//// Whenever the operating system has a message for us, it ends up here. If// we're interested in any particular message, we have to provide code to// handle it.//LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){ // Process the window message switch (msg) { case WM_ACTIVATE: // The active state of our window is changing (e.g. ALT-TAB). // We keep track of this so that we don't bother drawing // frames of animation if it can't be seen anyhow... G.bActive = !((BOOL)HIWORD(wParam)); return 0L; case WM_KEYDOWN: if (wParam == VK_ESCAPE) { // The ESCAPE key quits... G.bQuitting = TRUE; PostQuitMessage(0); return 0L; } break; case WM_DESTROY: // We're done; quit the main loop PostQuitMessage(0); return 0L; } // Pass all other messages on for default processing return DefWindowProc(hWnd, msg, wParam, lParam);}}
errors:
Compiler: Default compilerBuilding Makefile: "C:\Documents and Settings\HP_Owner\Desktop\C++\myproj\Makefile.win"Executing make...make.exe -f "C:\Documents and Settings\HP_Owner\Desktop\C++\myproj\Makefile.win" allg++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include" main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':main.cpp:8: error: `msg' undeclared (first use this function)main.cpp:8: error: (Each undeclared identifier is reported only once for each function it appears in.)main.cpp:17: error: `G' undeclared (first use this function)main.cpp:17: error: `Game_Main' undeclared (first use this function)main.cpp:27: error: syntax error before `{' tokenmain.cpp:38: error: case label `256' not within a switch statementmain.cpp:39: error: `wParam' undeclared (first use this function)main.cpp:48: error: case label `2' not within a switch statementmain.cpp:46: error: break statement not within loop or switchmain.cpp: At global scope:main.cpp:55: error: syntax error before `return'main.cpp:57:2: warning: no newline at end of filemake.exe: *** [main.o] Error 1Execution terminated
Meta AdamOne of a million noob C++ programmers.
you don't have all the files necessary and plus you're missing some variables as well.
hm, i copied right out of the tut, maybe theres more that i dont know about?
Meta AdamOne of a million noob C++ programmers.
try this code
[Edit: Your formatting was absolutely bonkers! I hope it's not your IDE generating such inconsistent whitespace! - Oluseyi]
[Edited by - Oluseyi on January 26, 2005 1:26:20 AM]
#include <windows.h>#include <stdio.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hwnd; MSG msg; WNDCLASSEX wndclass; wndclass.cbSize = sizeof (wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO); wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "Window Class 1"; wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO); RegisterClassEx (&wndclass); hwnd = CreateWindow ("Window Class 1", "My First Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow (hwnd, iCmdShow); while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } UnregisterClass("Window Class 1",hInstance); return msg.wParam;}LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam){ switch (iMsg) { case WM_CREATE: break; case WM_SIZE: break; case WM_PAINT: break; case WM_DESTROY: PostQuitMessage(0); } return DefWindowProc (hwnd, iMsg, wParam, lParam); }
[Edit: Your formatting was absolutely bonkers! I hope it's not your IDE generating such inconsistent whitespace! - Oluseyi]
[Edited by - Oluseyi on January 26, 2005 1:26:20 AM]
wndclass.cbSize = sizeof (wndclass); // Here we set the size of the wndclass. You will see this a lot in windows, it's kinda odd. We use the "sizeof()" function to tell windows the size of our class. wndclass.style = CS_HREDRAW | CS_VREDRAW; // The style we want is Verticle-Redraw and Horizontal-Redraw wndclass.lpfnWndProc = WndProc; // Here is where we assing our CALLBACK function. Remember up above our function "WndProc"? This just tells windows which function it needs to call to check for window messages. wndclass.cbClsExtra = 0; // We don't want to allocate any extra bytes for a class (useless for us) wndclass.cbWndExtra = 0; // Another useless thing for us. I believe these last 2 are initialized to 0 anyway. wndclass.hInstance = hInstance; // We assign our hInstance to our window. Once again, You can have several instances of a program, so this keeps track of the current one. wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO); // We call a function called LoadIcon that returns information about what icon we want. I chose the Wndows Logo. The NULL is in place of a hInstance. We don't need one in this case. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW); // We call a function called LoadCursor that returns information about what cursor we want, I chose an arrow. The NULL is in place of a hInstance. We don't need one in this case. // Here we set the background color. GetStockObject() returns a void so we must "cast" (turn it into) it as a HBRUSH to be compatible with the variable "hbrBackground". I chose GRAY wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wndclass.lpszMenuName = NULL; // We don't have a menu, so let's set this to NULL. wndclass.lpszClassName = "Window Class 1"; // Here we set a name for our class, to distinguish it against others. We need to use this name for later when we create the window. wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO); // We want the icon to be the windows logo. This is the icon in the top left corner of the window.[/source/
Le Linker Errors for BaseCode1:
[source lang ="cpp"]GameMain.o(.text+0x10):GameMain.cpp: undefined reference to `timeGetTime@0'GameMain.o(.text+0x36):GameMain.cpp: undefined reference to `timeGetTime@0'InitTerm.o(.text+0xb9):InitTerm.cpp: undefined reference to `timeBeginPeriod@4'InitTerm.o(.text+0xef):InitTerm.cpp: undefined reference to `IID_IDirectDraw7'InitTerm.o(.text+0x4a2):InitTerm.cpp: undefined reference to `IID_IDirectInput7A'InitTerm.o(.text+0x4f1):InitTerm.cpp: undefined reference to `IID_IDirectInputDevice7A'InitTerm.o(.text+0x4f9):InitTerm.cpp: undefined reference to `GUID_SysKeyboard'InitTerm.o(.text+0x637):InitTerm.cpp: undefined reference to `DirectSoundCreate@12'InitTerm.o(.text+0xc54):InitTerm.cpp: undefined reference to `timeEndPeriod@4'Utils.o(.text+0x778):Utils.cpp: undefined reference to `mmioDescend@16'Utils.o(.text+0x7d8):Utils.cpp: undefined reference to `mmioDescend@16'Utils.o(.text+0x817):Utils.cpp: undefined reference to `mmioRead@12'Utils.o(.text+0x8a1):Utils.cpp: undefined reference to `mmioRead@12'Utils.o(.text+0x931):Utils.cpp: undefined reference to `mmioRead@12'Utils.o(.text+0x977):Utils.cpp: undefined reference to `mmioAscend@12'Utils.o(.text+0x9d4):Utils.cpp: undefined reference to `mmioOpenA@12'Utils.o(.text+0xa1e):Utils.cpp: undefined reference to `mmioClose@8'Utils.o(.text+0xa66):Utils.cpp: undefined reference to `mmioSeek@12'Utils.o(.text+0xaa3):Utils.cpp: undefined reference to `mmioDescend@16'Utils.o(.text+0xae9):Utils.cpp: undefined reference to `mmioGetInfo@12'Utils.o(.text+0xb5a):Utils.cpp: undefined reference to `mmioAdvance@12'Utils.o(.text+0xbb1):Utils.cpp: undefined reference to `mmioSetInfo@12'Utils.o(.text+0xd54):Utils.cpp: undefined reference to `mmioClose@8'make.exe: *** [T_GameDev.exe] Error 1Execution terminatedle done.
Meta AdamOne of a million noob C++ programmers.
you'll need to go into Tools, Compiler Options, and enter these as is:
then check add to linker options
also under directories you'll have to add the directx lib and directx include. they will be whereever you install the DXSDK.
-lwinmm -lddraw -ldxguid -ldinput -ldsound
then check add to linker options
also under directories you'll have to add the directx lib and directx include. they will be whereever you install the DXSDK.
added that, and now i got
[Edit: Switched to [source] tags to preserve page width.
[Edited by - Oluseyi on January 26, 2005 2:30:09 AM]
g++.exe -c BaseCode3c/BaseCode3c/WinBase.cpp -o BaseCode3c/BaseCode3c/WinBase.o -I"C:/Dev-Cpp/include/c++/3.3.1" -I"C:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"C:/Dev-Cpp/include/c++/3.3.1/backward" -I"C:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"C:/Dev-Cpp/include" windres.exe -i Project1_private.rc --input-format=rc -o Project1_private.res -O coff g++.exe BaseCode3c/BaseCode3c/GameMain.o BaseCode3c/BaseCode3c/InitTerm.o BaseCode3c/BaseCode3c/Utils.o BaseCode3c/BaseCode3c/WinBase.o Project1_private.res -o "Project1.exe" -L"C:/Dev-Cpp/lib" -mwindows -lwinmm -lddraw -ldxguid -ldinput -ldsound Warning: .drectve `%.*s' unrecognizedBaseCode3c/BaseCode3c/InitTerm.o(.text+0x607):InitTerm.cpp: undefined reference to `DirectSoundCreate@12'make.exe: *** [Project1.exe] Error 1Execution terminated
[Edit: Switched to [source] tags to preserve page width.
[Edited by - Oluseyi on January 26, 2005 2:30:09 AM]
Meta AdamOne of a million noob C++ programmers.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement