That's a whole bunch of processing to accomplish a relatively simple
function.

First of all, you can't write to a Resource with StrCopy.  A Resource is a
PDB, so you need to use the "Dm..." functions.

Personally, I'd ...

1) Pre-scan to determine how long your resultant STL resource needs to be
2) Open the resource file with DmOpenDatabase, with DmReadWrite mode
3) Allocate a new resource buffer with DmNewHandle
4) Build the STL with a loop using DmWrite
5) Delete the old resource (if any) with DmRemoveResource
6) Add a new resource with DmAttachResource
7) Close the resource file you opened (DmCloseDatabase)

Regards,

Terry

"lauren" <[EMAIL PROTECTED]> wrote in message news:55365@palm-dev-forum...
>
> 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/

Reply via email to