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


BCB directx7 prob

Recommended Posts

SAKIRA    122
Helo Im having a linker error in bcb with a direct x 7 file from a book i converted the files from the books cdrom(of course it was in @#$%%^ vc++). From dsp to bpr with the vc++ conversion utility i will show you the code then the error the code three .CPP files //main.cpp //Read 640x480x256 bmp & display full screen (ESC to exit) //Copyright Ian Parberry, 1999 //Last updated May 22, 2000 //system includes #include <windows.h> #include <windowsx.h> #include <ddraw.h> #include <stdio.h> //system defines #define WIN32_LEAN_AND_MEAN //custom includes #include "defines.h" #include "bmp.h" //globals LPDIRECTDRAW lpDirectDrawObject=NULL; //direct draw object LPDIRECTDRAWSURFACE lpPrimary=NULL; //primary surface LPDIRECTDRAWPALETTE lpPrimaryPalette; //its palette BOOL ActiveApp; //is this application active? CBmpFileReader background; //background image //helper functions LPDIRECTDRAWPALETTE CreatePalette(LPDIRECTDRAWSURFACE surface); BOOL InitDirectDraw(HWND hwnd); HWND CreateDefaultWindow(char* name,HINSTANCE hInstance); BOOL LoadImages(){ //load pictures from disk //draw the first image to the primary surface if(!background.load("bckgnd.bmp")) //read from file return FALSE; //read failed if(!background.setpalette(lpPrimaryPalette)) //set palette return FALSE; //set palette failed if(!background.draw(lpPrimary)) //draw to surface return FALSE; //draw failed return TRUE; //all steps succeeded } //LoadImages BOOL keyboard_handler(WPARAM keystroke){ //keyboard handler BOOL result=FALSE; //return TRUE if game is to end switch(keystroke){ case VK_ESCAPE: result=TRUE; break; //exit game } return result; } //keyboard_handler //message handler (window procedure) long CALLBACK WindowProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam){ switch(message){ case WM_ACTIVATEAPP: ActiveApp=wParam; break; case WM_CREATE: break; case WM_KEYDOWN: //keyboard hit if(keyboard_handler(wParam))DestroyWindow(hwnd); break; case WM_DESTROY: //end of game if(lpDirectDrawObject!=NULL){ //if DD object exists if(lpPrimary!=NULL) //if primary surface exists lpPrimary->Release(); //release primary surface lpDirectDrawObject->Release(); //release DD object } ShowCursor(TRUE); //show the mouse cursor PostQuitMessage(0); //and exit break; default: //default window procedure return DefWindowProc(hwnd,message,wParam,lParam); } //switch(message) return 0L; } //WindowProc int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow){ MSG msg; //current message HWND hwnd; //handle to fullscreen window hwnd=CreateDefaultWindow("directX Demo 0",hInstance); if(!hwnd)return FALSE; //set up window ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); SetFocus(hwnd); //allow input from keyboard ShowCursor(FALSE); //hide the cursor //init graphics BOOL OK=InitDirectDraw(hwnd);//initialize DirectDraw if(OK)OK=LoadImages(); //load images from disk if(!OK){ //bail out if initialization failed DestroyWindow(hwnd); return FALSE; } //message loop while(TRUE) if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)){ if(!GetMessage(&msg,NULL,0,0))return msg.wParam; TranslateMessage(&msg); DispatchMessage(&msg); } else if(!ActiveApp)WaitMessage(); } //WinMain ---------------------------------------------------------------- //bmp.cpp: member functions for the bmp file reader //Copyright Ian Parberry, 1999 //Last updated May 22, 2000 #include "bmp.h" //header file //constructors and destructors CBmpFileReader::CBmpFileReader(){ //constructor m_cImage=0; //memory not yet allocated } CBmpFileReader::~CBmpFileReader(){ //destructor delete[]m_cImage; //reclaim memory from image data } //member functions BOOL CBmpFileReader::load(char *filename){ //load bmp from this file HANDLE hfile; //input file handle DWORD actualRead; //number of bytes actually read int image_size; //size of image (width*height) BOOL OK=TRUE; //no error has occurred yet //open input file for reading hfile=CreateFile(filename,GENERIC_READ,FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE)NULL); //bail if file could not be opened if(hfile==INVALID_HANDLE_VALUE)return FALSE; //read the header and info structures OK=ReadFile(hfile,&m_BMPFileHead,sizeof(m_BMPFileHead), &actualRead,NULL); if(OK)OK=ReadFile(hfile,&m_BMPFileInfo, sizeof(m_BMPFileInfo),&actualRead,NULL); //make sure the bmp is 8-bit color if(OK)OK=m_BMPFileInfo.biBitCount==COLOR_DEPTH; //get the bmp palette if(OK)OK=ReadFile(hfile,m_rgbPalette,sizeof(m_rgbPalette), &actualRead,NULL); //bail out is something went wrong if(!OK){CloseHandle(hfile); return FALSE;} //allocate memory for image data image_size=m_BMPFileInfo.biWidth*m_BMPFileInfo.biHeight; if(m_cImage)delete[]m_cImage; //dispose of any old space m_cImage=new BYTE[image_size]; //allocate new space if(!m_cImage){ //bail if alloc failed CloseHandle(hfile); return FALSE; } //round up line width to next multiple of 4 int width=(m_BMPFileInfo.biWidth+3)&~3; //read bmp image int i=0; //counter BYTE trash[4]; //to hold the trash at the end of each line int remainder=width-m_BMPFileInfo.biWidth; //width of trash while(OK&&iLock(NULL,&ddsd,DDLOCK_WAIT,NULL))) return FALSE; //calculate addresses and width dest=(BYTE*)ddsd.lpSurface; //destination src=m_cImage+ ((m_BMPFileInfo.biHeight-1)*m_BMPFileInfo.biWidth); //trim bmp if too wide if(m_BMPFileInfo.biWidth>ddsd.lPitch)src_width=ddsd.lPitch; else src_width=m_BMPFileInfo.biWidth; //move data to surface for(int i=0; iUnlock(NULL); return TRUE; } //draw BOOL CBmpFileReader::setpalette(LPDIRECTDRAWPALETTE palette){ PALETTEENTRY pe[COLORS]; //intermediate palette //construct pe[] for(int i=0; i.peRed=m_rgbPalette[i].rgbRed; //set red pe[i].peGreen=m_rgbPalette[i].rgbGreen; //set green pe[i].peBlue=m_rgbPalette[i].rgbBlue; //set blue } //load direct draw palette to surface palette->SetEntries(NULL,0,COLORS,pe); return TRUE; } ---------------------------------------------------------------- //ddsetup.cpp: directDraw setup and release //Copyright Ian Parberry, 1999 //Last updated May 22, 2000 //system includes #include <windows.h> #include <windowsx.h> #include <ddraw.h> //custom includes #include "defines.h" //globals extern LPDIRECTDRAW lpDirectDrawObject; //direct draw object extern LPDIRECTDRAWSURFACE lpPrimary; //primary surface extern LPDIRECTDRAWPALETTE lpPrimaryPalette; //its palette //helper functions LPDIRECTDRAWPALETTE CreatePalette(LPDIRECTDRAWSURFACE surface){ //create surface palette PALETTEENTRY pe[COLORS]; //new palette LPDIRECTDRAWPALETTE lpDDPalette; //direct draw palette //construct pe[], set to black for(int i=0; i CreatePalette(DDPCAPS_8BIT,pe,&lpDDPalette,NULL))) return NULL; //load direct draw palette to surface surface->SetPalette(lpDDPalette); return lpDDPalette; } //CreatePalette BOOL InitDirectDraw(HWND hwnd){ //direct draw initialization //create and set up direct draw object if(FAILED(DirectDrawCreate(NULL,&lpDirectDrawObject,NULL))) return FALSE; //set cooperative level if(FAILED(lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN))) return FALSE; //change screen resolution if(FAILED(lpDirectDrawObject-> SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,COLOR_DEPTH))) return FALSE; //create the primary surface DDSURFACEDESC ddsd; //direct draw surface descriptor ddsd.dwSize=sizeof(ddsd); ddsd.dwFlags=DDSD_CAPS; ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE; if(FAILED(lpDirectDrawObject-> CreateSurface(&ddsd,&lpPrimary,NULL))) return FALSE; //create its palette lpPrimaryPalette=CreatePalette(lpPrimary); return TRUE; } //InitDirectDraw long CALLBACK WindowProc(HWND hwnd,UINT message, WPARAM wParam,LPARAM lParam); //windows system functions HWND CreateDefaultWindow(char* name,HINSTANCE hInstance){ WNDCLASS wc; //window registration info //register display window wc.nostyle=CS_HREDRAW|CS_VREDRAW; //style wc.lpfnWndProc=WindowProc; //window message handler wc.cbClsExtra=wc.cbWndExtra=0; wc.hInstance=hInstance; wc.hIcon=LoadIcon(hInstance,IDI_APPLICATION); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=NULL; wc.lpszMenuName=NULL; wc.lpszClassName=name; RegisterClass(&wc); //create and set up fullscreen window return CreateWindowEx(WS_EX_TOPMOST,name,name, WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),NULL,NULL,hInstance,NULL); } those are the .cpp files ill also give the headers //bmp.h: header file for the bmp file reader //Copyright Ian Parberry, 1999 //Last updated September 2, 1999 #include <windows.h> #include <windowsx.h> #include <ddraw.h> #include "defines.h" #ifndef __bmp_h__ #define __bmp_h__ class CBmpFileReader{ //bmp file input class protected: BITMAPFILEHEADER m_BMPFileHead; //bmp header BITMAPINFOHEADER m_BMPFileInfo; //bmp file information RGBQUAD m_rgbPalette[COLORS]; //the palette BYTE *m_cImage; //the image public: CBmpFileReader(); //constructor ~CBmpFileReader(); //destructor BOOL load(char *filename); //load from file BOOL draw(LPDIRECTDRAWSURFACE surface); //draw image BOOL setpalette(LPDIRECTDRAWPALETTE palette); //set palette }; #endif ----------------------------------------------------------------- //defines.h: essential defines //Copyright Ian Parberry, 1999 //Last updated April 3, 2000 #ifndef __DEFINES_H__ #define __DEFINES_H__ #define SCREEN_WIDTH 640 //pixels wide #define SCREEN_HEIGHT 480 //pixels high #define COLORS 256 //number of colors #define COLOR_DEPTH 8 //number of bits to store colors #endif lol i know its alot but i want to get this dxthing the f over with ok i get this linker error: [Linker Fatal Error] Fatal: Unable to open file ''ODBCCP32.LIB'' and there is no lib for the odbccp32 in the borland .libs files i have it in vc++ but i dont know how to use implib and i dont know if converting it with imp lib render it unable to use any posible file it itself may need to call on. pls help im desperat ive been workin on this for sum years and it means my job! now thx ahead of thime

Share this post

Link to post
Share on other sites