View Issue Details

IDProjectCategoryView StatusLast Update
0035469FPCPackagespublic2019-08-23 17:02
ReporterZheng WangAssigned ToSven Barth 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
PlatformWindowsOSWindows 10OS Version1903
Product Version3.0.4Product Build 
Target VersionFixed in Version3.3.1 
Summary0035469: wrong type by MIDIHDR.reserved which get MMSYSERR_INVALPARAM while calling midiOutPrepareHeader function
DescriptionThe type of MIDIHDR.reserved was DWORD, which should be DWORD_PTR
This will cause wrong value of sizeof(MIDIHDR) in 64 bit version and failed to calling midi functions such as midiOutPrepareHeader function and get return value MMSYSERR_INVALPARAM
Steps To Reproduceprogram miditest;
uses windows,mmsystem;
var msgbuf:array[0..11]of byte=(0,0,0,0,0,0,0,0,$90,$3C,$7F,0);
var msgbufn:longword=12;
var midiout:longword;
var msghdr:MIDIHDR;
var midiouti:word=0;
begin
writeln(midiStreamOpen(@midiOut,@midiOuti,1,0,0,0));
  with msghdr do
    begin
    lpData:=@msgbuf;
    dwBufferLength:=msgbufn;
    dwBytesrecorded:=msgbufn;
    dwFlags:=0;
    dwOffset:=0;
    end;
  writeln(midiOutPrepareHeader(midiOut,@msghdr,sizeof(msghdr)));
  writeln(midiStreamOut(midiOut,@msghdr,sizeof(msghdr)));
  writeln(midiStreamRestart(midiOut));
  writeln(midiOutUnPrepareHeader(midiOut,@msghdr,sizeof(msghdr)));
sleep(1000);
midiStreamClose(midiOut);
end.
Additional InformationThis test program will press note C4 by midi, it will get result 11 while calling midiStreamOut
TagsNo tags attached.
Fixed in Revision42775
FPCOldBugId
FPCTarget-
Attached Files

Activities

Zheng Wang

2019-04-29 17:03

reporter   ~0115898

This is the original code in mmsystem.pp:

 _midihdr = packed Record
                    lpData: PChar;
                    dwBufferLength: DWORD;
                    dwBytesRecorded: DWORD;
                    dwUser: DWORD_PTR;
                    dwFlags: DWORD;
                    lpNext: PMIDIHDR;
                    reserved: DWORD;
                    dwOffset: DWORD;
                    dwReserved: array [0..Pred(8)] Of DWORD_PTR;
        End;

Here's the reference of the MIDIHDR structure from Microsoft
https://docs.microsoft.com/en-us/previous-versions/dd798449(v=vs.85)

As you can see, variable reserved should have type DWORD_PTR


Related bugs:
33823, 34113

Serge Anvarov

2019-04-29 18:24

reporter   ~0115901

By the way, in the documentation on this link the last field is defined as DWORD_PTR dwReserved[4]; while in MMSystem.h it is defined as DWORD_PTR dwReserved[8] which corresponds to mmsystem.pp

Zheng Wang

2019-04-30 05:44

reporter   ~0115908

Last edited: 2019-05-02 17:14

View 2 revisions

It's not "dwReserved" but "reserved" which have the issue
May be it's a good idea to check all the DWORD in mmsystem.pp

Zheng Wang

2019-08-19 14:29

reporter   ~0117737

Any update?

Sven Barth

2019-08-23 17:02

manager   ~0117803

I've found one other location. And also that our mmsystem seems to be missing some functions/types that are declared in the Microsoft headers...

Please test and close if okay.

Issue History

Date Modified Username Field Change
2019-04-29 16:54 Zheng Wang New Issue
2019-04-29 17:03 Zheng Wang Note Added: 0115898
2019-04-29 18:24 Serge Anvarov Note Added: 0115901
2019-04-30 05:44 Zheng Wang Note Added: 0115908
2019-05-02 17:14 Zheng Wang Note Edited: 0115908 View Revisions
2019-08-19 14:29 Zheng Wang Note Added: 0117737
2019-08-23 16:48 Sven Barth Assigned To => Sven Barth
2019-08-23 16:48 Sven Barth Status new => assigned
2019-08-23 17:02 Sven Barth Status assigned => resolved
2019-08-23 17:02 Sven Barth Resolution open => fixed
2019-08-23 17:02 Sven Barth Fixed in Version => 3.3.1
2019-08-23 17:02 Sven Barth Fixed in Revision => 42775
2019-08-23 17:02 Sven Barth FPCTarget => -
2019-08-23 17:02 Sven Barth Note Added: 0117803