Skip to main content
GameDev.net gamedev.net
🔒 Locked

help with OOP C++?

Started by escudo825 Jan 30, 2006 at 3:49 PM 14 replies 1.6k views
Original Post
escudo825
escudo825
I just got done with a semester of a c++ class. now I'm doing my own stuff and in the class we only covered the basics of object oriented programming. can anyone point me to some help? the main resone I need help is because I've had the DX7 SDK for awhile and I want to learn DDraw in c++ (I already know it in VB) but I can't get the samples compiled because I can't remember the specifics of compiling Oblject oriented programs.
Oluseyi
Oluseyi
There's no difference compiling object-oriented, pseudo-functional or procedural programs in C++. Your problems are likely due to not knowing how to properly set up your project workspace in Visual Studio.
escudo825
escudo825
then where could I learn the proper way?
M2tM
M2tM
By understanding what you need to include in your program and then seeking tutorials on including libs in your ide.
_____"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
escudo825
escudo825
ok heres another description that should help more.

I'm trying to compile and run DirectDraw7 example 1 from the DX7 SDK. it is my understanding that I should be able to just load the main source file, compile it and run it. and I'm using VC++ 6 if that helps.

I also am consistently getting these 3 errors:

.cpp(39) : error C2146: syntax error : missing ';' before identifier 'g_pDD'.cpp(39) : error C2501: 'LPDIRECTDRAW7' : missing storage-class or type specifiers.cpp(39) : fatal error C1004: unexpected end of file found
CTar
CTar
Quote:
Original post by escudo825
.cpp(39) : error C2146: syntax error : missing ';' before identifier 'g_pDD'



Try checking if you are missing a semicolon before g_pDD on line 39.
escudo825
escudo825
I did and that's not the problem. I can't find the code tag button to make this neater. but here it the code around the problem area.

#define TIMER_ID 1
#define TIMER_RATE 500

//-----------------------------------------------------------------------------
// Global data
//-----------------------------------------------------------------------------
LPDIRECTDRAW7 g_pDD = NULL; // DirectDraw object (line 39)
LPDIRECTDRAWSURFACE7 g_pDDSPrimary = NULL;// DirectDraw primary surface
LPDIRECTDRAWSURFACE7 g_pDDSBack = NULL; // DirectDraw back surface
BOOL g_bActive = FALSE; // Is application active?

line 39 is the problem area. if I comment that out I get the same problem with the next line. but seeing the code may at least show how I am confused.
CTar
CTar
Have you remembered to include the directdraw headers BEFORE line 39? It looks like it don't know anything about the types.
escudo825
escudo825
the DDRAW.h header is there. and just fyi, as far as c++ goes I'm not sure what I do or do not know ;). that's why I'm here instead of working on cool DirectDraw stuff.
CTar
CTar
Quote:
Original post by escudo825
the DDRAW.h header is there. and just fyi, as far as c++ goes I'm not sure what I do or do not know ;). that's why I'm here instead of working on cool DirectDraw stuff.


I said IT (the compiler) didn't knew anything about types, I don't know how much you know. I'm not sure what your problem is then, it seems there is something wrong with the LPDIRECTDRAW7 type, but if you have included ddraw.h there should be no problem.
jpetrie
jpetrie
Quote:

the DDRAW.h header is there


Where? Post the entire file that the error is occuring in; it definately sounds like the #include is missing or that something higher above line 39 is broken (possibly in another header you include). Place the source between source tags: (source) and (/source) except use the [ and ] brackets instead of parens.
escudo825
escudo825
well it's from the DX7 SDK (as i've said) so there shouldn't be any problem, but I'll post it anyway. it's also alittle big.

//-----------------------------------------------------------------------------// File: DDEx1.CPP//// Desc: Direct Draw example program 1.  Creates a Direct Draw//       object and then a primary surface with a back buffer.//       Slowly flips between the primary surface and the back//       buffer.  Press F12 to terminate the program.//// Copyright (c) 1995-1999 Microsoft Corporation. All rights reserved.//-----------------------------------------------------------------------------#ifndef WIN32_LEAN_AND_MEAN#define WIN32_LEAN_AND_MEAN#endif//-----------------------------------------------------------------------------// Include files//-----------------------------------------------------------------------------#include <windows.h>#include <ddraw.h>#include <stdio.h>#include <stdarg.h>#include "resource.h"//-----------------------------------------------------------------------------// Local definitions//-----------------------------------------------------------------------------#define NAME                "DDExample1"#define TITLE               "Direct Draw Example 1"//-----------------------------------------------------------------------------// Default settings//-----------------------------------------------------------------------------#define TIMER_ID            1#define TIMER_RATE          500//-----------------------------------------------------------------------------// Global data//-----------------------------------------------------------------------------LPDIRECTDRAW7               g_pDD = NULL;        // DirectDraw objectLPDIRECTDRAWSURFACE7        g_pDDSPrimary = NULL;// DirectDraw primary surfaceLPDIRECTDRAWSURFACE7        g_pDDSBack = NULL;   // DirectDraw back surfaceBOOL                        g_bActive = FALSE;   // Is application active?//-----------------------------------------------------------------------------// Local data//-----------------------------------------------------------------------------static char                 szMsg[] = "Page Flipping Test: Press F12 to exit";static char                 szFrontMsg[] = "Front buffer (F12 to quit)";static char                 szBackMsg[] = "Back buffer (F12 to quit)";//-----------------------------------------------------------------------------// Name: ReleaseAllObjects()// Desc: Finished with all objects we use; release them//-----------------------------------------------------------------------------static voidReleaseAllObjects(void){    if (g_pDD != NULL)    {        if (g_pDDSPrimary != NULL)        {            g_pDDSPrimary->Release();            g_pDDSPrimary = NULL;        }        g_pDD->Release();        g_pDD = NULL;    }}//-----------------------------------------------------------------------------// Name: InitFail()// Desc: This function is called if an initialization function fails//-----------------------------------------------------------------------------HRESULTInitFail(HWND hWnd, HRESULT hRet, LPCTSTR szError,...){    char                        szBuff[128];    va_list                     vl;    va_start(vl, szError);    vsprintf(szBuff, szError, vl);    ReleaseAllObjects();    MessageBox(hWnd, szBuff, TITLE, MB_OK);    DestroyWindow(hWnd);    va_end(vl);    return hRet;}//-----------------------------------------------------------------------------// Name: UpdateFrame()// Desc: Displays the proper text for the page//-----------------------------------------------------------------------------static voidUpdateFrame(HWND hWnd){    static BYTE                 phase = 0;    HDC                         hdc;    DDBLTFX                     ddbltfx;    RECT                        rc;    SIZE                        size;    // Use the blter to do a color fill to clear the back buffer    ZeroMemory(&ddbltfx, sizeof(ddbltfx));    ddbltfx.dwSize = sizeof(ddbltfx);    ddbltfx.dwFillColor = 0;    g_pDDSBack->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);    if (g_pDDSBack->GetDC(&hdc) == DD_OK)    {        SetBkColor(hdc, RGB(0, 0, 255));        SetTextColor(hdc, RGB(255, 255, 0));        if (phase)        {            GetClientRect(hWnd, &rc);            GetTextExtentPoint(hdc, szMsg, lstrlen(szMsg), &size);            TextOut(hdc, (rc.right - size.cx) / 2, (rc.bottom - size.cy) / 2,                    szMsg, sizeof(szMsg) - 1);            TextOut(hdc, 0, 0, szFrontMsg, lstrlen(szFrontMsg));            phase = 0;        }        else        {            TextOut(hdc, 0, 0, szBackMsg, lstrlen(szBackMsg));            phase = 1;        }        g_pDDSBack->ReleaseDC(hdc);    }}//-----------------------------------------------------------------------------// Name: WindowProc()// Desc: The Main Window Procedure//-----------------------------------------------------------------------------long FAR PASCALWindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    HRESULT                     hRet;    switch (message)    {        case WM_ACTIVATE:            // Pause if minimized            g_bActive = !((BOOL)HIWORD(wParam));            return 0L;        case WM_DESTROY:            // Clean up and close the app            ReleaseAllObjects();            PostQuitMessage(0);            return 0L;        case WM_KEYDOWN:            // Handle any non-accelerated key commands            switch (wParam)            {                case VK_ESCAPE:                case VK_F12:                    PostMessage(hWnd, WM_CLOSE, 0, 0);                    return 0L;            }            break;        case WM_SETCURSOR:            // Turn off the cursor since this is a full-screen app            SetCursor(NULL);            return TRUE;        case WM_TIMER:            // Update and flip surfaces            if (g_bActive && TIMER_ID == wParam)            {                UpdateFrame(hWnd);                while (TRUE)                {                    hRet = g_pDDSPrimary->Flip(NULL, 0);                    if (hRet == DD_OK)                        break;                    if (hRet == DDERR_SURFACELOST)                    {                        hRet = g_pDDSPrimary->Restore();                        if (hRet != DD_OK)                            break;                    }                    if (hRet != DDERR_WASSTILLDRAWING)                        break;                }            }            break;    }    return DefWindowProc(hWnd, message, wParam, lParam);}//-----------------------------------------------------------------------------// Name: InitApp()// Desc: Do work required for every instance of the application://          Create the window, initialize data//-----------------------------------------------------------------------------static HRESULTInitApp(HINSTANCE hInstance, int nCmdShow){    HWND                        hWnd;    WNDCLASS                    wc;    DDSURFACEDESC2              ddsd;    DDSCAPS2                    ddscaps;    HRESULT                     hRet;    // Set up and register window class    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = WindowProc;    wc.cbClsExtra = 0;    wc.cbWndExtra = 0;    wc.hInstance = hInstance;    wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAIN_ICON));    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);    wc.lpszMenuName = NAME;    wc.lpszClassName = NAME;    RegisterClass(&wc);    // Create a window    hWnd = CreateWindowEx(WS_EX_TOPMOST,                          NAME,                          TITLE,                          WS_POPUP,                          0,                          0,                          GetSystemMetrics(SM_CXSCREEN),                          GetSystemMetrics(SM_CYSCREEN),                          NULL,                          NULL,                          hInstance,                          NULL);    if (!hWnd)        return FALSE;    ShowWindow(hWnd, nCmdShow);    UpdateWindow(hWnd);    SetFocus(hWnd);    ///////////////////////////////////////////////////////////////////////////    // Create the main DirectDraw object    ///////////////////////////////////////////////////////////////////////////    hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL);    if (hRet != DD_OK)        return InitFail(hWnd, hRet, "DirectDrawCreateEx FAILED");    // Get exclusive mode    hRet = g_pDD->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);    if (hRet != DD_OK)        return InitFail(hWnd, hRet, "SetCooperativeLevel FAILED");    // Set the video mode to 640x480x8    hRet = g_pDD->SetDisplayMode(640, 480, 8, 0, 0);    if (hRet != DD_OK)        return InitFail(hWnd, hRet, "SetDisplayMode FAILED");    // Create the primary surface with 1 back buffer    ZeroMemory(&ddsd, sizeof(ddsd));    ddsd.dwSize = sizeof(ddsd);    ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |                          DDSCAPS_COMPLEX;    ddsd.dwBackBufferCount = 1;    hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSPrimary, NULL);    if (hRet != DD_OK)        return InitFail(hWnd, hRet, "CreateSurface FAILED");    // Get a pointer to the back buffer    ZeroMemory(&ddscaps, sizeof(ddscaps));    ddscaps.dwCaps = DDSCAPS_BACKBUFFER;    hRet = g_pDDSPrimary->GetAttachedSurface(&ddscaps, &g_pDDSBack);    if (hRet != DD_OK)        return InitFail(hWnd, hRet, "GetAttachedSurface FAILED");    // Create a timer to flip the pages    if (TIMER_ID != SetTimer(hWnd, TIMER_ID, TIMER_RATE, NULL))        return InitFail(hWnd, hRet, "SetTimer FAILED");    return DD_OK;}//-----------------------------------------------------------------------------// Name: WinMain()// Desc: Initialization, message loop//-----------------------------------------------------------------------------int PASCALWinMain(HINSTANCE hInstance,        HINSTANCE hPrevInstance,        LPSTR lpCmdLine,        int nCmdShow){    MSG                         msg;    if (InitApp(hInstance, nCmdShow) != DD_OK)        return FALSE;    while (GetMessage(&msg, NULL, 0, 0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return msg.wParam;}
nullsquared
nullsquared
My only guess is that you messed something up in resource.h.

Do you have a class/struct/union in that header? Since the macros on top (more of defines rather than macros) are made BEFORE actual compiling my only guess is that you have missing a ; on the end of a struct/union/class in resource.h.
escudo825
escudo825
well here is the extent of the resource.h file

//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by Script1.rc//#define IDI_ICON1                       101// Next default values for new objects// #ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE        102#define _APS_NEXT_COMMAND_VALUE         40001#define _APS_NEXT_CONTROL_VALUE         1000#define _APS_NEXT_SYMED_VALUE           101#endif#endif
Shannon Barber
Shannon Barber
My guess is that it's an old ddraw.h header that is being included - one that does not "know" about DirectDraw 7.

It depends on which version of MSVC you have, but somewhere under Tools->Options there are directory settings for Include and Library. Make sure the paths to the DirectX SDK are above the Platform SDK you have installed. The Include and Library entries should be perfectly paralleled (matched pairs in the same order in both list).

You can test this by changing:
LPDIRECTDRAW7 g_pDD = NULL;
to
LPDIRECTDRAW g_pDD = NULL;

And see if the first error goes away. If it does, you are using an old header.
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
escudo825
escudo825
well that's not the problem it seems. I moved to a different computer and now I only have one error:

ddex1.cpp(228) : error C2065: 'IDI_MAIN_ICON' : undeclared identifier

I don't know how I can fix this but my initial problem is gone. I just need to track down why this is happening.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.