Delphi 枚举设备使用代码

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;

时间: 2024-09-20 15:00:16

Delphi 枚举设备使用代码的相关文章

通过JavaScript或PHP检测Android设备的代码

随着乔布斯的回归,iPad2的发布,看来移动端的开发话题越来越火热了.在此列出一些能够在iOS的最大竞争者--安卓(Android)系统的检测方法. JavaScript判断方法 搜索user agent字符串中的Android单词是最省事儿的方法: 复制代码 代码如下: if(navigator.userAgent.match(/Android/i)) { // Do something! // Redirect to Android-site? window.location = 'http

微软发布2万行Linux设备驱动程序代码

[新浪科技讯]7月21日凌晨消息,微软公司宣布首次直接面向Linux社区发布2万行Linux设备驱动程序代码,以增加其在虚拟化市场的竞争力. 首次发布2万行Linux驱动代码 北京时间7月21日凌晨,微软公司对外宣布,面向Linux内核社区发布2万行的设备驱动程序代码.这是微软首次直接面向Linux社区发布Linux设备驱动程序代码.这些代码的许可证类型是GPLV2(GNU通用公共授权第二版),这是目前Linux社区最受欢迎的许可方式. 微软发布的2万行设备驱动程序代码可供Linux社区和客户使

通过JavaScript或PHP检测Android设备的代码_php技巧

随着乔布斯的回归,iPad2的发布,看来移动端的开发话题越来越火热了.在此列出一些能够在iOS的最大竞争者--安卓(Android)系统的检测方法. JavaScript判断方法 搜索user agent字符串中的Android单词是最省事儿的方法: 复制代码 代码如下: if(navigator.userAgent.match(/Android/i)) { // Do something! // Redirect to Android-site? window.location = 'http

利用delphi录入数据时代码错误问题

问题描述 利用delphi录入数据时代码错误问题 procedure TFrm_stu_ins.Button1Click(Sender: TObject); begin //写入数据 if (Trim(edt_name.Text)<>'') and (Trim(edt_numb.Text)<>'' ) and (Trim(edt_id.Text)<>'') then begin dm.q_stu_ins_ins.close; dm.q_stu_ins_ins.SQL.C

Android系统控制连接usb外部存储设备的代码在哪里能找到,我想在其中增加一个选择指定设备的功能

问题描述 Android系统控制连接usb外部存储设备的代码在哪里能找到,我想在其中增加一个选择指定设备的功能 代码指的是系统代码,Android系统支持USBhost功能.当u盘插在手机上时,系统自动甄别其是否为指定外设,如果是,没有额外动作,一切如常:如果不是,系统自动移除外设:楼主是Android新手,希望大家给予些帮助或思路

Windows系统中出现无法加载这个硬件的设备驱动程序(代码39)的解决方法介绍

近日不知何故,光驱和虚拟光驱盘符都不见了,查看系统发现硬件前面有黄色感叹号,无法使用,在网上搜索,发现有很多人出现同样的问题,只是解决的方法都不对,找了两天,终于找到了解决的方法: 修复"光驱图标不见"记 电脑没用几天,突然发现光驱图标不见了,系统提示为:Windows 无法加载这个硬件的设备驱动程序.驱动程序可能已损坏或不见了. (代码 39) 1.       我卸载了光驱,结果是能识别,但提示安装出错,错误还是一样: 2.       我把金山模拟光驱卸载,结果还是一样: 3. 

关于枚举的C#代码不是很理解,求解答。

问题描述 前面看到一个代码示例,但是不是很理解.GameMoves.cs代码usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Collections;namespaceWrox.ProCSharp.Arrays{publicclassGameMoves{privateIEnumeratorcross;privateIEnumeratorcircle;publicGameMoves(){cross=Cr

分享一段Shell和Python脚本解析VPN Profile for iOS/Android设备的代码

废话就不说了,直接上代码 Shell和Python脚本解析VPN Profile for iOS设备  代码如下 复制代码 #!/bin/bash httpserver="http://10.226.200.96/" vpnprofilename="vpn.mobileconfig" if [ ! -d "/tmp/vpn" ]; then mkdir /tmp/vpn fi cp ../tms_rest/$vpnprofilename /tmp

哪位懂delphi看看这段代码

问题描述 定义FunctionEncodeInit(Parameter:Pointer):SmallInt;stdcall;external'HotelLock.dll';FunctionEncodeExit():SmallInt;stdcall;external'HotelLock.dll';{制宾客卡.}FunctionMakeGuestCard(Rom:Pointer;Pass:Pointer;Building:Smallint;Floor:Pointer;District:Pointer