Directsound 的問題, close 時會出現access violation |
缺席
|
Lordaeron
初階會員 發表:24 回覆:93 積分:33 註冊:2004-05-19 發送簡訊給我 |
聲音有正常播出, 但當程式關閉時, 會出現access violation, 是我有才free 什麼東西嗎?
lpDirectSoundBuffer._Release 和lpDirectSound._Release 也試過放到FormClose中但結果依然是access violation. 有人有相似的經驗嗎? DirectX 的header 我是用DSPACK 所包的. [code delphi] unit wavetest; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, MMSystem, DirectSound, Wave; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public lpDirectSound: IDirectSound; lpDirectSoundBuffer: IDirectSoundBuffer; audiobuf: pointer; format: PWAVEFORMATEX; BufferDesc: DSBUFFERDESC; ptr1, ptr2: pointer; pdw1, pdw2: dword; { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var i:integer; cbSize: Longint; begin fillchar(bufferdesc, sizeof(bufferdesc), 0); WaveLoadFile( 'c\1.wav', cbSize, format, audiobuf ); bufferdesc.dwSize:=sizeof(bufferdesc); bufferdesc.dwBufferBytes:=cbSize; bufferdesc.lpwfxFormat:=format; DirectSoundCreate(nil, lpDirectSound, nil); lpDirectSound.SetCooperativeLevel(Handle, DSSCL_NORMAL); lpDirectSound.CreateSoundBuffer(bufferdesc, lpDirectSoundBuffer, nil); lpDirectSoundBuffer.Lock(0, cbSize, ptr1, pdw1, ptr2, pdw2, 0); copymemory(ptr1, audiobuf, pdw1); copymemory(ptr2, pchar(audiobuf) pdw1, pdw2); lpDirectSoundBuffer.Unlock(ptr1, pdw1, ptr2, pdw2); lpDirectSoundBuffer.Play(0, 0, 0); end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin if audiobuf<>nil then freemem(audiobuf); end; end. [/code] 編輯記錄
Lordaeron 重新編輯於 2008-05-21 16:21:59, 註解 無‧
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |