enumeration of ddraw

Started by
2 comments, last by uncleben 21 years, 12 months ago
i have some problems with the enumeration of ddraw devices. when i get the ddraw device with null as guid it works fine, but if i get it with a enumerated GUID, it doesn''t. AVATAN RPG ENGINE http://www.avatan.de.vu
- Benjamin Block
Advertisement
Make sure you copy the *whole* GUID, - *do not* copy just the pointer which is passed to the enumeration function because what the pointer points to is temporary for the enum call and will be invalid later on.

Here''s some pseudo code based on the engine of the last DX7 based game I worked on (Pac-Man:AIT for Hasbro):


  typedef struct{    GUID ddGuid;    GUID ddDriverGuid;}gfxDEVICEINFO;gfxDEVICEINFO g_deviceInfo;BOOL WINAPI gfxDDEnumCallbackEx( GUID* lpGUID, LPSTR lpszDesc, LPSTR lpszName, LPVOID lpContext, HMONITOR hm ){...    if (lpGUID)    {        // if GUID is non-NULL, copy to dev structure        memcpy( &g_deviceInfo.ddGuid, lpGUID, sizeof(GUID) );    }    LPDIRECTDRAW7 lpDD;    hr = _DirectDrawCreateEx( lpGUID, (LPVOID *)&lpDD, IID_IDirectDraw7, NULL );    if (FAILED(hr))    {        // can''t create a DD interface, skip this device        return TRUE;    }    ...    DDDEVICEIDENTIFIER2 dddi[2];    hr = lpDD->GetDeviceIdentifier( &(dddi[0]), 0 );    if (SUCCEEDED(hr))    {        memcpy( &dev.ddDriverGuid, &dddi.guidDeviceIdentifier, sizeof(GUID) );    }    ...    lpDD->Release();...}  


We used the DD device to do things like get the device identifier, get the available modes, enumerate D3D devices etc.

Since you''re doing enumeration stuff, something you''ll probably come across is a bug in GetDeviceIdentifier() which trashes a few past the end of the structure you pass it. You''ll note that I make an array of device identifiers to prevent any trashing problems.

In a real world app you''d collect all the validly enumerated devices in an array and present a list to the user.

BTW: the DirectX 7 SDK has sample code which handles multiple device enumeration correctly.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

Actually - another thought - is it the DirectDrawCreate call which is failing or something later ?

The reason I ask is because needing a GUID to create a device implies the use of a secondary card such as a 3Dfx Voodoo2. If it fails later on, it could also be a result of trying to do stuff which the card doesn''t support, such as 32bit screen modes or large surfaces.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

the problem is that on some computers, my game runs very slow, and on others it runs perfectly. thats why i wanted to try enumeration to make sure that the right device is used

AVATAN RPG ENGINE
http://www.avatan.de.vu
- Benjamin Block

This topic is closed to new replies.

Advertisement