Delphi enumeration device usage code_PHP tutorial
Jul 13, 2016 am 10:54 AMdelphi enumeration device usage code
Now delphi (2010, xe) already comes with directx related units (...sourcertlwin).
-------------------------------------------------- ----------------------------------
//Enumeration function
function directsoundenumerate(
lpdsenumcallback: tdsenumcallback; //Callback function
lpcontext: pointer //User pointer
): hresult; stdcall; //Return error code, if successful, return s_ok(0)
//The prototype of the callback function required by directsoundenumerate:
tdsenumcallback = function(
lpguid: pguid; //Guid of the device
lpcstrdescription: pchar; //Device description
lpcstrmodule: pchar; //Module identification
lpcontext: pointer //User pointer provided by directsoundenumerate
): bool; stdcall; //Returning true means that we want to continue enumeration. If we no longer want to continue searching, return false
-------------------------------------------------- ----------------------------------
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 one 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 not good to use the form control directly in the callback function. Modify it 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;
-------------------------------------------------- ----------------------------------
Get 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;

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

What software is crystaldiskmark? -How to use crystaldiskmark?

How to download foobar2000? -How to use foobar2000

GE universal remote codes program on any device

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange?

Teach you how to use the new advanced features of iOS 17.4 'Stolen Device Protection'
