I tested my MIDI app in the Windows XP mode virtual PC and it crashed immediately. Tests on several VirtualBox XP machines were ok. When I remote debug the application it appears to crash in the startup code before it reaches any line of (visible) code. The error message was that there were no MIDI drivers present. This is weird because only in a much later stage of the application the presence of any MIDI system is required and tested.
The control panel shows no MIDI system present, although as one of the integration features audio is mentioned.
Question: how can I prevent my application from crashing because no MIDI drivers are present, before I have a chance to test their presence?
Thanks in advance for any suggestion.
Using Delphi XE
Update Well, I was fooled by the remote debugger in combination with Windows XP mode. It usually doesn't work. The one time I got it somewhat working it gave me the correct answer (no MIDI drivers present). Rob and Warren were right, I should have dived deeper into the debugger before asking the question, sorry for that. However, the problem remains essentially the same, I hope it is accepted to modify the question slightly.
Slightly modified question How can I test in Delphi for no MIDI drivers present in Windows XP mode?
If in my Windows XP mode virtual PC there are no MIDI drivers present, Delphi still sees that one MIDI output device is present. As soon as I try to open this device an exception is raised "There is no driver installed on your system". That's right, but why does midiOutGetNumDevs
return 1 instead of 0 in that situation? Using Dave Churchers midi components I have written a small program to reproduce the error. This code works ok on VirtualBox.
unit MIDITest_Main;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, MMSystem, MIDIOut;
type
TForm1 = class(TForm)
Button1: TButton;
List: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click (Sender: TObject);
begin
List.Items.Add (Format ('%d MIDI output devices', [midiOutGetNumDevs]));
end; // Button1Click //
procedure TForm1.Button2Click (Sender: TObject);
var Device: TMidiOutput;
ePort: Int32;
begin
for ePort := 0 to midiOutGetNumDevs - 1 do
begin
Device := TMidiOutput.Create (Self);
Device.DeviceID := ePort;
List.Items.Add (Format ('Trying to open device %d', [Device.DeviceID]));
Application.ProcessMessages;
// ShowMessage ('Open');
if Device.Open then
begin
List.Items.Add (Format ('Opened device %s', [Device.ProductName]));
Application.ProcessMessages;
end else
begin
List.Items.Add (Format ('Cannot open device %d', [Device.DeviceID]));
Application.ProcessMessages;
end; // if
end; // if
end; // Button2Click //
end.