Delphi 枚舉裝置使用代碼_PHP教程

來源:互聯網
上載者:User
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;

http://www.bkjia.com/PHPjc/632336.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632336.htmlTechArticledelphi 枚舉裝置使用代碼 現在的 delphi(2010、xe) 已經內建了 directx 的相關單元(...sourcertlwin). --------------------------------------------------------------...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.