Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Help

Just 4 compile errors!

This topic is 6927 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

Thanks everyone, great help. However, I do feel like a fool for making a Win32 Console App and not spotting it! Thanks again. Edited by - Help on 5/6/00 9:02:12 PM

Share this post


Link to post
Share on other sites
Advertisement
Now, I have got it to compile but not to link unfortunately.
Thanks for your help.
Here is my linking error:


LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

Share this post


Link to post
Share on other sites
quote:
Original post by Help
Here is my linking error:

LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Test.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.



You should be building a "Win32 Application" instead of a "Win32 Console Application".

aig

Share this post


Link to post
Share on other sites
Here''s my revised version of the program, I apologise for the huge length of this post now - I''ll delete it when my question is resolved.



/////////////////////////////////////////
// My test Direct Draw prog
/////////////////////////////////////////

//defines
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

//includes
#include
#include
#include
#include

//Time defs
#define TIMER_ID 1
#define TIMER_RATE 500

//Window Defs
#define NAME "DDDemo"
#define TITLE "Direct Draw Example"

//Globals (ugh)
LPDIRECTDRAW lpDD;
LPDIRECTDRAWSURFACE lpDDSPrimary;
LPDIRECTDRAWSURFACE lpDDSBack;
BOOLEAN bActive;

//Local data
static char szFrontMsg[] = "Front buffer - - - F12 to quit";
static char szBackMsg[] = "Back buffer - - - F12 to quit";
static char szMsg[] = "Page Flipping test";


//Start of prog for real
static void finishObjects(void)
{

if (lpDD != NULL)
{
if (lpDDSPrimary != NULL)
{
lpDDSPrimary->Release();
lpDDSPrimary = NULL;
}
lpDD->Release();
lpDD = NULL;
}

}


//Update Frame function
static void UpdateFrame(HWND hwnd)
{

static BYTE phase = 0;
HDC hdc;
DDBLTFX ddbltfx;
RECT rc;
SIZE size;

//Use the blter to do a color fill, clearing the back buffer
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
lpDDSBack->Blt(NULL,NULL,NULL, DDBLT_COLORFILL / DDBLT_WAIT, &ddbltfx);

if (lpDDSBack->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(szFrontMsg));
phase = 0;
}
else
{
TextOut(hdc, 0, 0, szBackMsg, lstrlen(szBackMsg));
phase = 1;
}
lpDDSBack->ReleaseDC(hdc);
}

}


long FAR PASCAL WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HRESULT hRet;
static BYTE phase = 0;

switch (message)
{
case WM_ACTIVATE:
//Pause if minimised
bActive = !((BOOL)HIWORD(wParam));
return 0L;

case WM_DESTROY:
//Clean up and cliose the application
finishObjects();
PostQuitMessage(0);
return 0L;

case WM_KEYDOWN:
//Handle 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 application!
SetCursor(NULL);
return TRUE;

case WM_TIMER:
//Update and flip surfaces
if (bActive && TIMER_ID == wParam)
{
UpdateFrame(hwnd);
while (TRUE)
{
hRet = lpDDSPrimary->Flip(NULL, 0);
if (hRet == DD_OK)
break;
if (hRet == DDERR_SURFACELOST)
{
hRet = lpDDSPrimary->Restore();
if (hRet != DD_OK)
break;
}
if (hRet != DDERR_WASSTILLDRAWING)
break;
}
}
break;
}

return DefWindowProc(hwnd, message,wParam,lParam);
}


static HRESULT doInit(HINSTANCE hInstance, int nCmdShow)
{
HWND hwnd;
HDC hdc;
WNDCLASS wc;
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT ddrval;

// 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(NULL /* IDI_MAIN_ICON */));
wc.hCursor = LoadCursor(NULL, 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);



/////////////////////////////////////////
// Where the Direct Draw stuff begins
//////////////////////////////////////////
ddrval = DirectDrawCreate(NULL, &lpDD, NULL);
if (ddrval != DD_OK)
{
return false;
}

//Get exclusive and fullscreen modes
ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN);
if (ddrval != DD_OK)
{
lpDD->Release();
return false;
}

//Set the vid mode to 640x480x8
ddrval = lpDD->SetDisplayMode(640, 480, 8);
if (ddrval != DD_OK)
{
lpDD->Release();
return false;
}

//Create primary surface with just the 1 back buffer
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;

ddrval = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL);
if (ddrval != DD_OK)
{
lpDD->Release();
return false;
}

//Get pointer to the back buffer
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);
if (ddrval != DD_OK)
{
return FALSE;
}

if (lpDDSPrimary->GetDC(&hdc) == DD_OK)
{
SetBkColor(hdc, RGB(0,0,255));
SetTextColor(hdc, RGB(255,255,0));
TextOut(hdc, 0, 0, szFrontMsg, lstrlen(szFrontMsg));
lpDDSPrimary->ReleaseDC(hdc);
}

if (lpDDSBack->GetDC(&hdc) == DD_OK)
{
SetBkColor(hdc, RGB(0,0,255));
SetTextColor(hdc,RGB(255,255,0));
TextOut(hdc, 0, 0, szBackMsg, lstrlen(szBackMsg));
lpDDSBack->ReleaseDC(hdc);
}

//Timer
if (!SetTimer(hwnd, TIMER_ID, TIMER_RATE, NULL))
{
finishObjects();
}

return DD_OK;

}

////////////////////////////////////////////
// Initialisation and msg loop
////////////////////////////////////////////

int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpcmdLine, int nCmdShow)
{
MSG msg;

if (doInit(hInstance, nCmdShow) != DD_OK)
return FALSE;

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

Yes, I have the correct .lib files included in the link part of the Project->Settings tabs. (I believe they are ddraw.lib and dxguid.lib). Also, the library and header files are set to the top in the Tools->Options folders tab.

Thanks again ppl.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!