Delphi Enumerating devices using code
Now Delphi (2010, XE) has its own related units (... sourcertlwin) for DirectX.
--------------------------------------------------------------------------------
Enumeration functions
function Directsoundenumerate (
Lpdsenumcallback:tdsenumcallback; callback function
Lpcontext:pointer//user pointer
): HRESULT; stdcall; Returns the error code, and returns S_OK if successful (0)
Directsoundenumerate the desired callback function for the prototype:
Tdsenumcallback = function (
Lpguid:pguid; GUID of Device
Lpcstrdescription:pchar; Device description
Lpcstrmodule:pchar; Module identification
Lpcontext:pointer//user pointers provided by directsoundenumerate
): BOOL; stdcall; Returns true to indicate that you want to continue the enumeration without returning false if you continue to search.
--------------------------------------------------------------------------------
This is the common code:
--------------------------------------------------------------------------------
Unit unit1;
Interface
Uses
Windows, messages, Sysutils, variants, classes, graphics, controls, forms,
dialogs, Stdctrls;
Type
Tform1 = Class (Tform)
Listbox1:tlistbox; Only a list box is placed on the form
Procedure Formcreate (Sender:tobject);
End
Var
Form1:tform1;
Implementation
{$r *.DFM}
Uses DirectSound; //!
function Enumcallback (lpguid:pguid; lpcstrdescription, Lpcstrmodule:pchar;
Lpcontext:pointer): BOOL; stdcall;
Begin
Form1.listbox1.items.add (lpcstrdescription);
Result: = true;
End
Procedure Tform1.formcreate (Sender:tobject);
Begin
Directsoundenumerate (Enumcallback, nil);
End
End.
--------------------------------------------------------------------------------
Using the form controls directly in the callback function is not good and is modified as follows:
--------------------------------------------------------------------------------
Uses DirectSound;
function Enumcallback (lpguid:pguid; lpcstrdescription, Lpcstrmodule:pchar;
Lpcontext:pointer): BOOL; stdcall;
Begin
Tstrings (Lpcontext). Add (Lpcstrdescription);
Result: = true;
End
Procedure Tform1.formcreate (Sender:tobject);
Begin
Directsoundenumerate (Enumcallback, Listbox1.items);
End
--------------------------------------------------------------------------------
For more information:
--------------------------------------------------------------------------------
Uses DirectSound;
function Enumcallback (lpguid:pguid; lpcstrdescription, Lpcstrmodule:pchar;
Lpcontext:pointer): BOOL; stdcall;
Begin
If Lpguid <> nil then tstrings (lpcontext). Add (Guidtostring (lpguid^));
Tstrings (Lpcontext). Add (Lpcstrdescription);
If Lpcstrmodule <> nil then tstrings (lpcontext). Add (Lpcstrmodule);
Tstrings (Lpcontext). Add (EMPTYSTR);
Result: = true;
End
Procedure Tform1.formcreate (Sender:tobject);
Begin
Directsoundenumerate (Enumcallback, Listbox1.items);
End
http://www.bkjia.com/PHPjc/632336.html www.bkjia.com true http://www.bkjia.com/PHPjc/632336.html techarticle Delphi Enumeration Device using Code now Delphi (2010, XE) has its own associated unit (... sourcertlwin) for DirectX.--------------------------------------- -----------------------...