BufDesc           : TDSBufferDesc_DX7;
    g_Event           : array[0..3]of THandle ;//Cardinal;   ///////
    PosNotify         : array[0..3] of TDSBPOSITIONNOTIFY;
    DSNotify          : IDirectSoundNotify;
    DXSound           : IDirectSound;
    DXSSBuffer        : IDirectSoundBuffer;
.........
 
 ////设置DirectSound通知 机制
  for i := 0 to 3{MAX_AUDIO_BUF} do
  begin
    g_Event[i] := CreateEvent(nil, FALSE, FALSE, nil);  // 创建通知事件句柄
    PosNotify[i].dwOffset := i* 1300;//BUFFERNOTIFYSIZE ;
    PosNotify[i].hEventNotify := g_Event[i];
  end;                              
  hRet := DXSound.QueryInterface(IID_IDirectSoundNotify, DSNotify);
  //DSNotify := IDirectSoundNotify(DXSound);
  if DSNotify=nil then
  begin
    showmessage('Bad');
    exit;
  end;  hRet :=DSNotify.SetNotificationPositions(4,PosNotify[0]);   // 设置通知标志现在的情况是DSNotify查询结果总是为nil 不知道为什么,请指教!!!!!

解决方案 »

  1.   

    就是说hRet := DXSound.QueryInterface(IID_IDirectSoundNotify, DSNotify);查询到的DSNotify始终为nil.奇怪......
      

  2.   

      lpDirectSound: IDirectSound;
      lpDirectSoundBuffer: IDirectSoundBuffer;
     
      DirectSoundCreate(nil, lpDirectSound, nil);
      lpDirectSound.SetCooperativeLevel(Handle, DSSCL_NORMAL);
      lpDirectSound.CreateSoundBuffer(BufDesc, lpDirectSoundBuffer, nil);
      lpDirectSoundBuffer.Lock(0, RecvBytes, @ptr1, @pdw1, @ptr2, @pdw2, 0);
      CopyMemory(ptr1, @RecvBuff, pdw1);
      CopyMemory(ptr2, PChar(@RecvBuff) + pdw1, pdw2);
      lpDirectSoundBuffer.Unlock(ptr1, pdw1, ptr2, pdw2);
      lpDirectSoundBuffer.Play(0, 0, 0);    }