Title: How to know if an sound card is present
Question: My program did play wave files also if the soundcard was not present and a crash was raised.
That's the solution.
Answer:
Function IsSoundCardInstalled : Boolean;
Type
SCFunc = Function : UInt; StdCall;
Var
LibInst : LongInt;
EntryPoint : SCFunc;
Begin
Result := False;
LibInst := LoadLibrary( PChar( 'winmm.dll' ) );
Try
If ( Not( LibInst = 0 ) ) Then Begin
EntryPoint := GetProcAddress( LibInst, 'waveOutGetNumDevs' );
If ( EntryPoint 0 ) Then Result := True;
End;
Finally
If ( Not( LibInst = 0 ) ) Then FreeLibrary( LibInst );
End;
End;
Now, on Form_Create you can do:
If ( IsSoundcardInstalled ) Then
Label1.Caption := 'A soundcard is present.'
Else
Label1.Caption := 'No soundcard found. No sounds will be played.';