mark_c wrote:I am using a TList as a container for pointers to MIDIEVENT structures
Why are you using a TList and not an array/vector instead?
mark_c wrote:after filling the TList, I have to initialize the member (header.lpData) of the MIDIHDR structure with the start address of the first structure present in the TList.
You are not setting the lpData to the address of the first MIDIEVENT struct. You are setting it to the address of a local variable that itself contains the address of the first MDIEVENT struct. You need to drop the '&' operator, eg:
Code: Select all
MIDIEVENT *s = (MIDIEVENT *) MyList->Items[0];
header.lpData = (LPSTR) s;
However, your code still won't work, because in order to pass around multiple MIDIEVENTs in a single MIDIHDR, the MIDIHDR requires an array of MIDIEVENT instances, not an array of pointers to MIDIEVENT instances. The dwBufferLength must be set to the size of the whole array, so MIDI can calculate how many MIDIEVENTs are in the array, eg:
Code: Select all
MIDIEVENT MyArr[2] = {};
MIDIHDR header = {};
MIDIEVENT *ev = &MyArr[0];
ev->dwDeltaTime = 00;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C90;
ev = &MyArr[1];
ev->dwDeltaTime = 100;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C80;
header.lpData = (LPSTR) MyArr;
header.dwBufferLength = header.dwBytesRecorded = sizeof(MyArr);
header.dwUser = 0;
header.dwFlags = 0;
header.dwOffset = 0;
...
Or, if you want to use a dynamically allocated array:
Code: Select all
int count = 2;
MIDIEVENT *MyArr = new MIDIEVENT[count];
MIDIHDR header = {};
MIDIEVENT *ev = &MyArr[0];
ev->dwDeltaTime = 00;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C90;
ev = &MyArr[1];
ev->dwDeltaTime = 100;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C80;
header.lpData = (LPSTR) MyArr;
header.dwBufferLength = header.dwBytesRecorded = (sizeof(MIDIEVENT) * count);
header.dwUser = 0;
header.dwFlags = 0;
header.dwOffset = 0;
...
delete[] MyArr;
Or better:
Code: Select all
#include <vector>
std::vector<MIDIEVENT> MyVec(2);
MIDIHDR header = {};
MIDIEVENT *ev = &MyVec[0];
ev->dwDeltaTime = 00;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C90;
ev = &MyVec[1];
ev->dwDeltaTime = 100;
ev->dwStreamID = 0;
ev->dwEvent = 0x00403C80;
header.lpData = (LPSTR) MyVec.data();
header.dwBufferLength = header.dwBytesRecorded = (sizeof(MIDIEVENT) * MyVec.size());
header.dwUser = 0;
header.dwFlags = 0;
header.dwOffset = 0;
...