Having problem copying a form from one app to another.
the copying works and i've hex checked both forms and its
identical but when i try to load the "copied" form it is blank.
any ideas?
my code is below. thanks
copy_res("app1", "app2", 1000, 2000);
Err copy_res(char *dest, char *source, DmResID resID, DmResID NewresID)
{
LocalID src_dbID, dest_dbID;
DmOpenRef dest_ref = NULL, src_ref = NULL;
Err error = true;
char *res;
MemHandle myRecord = NULL, newRec = NULL, handle;
MemPtr p, p1;
UInt32 recSize;
// my form is less than 1K in size
res = MemPtrNew(1000);
if (!res)
return false;
// find the apps
src_dbID = DmFindDatabase (0, source);
dest_dbID = DmFindDatabase (0, dest);
if (src_dbID && dest_dbID)
{
// open new file for reading
src_ref = DmOpenDatabase (0, src_dbID, dmModeReadOnly);
if ( src_ref)
{
// get the resource
myRecord = DmGetResource ('tFRM', resID);
if (myRecord)
{
// get the size
recSize = (MemHandleSize(myRecord));
p = MemHandleLock (myRecord);
if (p)
{
// copy to temp
MemMove((void*)res, p, recSize);
MemHandleUnlock(myRecord);
}
DmReleaseResource(myRecord);
}
DmCloseDatabase (src_ref);
src_ref = NULL;
}
// open for writing
dest_ref = DmOpenDatabase (0, dest_dbID, dmModeReadWrite);
if (dest_ref)
{
// find the current formID
newRec = DmGet1Resource ('tFRM', NewresID);
if (newRec)
{
// resize it
if (MemHandleResize(newRec, recSize) == errNone)
{
// lock and write new icon
p1 = MemHandleLock(newRec);
if (p1)
{
DmWrite (p1, 0, res, recSize);
MemHandleUnlock(newRec);
}
}
DmReleaseResource(newRec);
}
}
}
MemPtrFree(res);
if (dest_ref)
DmCloseDatabase (dest_ref);
if (src_ref)
DmCloseDatabase (src_ref);
return error;
}
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/