Delphi 枚举设备使用代码_PHP教程
delphi 枚举设备使用代码
现在的 delphi(2010、xe) 已经自带了 directx 的相关单元(...sourcertlwin).
--------------------------------------------------------------------------------
//枚举函数
function directsoundenumerate(
lpdsenumcallback: tdsenumcallback; //回调函数
lpcontext: pointer //用户指针
): hresult; stdcall; //返回错误代码, 成功则返回 s_ok(0)
//directsoundenumerate 需要的回调函数的原形:
tdsenumcallback = function(
lpguid: pguid; //设备的 guid
lpcstrdescription: pchar; //设备描述
lpcstrmodule: pchar; //模块标识
lpcontext: pointer //由 directsoundenumerate 提供的用户指针
): bool; stdcall; //返回 true 表示要继续枚举, 不在继续找了就返回 false
--------------------------------------------------------------------------------
这是常见的代码:
--------------------------------------------------------------------------------
unit unit1;
interface
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, stdctrls;
type
tform1 = class(tform)
listbox1: tlistbox; //只在窗体上放了一个列表框
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.
--------------------------------------------------------------------------------
在回调函数中直接使用窗体控件不好, 修改如下:
--------------------------------------------------------------------------------
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;
--------------------------------------------------------------------------------
获取更多信息:
--------------------------------------------------------------------------------
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;

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

crystaldiskmark是什麼軟體? -crystaldiskmark如何使用?
