***************************************************************** * Neveprise Inc. Delphi FAQ * ***************************************************************** * Section: DirectX Topic: Enum DD devices * * Created: July 27th, 1999 Revised: July 27th, 1999 * * Updates: www.neveprise.de Info: support@neveprise.de * ***************************************************************** Q: How can I enumerate DirectDraw devices? How to declare the callback? A: Finding an enumeration function in DirectX is not hard, but the problem is how to declare the required callback function and what the lpContext param can be used for. What we do is to write one single function that retrieves all needed information as TStrings. This function contains the call to DirectDrawEnumerate() and in the var part our callback. The advantage of using TStrings as result is, that we have readable (for the user) and internal DirectX values in one object without declaring complex custom types. Perhaps you know that a string in TStrings can have an additional pointer to TObject (using AddObject() etc.) we can combine both information. //a "pseudo-record" as TObject, it contains information that is needed //later when we want to initialize a DirectDraw device driver (at least //the GUID of the graphics card is needed, it should be used in //DirectDrawCreate() as first parameter instead of nil) TDisplayDriver_SD = class (TObject) Name: string; Desc: string; GUID: PGUID; end; //the function to call from your app, Drivers will contain a list with all //devices and description function EnumDisplayDrivers_SD(var Drivers: TStringList): boolean; //callback function that fills the list function EnumCallBack(const lpGUID: PGUID; lpDeviceDescription: lpcStr; lpDeviceName: lpcStr; lpUserArg: Pointer): HResult; stdcall; var DisDrv: TDisplayDriver_SD; begin DisDrv:= TDisplayDriver_SD.Create; with DisDrv do begin Name:= lpDeviceName; //fill with values Desc:= lpDeviceDescription; GUID:= lpGUID; // .. and assign to stringlist as TObject TStringList(lpUserArg).AddObject(Desc, DisDrv); end; Result:=DDEnumRet_Ok; //enum was okay end; begin Result:=false; DXStat:='Enumerate Display Drivers'; if DXCheck(DirectDrawEnumerate(@EnumCallBack, Drivers))=true then Result:=true; end; //now you have TStrings, use it this way: //this fills a combobox (cbVideoDrivers) with all device names slDrivers:=TStringList.Create; if EnumDisplayDrivers_SD(slDrivers)=true then cbVideoDrivers.Items:=slDrivers; //if an item is selected, we can retrieve the GUID this way to pass'em //to DirectDrawCreate etc. var DevDD: TDisplayDriver_SD; TObject(DD):=slDrivers.Objects[cbVideoDrivers.ItemIndex]; Blazko