要判断系统是否安装了声卡,调用 Winmm.dll 中的 waveOutGetNumDevs 和 midiOutGetNumDevs 函数就可以了。这两个函数在 Var 部分的说明如下:
function waveOutGetNumDevs: longint; stdcall; external ‘winmm.dll’ name ‘waveOutGetNumDevs’;
function midiOutGetNumDevs: longint; stdcall; external ‘winmm.dll’ name ‘midiOutGetNumDevs’;
//判断声卡是否存在
Function IsSoundcardInstalled : Boolean;
Var
WaveOutPutDeviceCount : Integer;
MidiOutPutDeviceCount : Integer;
Begin
Result := False;
WaveOutPutDeviceCount := waveOutGetNumDevs;
MidiOutPutDeviceCount := midiOutGetNumDevs;
if (WaveOutPutDeviceCount>0) and (MidiOutPutDeviceCount>0) Then
Result := True
Else
Result := False;
End;
procedure TForm1.Button1Click(Sender: TObject);
Begin
if IsSoundcardInstalled Then
ShowMessage(‘系统已经安装了声卡’)
Else
ShowMessage(‘系统没有安装声卡’);
end;