i have a problem compiling a basic program, that just initializes directdraw 7.
the problems are marked in the code:
// directdrawer.cpp -> direct draw engine
// a1.0 - 05.01.2004
#define WIN32_LEAN_AND_MEAN // MFC-includes are being cut for faster compiling
#define INITGUID // include all GUIDs
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <ddraw.h>
#include "directdrawer.h"
// EXTERNALS ///////////////////////////////////////////////////////
/*extern HWND hwnd_main; // THESE MUST BE GLOBALS IN THE MAIN SOURCE FILE
extern HINSTANCE hinstance_main; // AND HOLD THE MAIN APP INSTANCE AND WINDOW HANDLE
*/
// GLOBALS /////////////////////////////////////////////////////////
LPDIRECTDRAW7 lpdd = NULL; //pointer for DirectDraw interface 7
// FUNCTIONS ///////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// CREATEDIRECTDRAWER //////////////////////////////////////////////
int CreateDirectDrawer(void)
{
// initialize COM
if(FAILED(CoInitialize(NULL)))
{ MessageBox(NULL, "CoInitialize() FAILED", "ERROR - directdrawer.cpp", MB_OK);
return(1); }
// get DirectDraw interface 7
if(FAILED(CoCreateInstance(CLSID_DirectDraw,
NULL,
CLSCTX_ALL,
IID_IDirectDraw7, ////////////////////////////////////////////////////////////////
(LPVOID*)&lpdd))) //if i don''t cast this (in the "tricks..."-book it is not casted),
//then i get a typecasting error.
//but... (look further down)
////////////////////////////////////////////////////////////////
{ MessageBox(NULL, "CoCreateInstance() for Direct Draw 7 FAILED", "ERROR - directdrawer.cpp", MB_OK);
return(2); }
// initialize the interface
if(FAILED(lpdd->Initialize(NULL)))
{ MessageBox(NULL, "IDirectDraw7_Initialize() FAILED", "ERROR - directdrawer.cpp", MB_OK);
return(3); }
//uninitialize COM
CoUninitialize();
return(0);
}//end: CreateDirectDrawer()
// SETCOOP /////////////////////////////////////////////////////////
int SetCoop(HWND hwnd, BOOL fullscreen)
{
if(fullscreen) //test if user requested fullscreen cooperative mode
{
//set cooperative level
if(FAILED(lpdd->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE |
DDSCL_ALLOWMODEX |
DDSCL_ALLOWREBOOT)))
{ MessageBox(NULL, "SetCooperativeLevel() FAILED", "ERROR - directdrawer.cpp", MB_OK);
return(1); }
}
else
{
//set cooperative level //////////////////////////////////////////////////////////////////////////
if(FAILED(lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL))) //during runtime is get an acces violation here, the error code is CXX0030
{ MessageBox(NULL, "SetCooperativeLevel() FAILED", "ERROR - directdrawer.cpp", MB_OK); //the error is somehow caused by lpdd. i think it is related to the typecast above...
return(1); } //////////////////////////////////////////////////////////////////////////
}
return(0);
}//end: SetCoop(...)
// CLEANUPDRAWER
int CleanupDrawer(void)
{
if(lpdd)
{ lpdd->Release();
lpdd = NULL; }
//TODO: release all other stuff that will be added.
return(0);
}
her are directdrawer.h and the main source file, if you want to compile it yourself:
//directdrawer.h -> header für directdrawer.cpp - direct draw engine
//a1.0
#ifndef DRAWER_H
#define DRAWER_H
#include <ddraw.h>
// EXTERNALS ///////////////////////////////////////////////////////
extern LPDIRECTDRAW7 lpdd; //pointer for DirectDraw interface 7
// PROTOTYPES //////////////////////////////////////////////////////
int CreateDirectDrawer(void);
int SetCoop(HWND hwnd, BOOL fullscreen);
int CleanupDrawer(void);
#endif
// emptyprog.cpp - leeres windows programmgeruest (oeffnet fenster)
#define WIN32_LEAN_AND_MEAN // MFC-includes are being cut for faster compiling
// INCLUDES ////////////////////////////////////////////////////////
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ddraw.h>
#include "directdrawer.h"
// GLOBALS /////////////////////////////////////////////////////////
HWND hwnd_main = NULL; //global window handle
HINSTANCE hinstance_main = NULL; //global application instance
extern LPDIRECTDRAW7 lpdd; //pointer for DirectDraw interface 7
// PROTOTYPES //////////////////////////////////////////////////////
// WINPROC /////////////////////////////////////////////////////////
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam)
{
PAINTSTRUCT ps; //can be used in WM_PAINT
HDC hdc; //handle to a device context - "
//check message
switch(msg)
{
case WM_PAINT:
{
hdc = BeginPaint(hwnd, &ps);
//do the painting here
EndPaint(hwnd,&ps);
return(0);
}break;
case WM_DESTROY:
{
PostQuitMessage(NULL);
}
default:break;
}//end: switch(msg)
return(DefWindowProc(hwnd, msg, wparam, lparam)); //process any message that i didn''t mention
}//end: WindowProc(...)
// WINMAIN /////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
{
WNDCLASSEX winclass; //windows class
HWND hwnd;
MSG msg; //msg for the WinProc
BOOL exit_loop = FALSE; //for main event loop
//fill in class data
winclass.cbSize = sizeof(winclass);
winclass.style = CS_DBLCLKS | CS_OWNDC | // (no "close" button -> //CS_NOCLOSE |
CS_HREDRAW | CS_VREDRAW;
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = "
WINCLASS";
winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
hinstance_main = hinstance;
if(!RegisterClassEx(&winclass)) //register the class
return(MessageBox(NULL, "could not register WNDCLASSEX winclass\nRegisterClassEx() failed", "ERROR", MB_OK));
if(!(hwnd = CreateWindowEx(NULL, //extended style
"WINCLASS", //clss
"fill in program title", //window title
WS_OVERLAPPEDWINDOW | WS_VISIBLE, //style
0,0, //x,y position
400,400, //width,height
NULL, //handle to parent window
NULL, //handle to menu
hinstance, //application instance
NULL))) //extra creation parameters
return(MessageBox(NULL, "could not create window\nCreateWindowEx() failed", "ERROR", MB_OK));
hwnd_main = hwnd;
CreateDirectDrawer();
SetCoop(hwnd, FALSE);
// MAIN EVENT LOOP //
while(!exit_loop)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) //test for message in queue
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//TODO: main game processing
}//end: while(!exit_loop)
CleanupDrawer();
return(msg.wParam);
}//end: WinMain(...)
thanks for taking a look!
bony
if you found any spelling errors, you may keep them.
:) if you found any spelling errors, you may keep them. :)