搜索
首页php教程php手册Delphi 枚举设备使用代码

Delphi 枚举设备使用代码

Jun 13, 2016 am 09:55 AM
delphidi代码使用枚举自带设备

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;

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具