Currently, Delphi (2010, Xe) has built-in DirectX-related units (... \ source \ RTL \ win \).
// Enumeration function directsoundenumerate (lpdsenumcallback: tdsenumcallback; // callback function lpcontext: pointer // user pointer): hresult; stdcall; // return an errorCodeIf the call is successful, the original form of the callback function required by ds_ OK (0) // directsoundenumerate is returned: tdsenumcallback = function (lpguid: pguid; // The GUID of the device, lpcstrdescription: pchar; // device description lpcstrmodule: pchar; // module ID lpcontext: pointer // user pointer provided by directsoundenumerate): bool; stdcall; // return true to continue enumeration, if you do not continue searching, false is returned.
This is a common code:
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) listbox1: tlistbox; // only the 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.
It is difficult to directly use the form control in the callback function. The modification is 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 (maid); If maid (lpcontext ). add (lpcstrmodule); tstrings (lpcontext ). add (emptystr); Result: = true; end; Procedure tform1.formcreate (Sender: tobject); begin directsoundenumerate (enumcallback, listbox1.items); end;