zoukankan      html  css  js  c++  java
  • 在 Delphi 下使用 DirectSound (1): 枚举播放设备


    现在的 Delphi(2010、XE) 已经自带了 DirectX 的相关单元(...\source\rtl\win\).
    //枚举函数
    function DirectSoundEnumerate(
      lpDSEnumCallback: TDSEnumCallback; //回调函数
      lpContext: Pointer                 //用户指针
    ): HResult; stdcall; //返回错误代码, 成功则返回 DS_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;
    

  • 相关阅读:
    c3p0、dbcp、proxool、BoneCP比较
    velocity的一些优化记录
    JUnit-4.11使用报java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing错误
    Deployment failure on Tomcat 7.x. Could not copy all resources to
    Spring3.2.3+Quartz2.2.1 整合配置
    mysql批量insert速度超慢
    Fine Uploader + Spring3.2.2(Java+html5上传) SpringMVC+jquery-fineuploader 文件上传
    实现工资的按天统计(X:日期 Y:姓名)
    Java发邮件带附件(且重命名附件)
    微信小程序wx.switchTab传参问题
  • 原文地址:https://www.cnblogs.com/del/p/1934003.html
Copyright © 2011-2022 走看看