Delphi enumeration device code. Delphi enumeration device use code current delphi (2010, xe) already comes with directx related units (... sourcertlwin). ---------------------------------------------------------------- delphi enumeration device use code
Currently, delphi (2010, xe) has built-in directx-related units (... sourcertlwin ).
--------------------------------------------------------------------------------
// Enumeration function
Function directsoundenumerate (
Lpdsenumcallback: tdsenumcallback; // callback function
Lpcontext: pointer // User pointer
): Hresult; stdcall; // return the error code. if the code is successful, s_ OK (0) is returned)
// Original form of the callback function required by directsoundenumerate:
Tdsenumcallback = function (
Lpguid: pguid; // guid of the device
Lpcstrdescription: pchar; // device description
Lpcstrmodule: pchar; // module id
Lpcontext: pointer // User pointer provided by directsoundenumerate
): Bool; stdcall; // returns true, indicating that the enumeration is to be continued. if you do not continue searching, false is returned.
--------------------------------------------------------------------------------
This is a 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.
--------------------------------------------------------------------------------
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 (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.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632336.htmlTechArticledelphi enumeration device using code now delphi (2010, xe) already comes with directx related units (... sourcertlwin ).--------------------------------------------------------------...