Jump to content
  • Advertisement

Archived

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

jimiwa

need help with direct draw

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

I posted this before but only got one reply which didn''t help, so I''m posting it again. I am not getting any compile errors with my code but I am getting a windows error. My error says: An unhandled exception of type ''System.NullReferenceException'' occurred in game.exe Additional information: Object reference not set to an instance of an object I am working in visual studio.net I first get a window that pops up and then the error pops up. The program does not go into full screen mode. here''s the code: #include <windows.h> #include <windowsx.h> #include <ddraw.h> #define WIN32_LEAN_AND_MEAN HWND hwnd; LPDIRECTDRAW lpdd = NULL; LPDIRECTDRAW7 lpdd7 = NULL; LPDIRECTDRAWSURFACE lpdds1 = NULL; LPDIRECTDRAWSURFACE lpdds2 = NULL; DDSURFACEDESC ddsd; int openg(); int closeg(); int main() { openg(); closeg(); return 0; } int openg() { if (FAILED(DirectDrawCreateEx(NULL, (LPVOID* )&lpdd, IID_IDirectDraw7, NULL))) { exit(100); } if (FAILED(lpdd7->SetCooperativeLevel(hwnd,DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) { exit(101); } if (FAILED(lpdd7->SetDisplayMode(1024,768, 32, 0, 0))) { exit(102); } return 0; } int closeg() { return 0; }

Share this post


Link to post
Share on other sites
Advertisement
even though you don't have a surface initialized you still have to deallocate the the object to DirectDraw (ie. lpDD).

try this:

int closeg()
{
if (lpDD != NULL)
lpDD->Release();

return 0;
}


edit:

also do you have this setup in in int Main () or int WINAPI WinMain(..., ..., ..., ...)?

from the look of what you have you'll gonna get a number of errors.

look at this for the correct setup.

edit2: here's an example source

#include <windows.h>
#include <windowsx.h>
#include <ddraw.h>

//defines

#define WIN32_LEAN_AND_MEAN
#define WNDCLASSNAME "GameWindowClass"
#define GAME_RES_X 640
#define GAME_RES_Y 480
#define GAME_BITDEPTH 8;

//declare function


LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
int InitDDraw();
int DeInitDDraw();
int Game_Main();

//GLOBALS

HWND hWnd;

LPDIRECTDRAW lpdd7 = NULL;
LPDIRECTDRAWSURFACE2 lpddsPrimary = NULL;

//ENTRY POINT

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
WNDCLASSEX wndclass;
MSG msg;

wndclass.cbSize = sizeof(WNDCLASSEX);
wndclass.style = CS_HREDRAW | CS_VREDRAW |
CS_DBLCLKS | CS_OWNDC;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = WNDCLASSNAME;
wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


//Register Class

if (!RegisterClassEx(&wndclass))
{
MessageBox(hWnd,"Error registering Class","Error",MB_OK);
return (0);

}

//Create Window

if (!(hWnd=CreateWindowEx(NULL, WNDCLASSNAME, "Init DirectDraw",
WS_POPUP | WS_VISIBLE,
0,0,
GAME_RES_X,GAME_RES_Y,
NULL,NULL,
hInstance,
NULL)))
{
MessageBox(hWnd,"Error Creating Window","Error",MB_OK);
return (0);
}

//Init DirectDraw

InitDDraw();

//MAIN LOOP

while (TRUE)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{

if (msg.message==WM_QUIT)
{
PostQuitMessage(0);
return (0);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//this is where the actual game will loop

Game_Main();
}
//DeInit DirectDraw



return (msg.wParam);
}


LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case (WM_CLOSE):
{

if (MessageBox(hWnd, "Really Quit", "Quit",MB_YESNO | MB_ICONQUESTION))
return (0);

}
case (WM_KEYDOWN):
{
if (wParam==VK_ESCAPE)
{
PostQuitMessage(0);
return (0);
}
}
case (WM_DESTROY):
{
PostQuitMessage(0);
return (0);
}

}
return (DefWindowProc(hWnd, msg, wParam, lParam));
}


int InitDDraw()
{
if (FAILED(DirectDrawCreateEx(NULL, (LPVOID* )&lpdd7,IID_IDirectDraw7,NULL)))
return (0);
if (FAILED(lpdd7->SetCooperativeLevel(hWnd,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)))
return (0);
if (FAILED(lpdd7->SetDisplayMode(GAME_RES_X,GAME_RES_Y,GAME_BITDEPTH,0,0)))
return (0);
return (1);
}

[edited by - Alpha_ProgDes on September 22, 2003 1:18:01 PM]


[edited by - Alpha_ProgDes on September 22, 2003 1:23:54 PM]

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!