I'm trying to create a string list with the names of all the SMFs in the
SystemMidiDatabase. This code that I have doesn't work. What am I doing
wrong?
// open system midi database
midiDB = DmOpenDatabaseByTypeCreator(sysFileTMidi, sysFileCSystem,dmModeReadOnly);
// If MIDI sound list is empty, just leave
if (midiDB == NULL)
return errNone;
// otherwise iterate through...
UInt theCategory = dmAllCategories;
UInt totalItems = DmNumRecordsInCategory(midiDB, theCategory);
UInt i;
UInt recordNum = 0;
CharPtr itemTextP;
// put each into MIDIStringList...
for (i = 0; i < totalItems; i++, recordNum++) {
// get a handle to the record
MemHandle recordH = DmQueryNextInCategory(midiDB, &recordNum,
theCategory);
// read the record and put it into a more readable list
MemHandle currRecord = DmQueryRecord(midiDB, recordNum);
SndMidiListItemType* listP = (SndMidiListItemType*)
MemHandleLock(currRecord);
itemTextP = listP[recordNum].name;
// write itemTextP to MIDIStringList (problems start here)
MemHandle MidiListH = DmGetResource('tSTL', MIDIStringList);
StrListPtr MidiListP = (StrListPtr) MemHandleLock(MidiListH);
// i need some sort of pointer to MidiListH->newString but how?
// not like this cause it don't work.
CharPtr oldList = (CharPtr) MemHandleLock(MidiListH->newString);
// increment number of strings
MidiListP->numStrings++;
// add itemTextP to the end of MidiListP->firstString
// also problems here. how should this be done?
CharPtr newList = (CharPtr) MemPtrNew(StrLen(MidiListP->firstString) +
StrLen(itemTextP) + 1);
StrCopy(newList, MidiListP->firstString);
StrCat(newList, itemTextP);
oldList = newList;
// am i going overboard with deallocation here?
MemHandleUnlock(oldList);
MemPtrFree(newList);
MemHandleUnlock(MidiListP);
DmReleaseResource(MidiListH);
MemHandleUnlock(listP);
MemHandleUnlock(currRecord);
MemHandleUnlock(recordH);
}
thanks!
-l
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/