Archived

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

Alload

Problem using a function found in a tutorial

Recommended Posts

Hello, I tried to use a function which loads a bitmap and blits it in a DirectDraw Surface, but when I try to compile the code VC++ says that the local function definitions are illegal. Could you help me please? Here''s the "BitmapToSurface.h": #include #include int BitmapToSurface(LPDIRECTDRAWSURFACE lpSurfaceDest, char szBitmapName[], int iXSize, int iYSize, int iXDest, int iYDest) { HDC hSrcDC; // source DC - memory device context HDC hDestDC; // destination DC - surface device context HBITMAP hbitmap; // handle to the bitmap resource BITMAP bmp; // structure for bitmap info int nHeight, nWidth; // bitmap dimensions // first load the bitmap resource if ((hbitmap = (HBITMAP)LoadImage(hInstance, szBitmapName, IMAGE_BITMAP, iXSize, iYSize, LR_CREATEDIBSECTION | LR_LOADFROMFILE)) == NULL) return(FALSE); // create a DC for the bitmap to use if ((hSrcDC = CreateCompatibleDC(NULL)) == NULL) return(FALSE); // select the bitmap into the DC if (SelectObject(hSrcDC, hbitmap) == NULL) { DeleteDC(hSrcDC); return(FALSE); } // get image dimensions if (GetObject(hbitmap, sizeof(BITMAP), &bmp) == 0) { DeleteDC(hSrcDC); return(FALSE); } nWidth = bmp.bmWidth; nHeight = bmp.bmHeight; // retrieve surface DC if (FAILED(lpSurfaceDest->GetDC(&hDestDC))) { DeleteDC(hSrcDC); return(FALSE); } // copy image from one DC to the other if (BitBlt(hDestDC, iXDest, iYDest, nWidth, nHeight, hSrcDC, 0, 0, SRCCOPY) == NULL) { lpSurfaceDest->ReleaseDC(hDestDC); DeleteDC(hSrcDC); return(FALSE); } // kill the device contexts lpSurfaceDest->ReleaseDC(hDestDC); DeleteDC(hSrcDC); // return success return 0; } And here''s the "main.cpp": #include #include #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif /////////////////////////////////////////////////////////////////// LPDIRECTDRAW lpDirectDrawObject = NULL; LPDIRECTDRAWSURFACE lpPrimary = NULL; /////////////////////////////////////////////////////////////////// long CALLBACK WndProc(HWND hwnd, UINT message, UINT wParam, long lParam) { switch (message) { case WM_KEYDOWN: { if (wParam == VK_ESCAPE) { DestroyWindow(hwnd); return 0; } else return 0; } case WM_DESTROY: { if (lpDirectDrawObject) { if (lpPrimary) lpPrimary->Release(); lpDirectDrawObject->Release(); } PostQuitMessage(0); return 0; } default: { return (DefWindowProc(hwnd, message, wParam, lParam)); } } } /////////////////////////////////////////////////////////////////// int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HWND hwnd; WNDCLASSEX wndclassex; MSG msg; const char szClassName[] = "Window Class"; wndclassex.lpszClassName = szClassName; wndclassex.cbSize = sizeof(wndclassex); wndclassex.style = CS_HREDRAW | CS_VREDRAW; wndclassex.lpszMenuName = NULL; wndclassex.hInstance = hInstance; wndclassex.lpfnWndProc = WndProc; wndclassex.hbrBackground = NULL; wndclassex.cbClsExtra = 0; wndclassex.cbWndExtra = 0; wndclassex.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wndclassex.hCursor = LoadCursor(NULL, IDC_ARROW); RegisterClassEx(&wndclassex); hwnd = CreateWindowEx( WS_EX_TOPMOST, szClassName, "DirectX Project", WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); ShowWindow(hwnd, nShowCmd); UpdateWindow(hwnd); /////////////////////////////////////////////////////////////////// DirectDrawCreate(NULL, &lpDirectDrawObject, NULL); lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); lpDirectDrawObject->SetDisplayMode(1024, 768, 32); DDSURFACEDESC ddsd; ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL); #include "BitmapToSurface.h" BitmapToSurface(lpPrimary, "image.bmp", 1024, 768, 0, 0); /////////////////////////////////////////////////////////////////// while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }

Share this post


Link to post
Share on other sites
I manage to get the things working a bit better, but I can''t still compile my code.

If anyone can help me, here you can download the source files: http://www.multimania.com/final6/DDproblem.zip

THANKS.

Share this post


Link to post
Share on other sites