Archived

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

Why does calling DX froma a dll crash ?

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

This question is really driving me mad! I''ve just moved some code from a exe to a dll to make it reusable, as a freeware 3d engine, and I think windows is moving stuff around as It runs, all it does is flip the buffers, and after a few seconds of this crash. Is there a paticular way that I have to declare my functions? or is something in the .def file wrong? my .def file: LIBRARY FNZ3DDX CODE PRELOAD DISCARDABLE DATA PRELOAD SINGLE EXPORTS DisplayInfo @1 START_R3D @2 KILL_R3D @3 Flip_Buffers @4 That''s it! how do I tell windows not to move code / data on me? - Anthony

Share this post


Link to post
Share on other sites
You must be doing something wrong because the code I am writing right now is in a DLL and calls DirectX.

You need to show some of your code in the DLL and how you import/export it.

But first one important question: Do you use MFC?

Jacob Marner

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Solution:
use __declspec(dllexport) and __declspec(dllimport) instead of a DEF file. Save yourself the trouble!

Share this post


Link to post
Share on other sites
quote:
Original post by felonius
You need to show some of your code in the DLL


//Here you go...


#include
#include
#include
#include

void WriteDebug(char *m);
extern "C"{
void Flip_Buffers();
static HRESULT WINAPI surfacechooser( LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID lpContext);


HWND dxwin;
LPDIRECTDRAW7 myyyyy;
static LPDIRECTDRAWSURFACE7 frontsurf;
LPDIRECTDRAWSURFACE7 backsurf;
LPDIRECTDRAWSURFACE7 zsurf;
LPDIRECT3DDEVICE7 d3dd;
LPDIRECT3D7 d3di;
BOOL See;
int bar;

static HRESULT CALLBACK zbcb(DDPIXELFORMAT* pddpf, void * pddpfDesired )
{
if (pddpf->dwFlags == DDPF_ZBUFFER )
{

memcpy( pddpfDesired, pddpf, sizeof(DDPIXELFORMAT) );
// Return with D3DENUMRET_CANCEL to end the search.
return D3DENUMRET_CANCEL;

}
return D3DENUMRET_OK;
}

void evaluate(LPDDSURFACEDESC2 lpDDSurfaceDesc)
{
char scm[100];

WriteDebug("\n\n Evaluating a surface!!\n");
//sprintf(scm,"%");
if ((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Width: %d\n",lpDDSurfaceDesc->dwWidth);
WriteDebug(scm);

}


if ((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Height: %d\n",lpDDSurfaceDesc->dwHeight);
WriteDebug(scm);
}

if ((lpDDSurfaceDesc->dwFlags & DDSD_PITCH ) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Pitch per line Size: %d\n",lpDDSurfaceDesc->lPitch);
WriteDebug(scm);
}

if ((lpDDSurfaceDesc->dwFlags & DDSD_CAPS ) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_3DDEVICE )
{
WriteDebug("Can Be Written to by 3d device\n");
}
else
{
WriteDebug("CANNOT be Written to by 3d device\n");
}

if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)
{
WriteDebug("Is A Backbuffer\n");
}
else
{
WriteDebug("is NOT a backbuffer\n");
}


if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FLIP )
{
WriteDebug("Is A DDSCAPS_FLIP \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_FLIP \n");
}



if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
{
WriteDebug("Is A DDSCAPS_FRONTBUFFER \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_FRONTBUFFER \n");
}

if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
WriteDebug("Is A DDSCAPS_SYSTEMMEMORY \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_SYSTEMMEMORY\n");
}


if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY )
{
WriteDebug("Is A DDSCAPS_VIDEOMEMORY \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_VIDEOMEMORY \n");
}

WriteDebug("Finished the surface...\n");
WriteDebug("\n\n");
}

}




HRESULT WINAPI surfacechooser( LPDIRECTDRAWSURFACE7 lpDDSurface, LPDDSURFACEDESC2 lpDDSurfaceDesc,LPVOID lpContext)
{
char scm[100];
WriteDebug("\n\n Suitable Surface Found!!\n");
//sprintf(scm,"%");
if ((lpDDSurfaceDesc->dwFlags & DDSD_WIDTH) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Width: %d\n",lpDDSurfaceDesc->dwWidth);
WriteDebug(scm);

}


if ((lpDDSurfaceDesc->dwFlags & DDSD_HEIGHT) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Height: %d\n",lpDDSurfaceDesc->dwHeight);
WriteDebug(scm);
}

if ((lpDDSurfaceDesc->dwFlags & DDSD_PITCH ) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
sprintf(scm,"Pitch per line Size: %d\n",lpDDSurfaceDesc->lPitch);
WriteDebug(scm);
}

if ((lpDDSurfaceDesc->dwFlags & DDSD_CAPS ) ||(lpDDSurfaceDesc->dwFlags & DDSD_ALL))
{
if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_3DDEVICE )
{
WriteDebug("Can Be Written to by 3d device\n");
}
else
{
WriteDebug("CANNOT be Written to by 3d device\n");
}

if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_BACKBUFFER)
{
WriteDebug("Is A Backbuffer\n");
}
else
{
WriteDebug("is NOT a backbuffer\n");
}


if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FLIP )
{
WriteDebug("Is A DDSCAPS_FLIP \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_FLIP \n");
}



if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
{
WriteDebug("Is A DDSCAPS_FRONTBUFFER \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_FRONTBUFFER \n");
}

if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
{
WriteDebug("Is A DDSCAPS_SYSTEMMEMORY \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_SYSTEMMEMORY\n");
}


if (lpDDSurfaceDesc->ddsCaps.dwCaps & DDSCAPS_VIDEOMEMORY )
{
WriteDebug("Is A DDSCAPS_VIDEOMEMORY \n");
}
else
{
WriteDebug("is NOT a DDSCAPS_VIDEOMEMORY \n");
}

}

WriteDebug("Cloning the surface...\n");
//memcpy(lpContext,lpDDSurfaceDesc,sizeof(dadsd));
memcpy( lpContext, lpDDSurfaceDesc, sizeof(DDSURFACEDESC2) );
WriteDebug("\n\n");

return DDENUMRET_OK;
}



void DisplayInfo();

BOOL WINAPI DllEntryPoint (HINSTANCE hDLL, DWORD dwReason, LPVOID reserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
{

MessageBox(0, "This software features the FonzyCo 3D Engine","FNZ3DLIB",MB_OK);
break;
}

case DLL_PROCESS_DETACH:
{
MessageBox(0, "This software used the FonzyCo 3D Engine","FNZ3DLIB",MB_OK);
break;
}
}

return TRUE;

}

void DisplayInfo()
{
MessageBox(0, "FonzyCo 3D Engine DirectX Version\nCopyright ©2000 Anthony Graham\n\n\nFonzyCo\nhttp://www.fonzyco.co.uk","FNZ3DLIB",MB_OK);
}

DDSURFACEDESC2 sparesd;
DDSURFACEDESC2 dadsd;
DDSURFACEDESC2 zbsd;
DDSCAPS2 ddscaps;
LPDIRECTDRAWCLIPPER pcClipper;
DDPIXELFORMAT zbpf;
D3DVIEWPORT7 ViewPor;
/*
HRESULT START_R3D(HWND hWnd,int sswidth, int ssheight)
{

//PrepareDebug();

ShowCursor(FALSE);
HRESULT hr;
dxwin=hWnd;
hr=DirectDrawCreateEx(NULL, (void **)&myyyyy, IID_IDirectDraw7, NULL);
//hr=DirectDrawCreateEx((GUID FAR *)DDCREATE_EMULATIONONLY ,(void **)&myyyyy, IID_IDirectDraw7, NULL);
if (FAILED(hr))
{
WriteDebug("DDCEx x\n");
return hr;
}
else
{
WriteDebug("DDCEx v\n");
}


hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hr!=DD_OK)
{

return hr;
}
else
{
}


hr = myyyyy->SetDisplayMode(sswidth, ssheight, 16,0,0);
if (FAILED(hr))
{
return hr;
}
else
{

}

//hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hr!=DD_OK)
{
return hr;
}
else
{

}





//// creating surface description
ZeroMemory(&dadsd,sizeof(DDSURFACEDESC2));
dadsd.dwSize = sizeof(DDSURFACEDESC2);
dadsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
dadsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
dadsd.dwBackBufferCount = 1;

sparesd.dwSize = sizeof(DDSURFACEDESC2);
sparesd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
sparesd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
sparesd.dwBackBufferCount = 1;

WriteDebug("spare SD:\n");
evaluate(&sparesd);
WriteDebug("\n\n\n");

WriteDebug("dadsd SD:\n");
evaluate(&dadsd);
WriteDebug("Enumerating Surfaces\n");


myyyyy->EnumSurfaces(DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH,
&sparesd,
&dadsd,
surfacechooser);


dadsd.dwSize = sizeof(DDSURFACEDESC2);
dadsd.dwFlags &= DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
dadsd.ddsCaps.dwCaps &= DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
// Un comment these 2 lines to force software mode


// dadsd.ddsCaps.dwCaps &= DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY;
// dadsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;


if (dadsd.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
{
dadsd.ddsCaps.dwCaps ^= DDSCAPS_FRONTBUFFER;
}

dadsd.dwBackBufferCount = 1;
evaluate(&dadsd);
//// EO surface description
WriteDebug("Attempting To Create Primary Surface\n");
//// creating front surface


hr = myyyyy->CreateSurface(&dadsd, &frontsurf, NULL);
if(hr == DD_OK)
{
WriteDebug("CS(F) OKAY\n");
}
else
{
WriteDebug("CS(F) FAIL\n");
switch(hr)
{
case DDERR_INCOMPATIBLEPRIMARY:
WriteDebug("DDERR_INCOMPATIBLEPRIMARY\n");
break;
case DDERR_INVALIDCAPS :
WriteDebug("DDERR_INVALIDCAPS \n");
break;
case DDERR_INVALIDOBJECT :
WriteDebug("DDERR_INVALIDOBJECT \n");
break;
case DDERR_INVALIDPARAMS :
WriteDebug("DDERR_INVALIDPARAMS \n");
break;
case DDERR_INVALIDPIXELFORMAT :
WriteDebug("DDERR_INVALIDPIXELFORMAT \n");
break;
case DDERR_NOALPHAHW :
WriteDebug("DDERR_NOALPHAHW \n");
break;
case DDERR_NOCOOPERATIVELEVELSET :
WriteDebug("DDERR_NOCOOPERATIVELEVELSET \n");
break;
case DDERR_NODIRECTDRAWHW :
WriteDebug("DDERR_NODIRECTDRAWHW \n");
break;
case DDERR_NOEMULATION :
WriteDebug("DDERR_NOEMULATION \n");
break;
case DDERR_NOEXCLUSIVEMODE :
WriteDebug("DDERR_NOEXCLUSIVEMODE \n");
break;

}
return hr;
}



//// EO creating front surface


//// Creating Back buffer


WriteDebug("Getting Attached backsurf\n");

ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hr = frontsurf->GetAttachedSurface(&ddscaps, &backsurf);
if(hr == DD_OK)
{
WriteDebug("CBS(F) OKAY\n");
}
else
{
WriteDebug("CBS(F) FAIL\n");
return 0;
}




hr = myyyyy->CreateClipper( 0, &pcClipper, NULL );
if( FAILED( hr ) )
{
WriteDebug("cliper FAIL\n");
}
else
{
WriteDebug("cliper OKAY\n");
}

// Assign it to the window handle, then set
// the clipper to the desired surface.
pcClipper->SetHWnd( 0, hWnd );
backsurf->SetClipper( pcClipper );
pcClipper->Release();

//// EO creating Back Buffer



hr=myyyyy->QueryInterface(IID_IDirect3D7, (void **)&d3di);
if (FAILED(hr))
{
WriteDebug("QI FAIL\n");

return hr;
}
else
{
WriteDebug("QI OKAY\n");

}



d3di->EnumZBufferFormats(IID_IDirect3DHALDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );
zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
//zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;
hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
if (FAILED(hr))
{
WriteDebug("create Surf FAILED");
}
else
{
WriteDebug("create Surf OKAY");
}
hr = backsurf->AddAttachedSurface(zsurf);
if (FAILED(hr))
{
WriteDebug("ADD ATTAChed Surf FAILED");
}
else
{
WriteDebug("add attach Surf OKAY");
}
hr=d3di->CreateDevice(IID_IDirect3DHALDevice, backsurf, &d3dd);
if (FAILED(hr))
{
WriteDebug("DEVICE CREATION FAILED");
backsurf->DeleteAttachedSurface(0,zsurf);
zsurf->Release();

d3di->EnumZBufferFormats(IID_IDirect3DMMXDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );

//zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
zbsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;

hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
hr = backsurf->AddAttachedSurface(zsurf);
hr=d3di->CreateDevice(IID_IDirect3DMMXDevice, backsurf, &d3dd);
if (FAILED(hr))
{
backsurf->DeleteAttachedSurface(0,zsurf);
zsurf->Release();
d3di->EnumZBufferFormats(IID_IDirect3DRGBDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );

//zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
zbsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;

hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
hr = backsurf->AddAttachedSurface(zsurf);

hr=d3di->CreateDevice(IID_IDirect3DRGBDevice, backsurf, &d3dd);
if (FAILED(hr))
{
return hr;
}
}
}


d3dd->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
d3dd->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
//d3dd->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS ,TRUE);
//d3dd->SetRenderState(D3DRENDERSTATE_ANTIALIAS,D3DANTIALIAS_SORTINDEPENDENT);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);

//FOR SOFTWARE
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
//d3dd->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE , FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESS );
//d3dd->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
d3dd->SetRenderState(D3DRENDERSTATE_SHADEMODE , D3DSHADE_FLAT );
d3dd->SetRenderState(D3DRENDERSTATE_COLORVERTEX , FALSE);
d3dd->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE );

//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);

//Make It Look Nice
d3dd->SetTextureStageState(0,D3DTSS_MAGFILTER ,D3DTFG_LINEAR);
d3dd->SetTextureStageState(0,D3DTSS_MINFILTER ,D3DTFN_LINEAR);

ViewPor.dwX=0;
ViewPor.dwY=0;
ViewPor.dwWidth=sswidth;
ViewPor.dwHeight=ssheight;
ViewPor.dvMinZ=0.0f;
ViewPor.dvMaxZ=1.0f;
WriteDebug("VP now\n");
hr=d3dd->SetViewport(&ViewPor);
if (FAILED(hr))
{
WriteDebug("VP FAIL\n");
return hr;
}
else
{
WriteDebug("VP OKAY\n");
}

See=TRUE;

return 0;

}
*/

HRESULT START_R3D(HWND hWnd,int sswidth, int ssheight)
{
//PrepareDebug();
ShowCursor(FALSE);
HRESULT hr;
dxwin=hWnd;


WriteDebug("Creating Direct Draw Interface...\n");


hr=DirectDrawCreateEx(NULL, (void **)&myyyyy, IID_IDirectDraw7, NULL);
//hr=DirectDrawCreateEx((GUID FAR *)DDCREATE_EMULATIONONLY ,(void **)&myyyyy, IID_IDirectDraw7, NULL);
if (FAILED(hr))
{

WriteDebug("Failed to Create DDI\n");

return hr;
}
else
{

WriteDebug("DDI Created!\n");

}


hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hr!=DD_OK)
{

WriteDebug("SetCooperativeLevel Failed!!!!!!\n");

return hr;
}
else
{
WriteDebug("SetCooperativeLevel Okay\n");
}




WriteDebug("Setting Display Mode...\n");
hr = myyyyy->SetDisplayMode(sswidth, ssheight, 16,0,0);
if (FAILED(hr))
{
WriteDebug("Set Display Mode Failed\n");
return hr;
}
else
{
WriteDebug("Set Display Mode Suceeded\n");
}

//hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
hr=myyyyy->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if (hr!=DD_OK)
{

WriteDebug("SetCooperativeLevel Failed!!!!!!\n");
return hr;
}
else
{
WriteDebug("SetCooperativeLevel Okay\n");
}





//// creating surface description


//ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
dadsd.dwSize = sizeof(DDSURFACEDESC2);
dadsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
dadsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY;
dadsd.dwBackBufferCount = 1;

DDSURFACEDESC2 sparesd;
sparesd.dwSize = sizeof(DDSURFACEDESC2);
sparesd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
sparesd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
sparesd.dwBackBufferCount = 1;



myyyyy->EnumSurfaces(DDENUMSURFACES_CANBECREATED | DDENUMSURFACES_MATCH,
&sparesd,
&dadsd,
surfacechooser);


dadsd.dwSize = sizeof(DDSURFACEDESC2);
dadsd.dwFlags &= DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
dadsd.ddsCaps.dwCaps &= DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_VIDEOMEMORY | DDSCAPS_SYSTEMMEMORY;
// Un comment these 2 lines to force software mode

/*
dadsd.ddsCaps.dwCaps &= DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE | DDSCAPS_SYSTEMMEMORY;
dadsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
*/

if (dadsd.ddsCaps.dwCaps & DDSCAPS_FRONTBUFFER)
{
dadsd.ddsCaps.dwCaps ^= DDSCAPS_FRONTBUFFER;
WriteDebug("Fixing the set stuff\n");
}

dadsd.dwBackBufferCount = 1;
evaluate(&dadsd);
//// EO surface description
//WriteDebug("Attempting To Create Primary Surface\n");
//// creating front surface

//MessageBox( 0, "Attempting To Create Priamry Surface", "DXprog", MB_OK);
WriteDebug("Attempting To Create Primary Surface...\n");


hr = myyyyy->CreateSurface(&dadsd, &frontsurf, NULL);
if(hr == DD_OK)
{

WriteDebug("Create Primary Surface Okay!\n");
//MessageBox( 0, "Created Surface Okay", "DXprog", MB_OK);


}
else
{

WriteDebug("Pri surface not generated, Error: ");

switch (hr)
{
case DDERR_INCOMPATIBLEPRIMARY:
WriteDebug("DDERR_INCOMPATIBLEPRIMARY");
break;

case DDERR_INVALIDCAPS:
WriteDebug( "DDERR_INVALIDCAPS");
break;
case DDERR_INVALIDOBJECT:
WriteDebug("DDERR_INVALIDOBJECT");
break;
case DDERR_INVALIDPARAMS:
WriteDebug("DDERR_INVALIDPARAMS ");
break;
case DDERR_NOALPHAHW:
WriteDebug("DDERR_NOALPHAHW ");
break;
case DDERR_NOCOOPERATIVELEVELSET :
WriteDebug("DDERR_NOCOOPERATIVELEVELSET ");
break;
case DDERR_NODIRECTDRAWHW:
WriteDebug("DDERR_NODIRECTDRAWHW");
break;
case DDERR_NOEMULATION:
WriteDebug("DDERR_NOEMULATION ");
break;
case DDERR_NOEXCLUSIVEMODE:
WriteDebug("DDERR_NOEXCLUSIVEMODE ");
break;
case DDERR_NOFLIPHW:
WriteDebug( "DDERR_NOFLIPHW");
break;
case DDERR_NOMIPMAPHW:
WriteDebug( "DDERR_NOMIPMAPHW");
break;
case DDERR_NOOVERLAYHW:
WriteDebug( "DDERR_NOOVERLAYHW");
break;
case DDERR_NOZBUFFERHW:
WriteDebug( "DDERR_NOZBUFFERHW ");
break;
case DDERR_OUTOFMEMORY:
WriteDebug( "DDERR_OUTOFMEMORY ");
break;
case DDERR_OUTOFVIDEOMEMORY:
WriteDebug( "DDERR_OUTOFVIDEOMEMORY ");
break;
case DDERR_PRIMARYSURFACEALREADYEXISTS:
WriteDebug( "DDERR_PRIMARYSURFACEALREADYEXISTS ");
break;
case DDERR_UNSUPPORTEDMODE:
WriteDebug( "DDERR_UNSUPPORTEDMODE");
break;
}
WriteDebug("\n");


return hr;
}



//// EO creating front surface


//// Creating Back buffer

WriteDebug("Attempting to Get Attached BackBuffer\n");


ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hr = frontsurf->GetAttachedSurface(&ddscaps, &backsurf);
if(hr == DD_OK)
{

WriteDebug("Got the Attached BB\n");

}
else
{

WriteDebug("Failed to get Attached Backbuffer\n");

return 0;
}





LPDIRECTDRAWCLIPPER pcClipper;
hr = myyyyy->CreateClipper( 0, &pcClipper, NULL );
if( FAILED( hr ) )
{
WriteDebug("Create CLipper Failed\n");
}

// Assign it to the window handle, then set
// the clipper to the desired surface.
pcClipper->SetHWnd( 0, hWnd );
backsurf->SetClipper( pcClipper );
pcClipper->Release();


//// EO creating Back Buffer

WriteDebug("Creating a D3DI...\n");
hr=myyyyy->QueryInterface(IID_IDirect3D7, (void **)&d3di);
if (FAILED(hr))
{

WriteDebug("Failed to create D3DI\n");
return hr;
}
else
{

WriteDebug("Created D3DI okay!\n");
}



WriteDebug("End Of Debug Messages\n\n\n");

d3di->EnumZBufferFormats(IID_IDirect3DHALDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );
zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
//zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER | DDSCAPS_SYSTEMMEMORY;
hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
hr = backsurf->AddAttachedSurface(zsurf);
WriteDebug("Trying HAL Device\n");
hr=d3di->CreateDevice(IID_IDirect3DHALDevice, backsurf, &d3dd);
if (FAILED(hr))
{
backsurf->DeleteAttachedSurface(0,zsurf);
zsurf->Release();

d3di->EnumZBufferFormats(IID_IDirect3DMMXDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );

//zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
zbsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;

hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
hr = backsurf->AddAttachedSurface(zsurf);
WriteDebug("Trying MMX Device\n");
hr=d3di->CreateDevice(IID_IDirect3DMMXDevice, backsurf, &d3dd);
if (FAILED(hr))
{
backsurf->DeleteAttachedSurface(0,zsurf);
zsurf->Release();
d3di->EnumZBufferFormats(IID_IDirect3DRGBDevice, zbcb, (VOID*)&zbpf);
zbsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
zbsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER;
zbsd.dwSize = sizeof(DDSURFACEDESC2);
zbsd.dwWidth=sswidth; //FIXME!
zbsd.dwHeight=ssheight; //FIXME!
memcpy( &zbsd.ddpfPixelFormat, &zbpf, sizeof(DDPIXELFORMAT) );

//zbsd.ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY;
zbsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;

hr = myyyyy->CreateSurface( &zbsd, &zsurf, NULL );
hr = backsurf->AddAttachedSurface(zsurf);
WriteDebug("Trying RGB Device\n");
hr=d3di->CreateDevice(IID_IDirect3DRGBDevice, backsurf, &d3dd);
if (FAILED(hr))
{
return hr;
}
}
}
WriteDebug("Device Okay\n");


d3dd->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE );
d3dd->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, TRUE);
//d3dd->SetRenderState(D3DRENDERSTATE_EDGEANTIALIAS ,TRUE);
//d3dd->SetRenderState(D3DRENDERSTATE_ANTIALIAS,D3DANTIALIAS_SORTINDEPENDENT);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);

//FOR SOFTWARE
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE );
//d3dd->SetRenderState(D3DRENDERSTATE_COLORKEYENABLE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE , FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_ZFUNC, D3DCMP_LESS );
//d3dd->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
d3dd->SetRenderState(D3DRENDERSTATE_SHADEMODE , D3DSHADE_FLAT );
d3dd->SetRenderState(D3DRENDERSTATE_COLORVERTEX , FALSE);
d3dd->SetRenderState( D3DRENDERSTATE_ALPHATESTENABLE, FALSE );

//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);
//d3dd->SetRenderState(D3DRENDERSTATE_TEXTUREPERSPECTIVE, FALSE);

//Make It Look Nice
d3dd->SetTextureStageState(0,D3DTSS_MAGFILTER ,D3DTFG_LINEAR);
d3dd->SetTextureStageState(0,D3DTSS_MINFILTER ,D3DTFN_LINEAR);









ViewPor.dwX=0;
ViewPor.dwY=0;
ViewPor.dwWidth=sswidth;
ViewPor.dwHeight=ssheight;
ViewPor.dvMinZ=0.0f;
ViewPor.dvMaxZ=1.0f;
hr=d3dd->SetViewport(&ViewPor);
if (FAILED(hr))
{
return hr;
}

See=TRUE;


return 0;
}















HRESULT KILL_R3D()
{
ShowCursor(TRUE);
HWND hWnd;
hWnd=dxwin;
//HRESULT hr;

See=FALSE;
//myyyyy->RestoreDisplayMode();


if (d3dd) d3dd->Release();
if (d3di) d3di->Release();
if (zsurf) zsurf->Release();
if (backsurf) backsurf->Release();
if (frontsurf) frontsurf->Release();
if (myyyyy) myyyyy->Release();


d3dd=NULL;
d3di=NULL;
zsurf=NULL;
backsurf=NULL;
frontsurf=NULL;
myyyyy=NULL;
return 0;

}




char ssss[200];
void Flip_Buffers()
{
bar+=100;
bar%=30000;
//if (!bar%5)
//{
//sprintf(ssss,"color=%d \n",bar);
//WriteDebug(ssss);
//}
if (See)
{
//WriteDebug("FB CALLED!!!\n");
frontsurf->Flip(NULL, DDFLIP_WAIT);
d3dd->Clear(NULL, NULL,D3DCLEAR_TARGET,bar,0.0,0);
//backsurf->Flip(NULL, DDFLIP_WAIT);

}
}

} // eo extern "c"

Share this post


Link to post
Share on other sites
quote:
Original post by felonius
and how you import/export it.
Jacob Marner



here''s the import code:

HINSTANCE f3ddl= NULL;
typedef void (*FNZDISPINF)(void);
typedef HRESULT (*SUR3D)(HWND hWnd,int sswidth, int ssheight);
typedef HRESULT (*KR3D)(void);
typedef void (*FLPBUF)(void);
FNZDISPINF DisplayInfo;
FLPBUF Flip_Buffers;
SUR3D SETUP_R3D;
KR3D KILL_R3D;
BOOL See;

snip....

f3ddl=LoadLibrary("C:\\MSDEV\\Projects\\FNZ3DDX\\Debug\\FNZ3DDX.DLL");
DisplayInfo=(FNZDISPINF)GetProcAddress(f3ddl,"DisplayInfo");
SETUP_R3D=(SUR3D)GetProcAddress(f3ddl,"START_R3D");
KILL_R3D=(KR3D)GetProcAddress(f3ddl,"KILL_R3D");
Flip_Buffers=(FLPBUF)GetProcAddress(f3ddl,"Flip_Buffers");


snip...

then i call SETUP_R3D and then repetedly call Flip_Buffers ands that dies after a while :-(

- Anthony

Share this post


Link to post
Share on other sites
thanks for the advice, I''ve now found the problem, th code was constantly flipping, (as intended) but it was filling up the "instruction stack" (not sure of the name for this) and then it crashed, (I found this by making it vsync and since it has ran fine for over an hour).

- Anthony

Share this post


Link to post
Share on other sites