Delphi enumerating devices using code _php Tutorial

Source: Internet
Author: User
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.--------------------------------------- -----------------------...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.