Delphi enumeration device usage code_PHP tutorial

WBOY
Release: 2016-07-13 10:54:12
Original
1026 people have browsed it

delphi 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;

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632336.htmlTechArticledelphi enumeration device usage code The current delphi (2010, xe) already comes with directx related units (. ..sourcertlwin).------------------------------------------------ ------------------...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!