Advertisement

I've got a gun pointed at my computer, give me a reason to stop

Started by May 21, 2000 12:26 AM
44 comments, last by JwayneT 24 years, 6 months ago
Yeah,

The school computers use MSVC++. And I got the Exact same error. Remember that mine is DDrawExp2.cpp

a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
Something that might be messing you up is this.
Microsoft "forgot" to put everything into the Borland libraries of DirectX. I have a Borland C Builder but I never use it b/c I dont know what will and what wont work with DirectX. However, everything is supported in MSVC because microsoft makes it but doesn''t make Borland Compilers. Messed up isn''t it ?
Advertisement
Y''know,

I thought so too, untill I found some of the DDraw examples that Borland supplied. They all worked, they all use Direct X ddraw, and my code is the same for initialization?!?!?!?!?!?!

a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
ncsu121978: That is not true. As I said before, the actual DX object functions are not found in the libs distributed with DX. The only things that could possibly be "forgotten" are the DirectDrawCreate functions and their ilk. Those types of functions are COMPLETELY UNNECESSARY to use DX. As long as you can properly create the object, it's not going to suddenly crash on you or sprout bugs when you call certain functions because of a bug in the libs. The libs don't contain any kind of linking with the DX DLLs outside of the unnecessary creation code.


To everyone here: You don't need ANY libs to use DX!


JwayneT: I think I know now exactly what happened. When you passed one of those structs to DirectDraw without filling it with zeros, it gave you back an error: DDERR_INVALIDPARAMS. Then your InitFail() code was called and eventually the TFormMain or whatever it is was destroyed. The destructor tried to make sure whether the pointers were non-NULL first, and then Release() the DX objects. This is a very good approach and makes it easy to debug DX programs, but unfortunately it will not work the way you have it set up. You must set the pointers to NULL in the form's constructor, because they contain random data until you initialize them. That is, they will be non-NULL from the beginning. The access violation occurred when you attempted to Release() the DX objects.

The whole idea behind NULL pointers is that you keep them NULL when they are not valid, and conversely non-NULL when they are valid. That way, you know exactly which pointers are valid without having to dig deep into the code.


There is no way that the DX DLLs would not work with a Borland compiler -- that is just an illusion. The DLLs that DirectDraw uses only use C-style linking because they are COM, and other languages that support COM should have no trouble compiling. I still recommend against using the DirectDrawCreate function, as it may contain VC-specific code. I'm going to write an initialization routine for DirectDraw 7.0 from scratch using the COM functions. I want you to put this in your initialization code, remove the DX libs, and see if it does work in a Borland compiler. Oh, one more thing -- you need to #define INITGUID before including any DX headers, so that the headers themselves will define the GUIDs of the the DX objects.


// Initialize the standard COM libraries
if( FAILED( CoInitialize(NULL) ) )
{
InitFail();
return;
}

HRESULT ddrval;

// Create a DirectDraw7 object
ddrval = CoCreateInstance(&CLSID_DirectDraw, NULL, CLSCTX_ALL,
&IID_IDirectDraw7, &lpDD);

if( FAILED( ddrval ) )
{
InitFail();
return;
}

// Initialize the new object
ddrval = lpDD->Initialize(NULL);

if( FAILED( ddrval ) )
{
InitFail();
return;
}

// Get exclusive mode
ddrval = lpDD->SetCooperativeLevel(Handle, DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN );

if( FAILED( ddrval ) )
{
InitFail();
return;
}

// Set the video mode to 640x480x8
ddrval = lpDD->SetDisplayMode(640, 480, 8);

if( FAILED( ddrval ) )
{
InitFail();
return;
}

// Create the primary surface with 1 back buffer
DDSURFACEDESC2 ddsd;
memset(&ddsd, 0, sizeof( DDSURFACEDESC2 ));

ddsd.dwSize = sizeof( DDSURFACEDESC2 );
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( FAILED( ddrval ) )
{
InitFail();
return;
}

DDSCAPS ddscaps;
memset(&ddsd, 0, sizeof( DDSCAPS2 ));

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
ddrval = lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack);

if( FAILED( ddrval ) )
{
InitFail();
return;
}

/* You are on your own here -- I don't use palettes */

// create and set the palette
lpDDPal = DDLoadPalette(lpDD, szBitmap);

if (lpDDPal)
lpDDSPrimary->SetPalette(lpDDPal);

// Create the offscreen surface, by loading our bitmap.
lpDDSOne = DDLoadBitmap(lpDD, szBitmap, 0, 0);

if( lpDDSOne == NULL )
{
InitFail();
return;
}
// Set the color key for this bitmap (black)
DDSetColorKey(lpDDSOne, RGB(0,0,0));



Note that after you destroy the DX objects you should call CoUninitialize() to uninitialize the standard COM library.

BTW, none of the code you sent me is portable -- it contains Borland's own classes. It is the Borland equivalent of MFC. I would have to re-write the whole program to test it in VC. That wouldn't do either of us any good because the bug lies somewhere in your use of the Borland framework (and don't tell me the Borland framework is buggy).




- null_pointer
Sabre Multimedia


Edited by - null_pointer on June 1, 2000 8:13:26 AM

Edited by - null_pointer on June 1, 2000 8:14:23 AM
I don''t know if something happend in the transmition of the attachment or something? This is my code.
//----------------------------------------------------------
#include <>
#include <>
#include <>
#include <>
HWND globalhwnd;
#define Width 640
#define Height 480
#define INITGUID
LPDIRECTDRAW lpdd;
LPDIRECTDRAWSURFACE lpddsprimary, lpddsback;
DDSURFACEDESC ddsd;
DDSCAPS ddsCaps;

LRESULT CALLBACK WndProc(HWND,unsigned int,unsigned int,LONG);

void error(int v)
{
fstream file;
file.open("d:\error.txt",ios::app,0);
switch(v)
{
case 1:
file<<"error in initializing object...\n";
break;
case 2:
file<<"error in setting to fullscreen exclusive...\n";
break;
case 3:
file<<"error in setting display mode...\n";
break;
case 4:
file<<"error in setting primary surface...\n";
break;
case 5:
file<<"error in setting back surface...\n";
break;
default:break;
};
file.close();
return;
};

initialize_ddraw()
{
HRESULT ddval;
ddval=DirectDrawCreate(NULL,&lpdd,NULL);
if(!(ddval==DD_OK)){error(1);};//create the DirectDraw object
ddval=lpdd->SetCooperativeLevel(globalhwnd,DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN);
if(!(ddval==DD_OK)){error(2);};//get it fullscreen and hopefully exclusive
ddval=lpdd->SetDisplayMode(Width,Height,8);
if(!(ddval==DD_OK)){error(3);};//set the display mode
ddsd.dwSize = sizeof(ddsd);//this is th ddraw surface description structure for flipping surfaces
ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;//what types of surfaces that will be created
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;//the three sufaces
ddsd.dwBackBufferCount = 1;//this is the surface where all of the sprites are drawn and fliped to the primary
ddval=lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);//create the ddraw primary surface
if(!(ddval==DD_OK)){error(4);};
ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
ddval=lpddsprimary->GetAttachedSurface(&ddsCaps,&lpddsback);
if(!(ddval==DD_OK)){error(5);};//creates ddraw back surface
return 0;
};//this function will initialize both ddraw surfaces and pointers to as well

destroy_ddraw()
{
if(lpddsprimary)lpddsprimary->Release();
if(lpddsback)lpddsback->Release();
if(lpdd)lpdd->Release();
return 0;
};//destroys all of the surfaces after use


WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hPrevInstance;
HWND hwnd;
MSG message;
WNDCLASS wndclass;
wndclass.cbClsExtra =0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=GetStockObject(4);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(hInstance,NULL);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="DDrawExp";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW / CS_VREDRAW;
if (!RegisterClass(&wndclass))
return 0;
globalhwnd=CreateWindow("DDrawExp","DDrawExp ver 0.0",WS_OVERLAPPEDWINDOW,0,0,Width,Height,NULL,NULL,hInstance,NULL);
HACCEL hAccel=LoadAccelerators(hInstance,NULL);
ShowWindow(globalhwnd,nCmdShow);
initialize_ddraw();
while(GetMessage(&message,hwnd,0,0))
{//game main here
TranslateMessage(&message);
DispatchMessage(&message);
};
destroy_ddraw();
return message.wParam;
};

LRESULT CALLBACK WndProc(HWND hwnd, unsigned int imessage,unsigned int wparam,LONG lparam)
{imessage;return 0;};
//----------------------------------------------------------
But what code you posted I will probably try tonight, and thanks for all the help so far. I know I''ve been real tireless with all of my problems, and I''m surprize I haven''t been kicked off. I wish I could contribute something in return.




a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
Crap!!! My includes were ddraw.h,dinput.h,windows.h,fstream.h in order. Sorry!!

a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
Advertisement
I tried your code, and I got access violations on lpDD->Initialize(NULL).

a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]
Sometimes Borland''s products are funky. I had Turbo C++ 4.5 by Borland, and everytime I tried to make an array of structs it crashed. Used the exact same source in MS Visual C and Borland C++ 5.0 and the code was fine. Hmmm..
JwayneT: I don''t know why you would have gotten an access violation on lpDD->Initialize(NULL) if CoCreateInstance succeeded... Can you send me your updated source? Perhaps I can get it to work somehow...



- null_pointer
Sabre Multimedia
Here ya go!

initialize_ddraw()
{
HRESULT ddval;
memset(&ddsd,0,sizeof(DDSURFACEDESC));
memset(&ddsCaps,0,sizeof(DDSCAPS));
//ddval=DirectDrawCreate(NULL,&lpdd,NULL);
ddval=CoCreateInstance(CLSID_DirectDraw,NULL,CLSCTX_ALL,IID_IDirectDraw7,(void**)lpdd);
ddval=lpdd->Initialize(NULL);
if(!(ddval==DD_OK)){error(1);};
ddval=lpdd->SetCooperativeLevel(globalhwnd,DDSCL_EXCLUSIVE / DDSCL_FULLSCREEN);
if(!(ddval==DD_OK)){error(2);};
ddval=lpdd->SetDisplayMode(Width,Height,8);
if(!(ddval==DD_OK)){error(3);};
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS / DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE / DDSCAPS_FLIP / DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
ddval=lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);
if(!(ddval==DD_OK)){error(4);};
ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
ddval=lpddsprimary->GetAttachedSurface(&ddsCaps,&lpddsback);
if(!(ddval==DD_OK)){error(5);};//creates ddraw back surface
ddval=lpdd->CreatePalett(DDPCAPS_8BIT,NULL,&ddpal,NULL);
return 0;
};

When I use cocreateinstance I get to the underlined part of my code before access violation. When I use directdrawcreate I get to the bold.



a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Ever notice how Evil spelled backward is Live?

-=CF=-
a.h{text-decoration:none;color:blue;};a.h:hover{text-decoration:underline;background:red;};

Why is it called a hot water heater? Isn't it cold when it goes in the tank?

[email=jtaylor@gtemail.net" class="h]-=CF=-[/email]

This topic is closed to new replies.

Advertisement