>I'm trying to write software to add an appointment to the Date Book from
>inside another application running on the palm. Does anyone know of an API I
>can use to do this, or built in methods, I've looked at a few, but they're

Actually, if you take a look at the DateBook source code that comes 
with the SDK, it's pretty straightforward. Here's a piece of code 
that adds a basic appointment with no frills. You'll need to fill in 
the blanks to do anything fancy, and read between the lines a bit.

Regards,
Steve Mann

# # #

/***********************************************************************
  * FUNCTION:           AddDateBookMessage
  *
  * DESCRIPTION:        Stuff a new Datebook message into a datebook record
  *
  * RETURNED:           zero or an error code
  ***********************************************************************/
static Err              AddDateBookMessage
(
        void
)
{
        Err     error;
        UInt16  index;
        UInt16  category        = dmUnfiledCategory;

// Get the length of the new record. It's the record header length 
plus the length of the description.
// We subtract two from the header length because it has a 
single-byte data placeholder that is
// overwritten by the description and a one-byte invisible filler 
byte place there by the compiler to
// round out the structure to an even # of bytes.

        Int16 descrLen  = CALCULATE THE LENGTH OF THE APPOINTMENT DESCRIPTION;
        Int16 recLen    = ( Int16 ) ( descrLen + sizeof ( 
ApptPackedDBRecordType ) - 2 );

// Allocate a new Date Book record large enough to hold the 
appointment and clear it out

        ApptPackedDBRecordPtr recP = ( ApptPackedDBRecordPtr ) 
MemPtrNew ( recLen );
        ErrFatalDisplayIf ( ! recP, "Error allocating Date Book 
record buffer" );
        MemSet ( recP, ( Int32 ) MemPtrSize ( recP ), 0);

// Add the description to the appointment

        recP->flags.description = 1;
        recP->firstField = NULL;        // To get StrNCat to work
        StrNCat ( &recP->firstField, &msgP->DBDescript, descrLen + 1 );

// Start and end times

        recP->when.startTime.hours = ......;
        recP->when.startTime.minutes= .....;
        recP->when.endTime.hours        = ......;
        recP->when.endTime.minutes = ......;

// Appointment date

        recP->when.date.month = ......;
        recP->when.date.day = ......;
        recP->when.date.year = ......;

// Open the datebook database

        DmOpenRef dbRef = DmOpenDatabaseByTypeCreator
                ( 'DATA', sysFileCDatebook, dmModeReadWrite | 
dmModeShowSecret );
        if ( ! dbRef )
        {
                MemPtrFree ( recP );
                return dmErrCantOpen;
        }

// Write the new appointment to the date book, save the record index so that
// we can pass it to the Date Book for subsequent viewing, and free 
the buffer pointer.
// UTAddRecord creates a new record of size MemPtrSize ( recP ), 
copies what's in recP
// into that record, and returns the new record's index in &index.

        index   = dmMaxRecordIndex;
        error   = UTAddRecord ( dbRef, &index, recP, ( UInt16 ) 
MemPtrSize ( recP ), category );
        MemPtrFree ( recP );
        DmCloseDatabase ( dbRef );
        return error;
}

-- 
-------------------------------------------
Creative Digital Publishing Inc.
1315 Palm Street, San Luis Obispo, CA 93401-3117
-------------------------------------------
805.784.9461              805.784.9462 (fax)
[EMAIL PROTECTED]       http://www.cdpubs.com

-- 
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