Make your own free website on Tripod.com

                                Create pdb Files Based  on some Record Structure

1)Easy creation process
2)Customizable -> You can use your own Record structure

Read Pdb Format from oasis.palm.com/dev/kb

As Palm uses big-endian order so i have used functions
 ChangeFormat16 and ChangeFormat32 .

This code is checked and is executing without errors.
Please Mail me (manishjaggi@hotmail.com)
if you have some problems with this code
 

//////////////////////////////////////////////////////// Code ////////////////////////////////////////////
# include <windows.h>
 

WORD ChangeFormat16(short int num);
DWORD ChangeFormat32(DWORD x);
 

typedef struct
{

    char name [32];
   unsigned short attributes;
   unsigned short version;
   DWORD creationDate;
   DWORD modificationDate;
   DWORD lastBackupDate;
   DWORD modificationNumber;
   DWORD appInfoID;
   DWORD sortInfoID;
   DWORD type;
   DWORD creator;
   DWORD unqueIDSeed;
  DWORD nextRecordistID;
  WORD numRecords;
} PDBHeader;

typedef struct
{

   DWORD localChunkID;
   char attributes;
   char uid [3];
} FieldDescrType;

struct Record
{
    int x;
   float b;
  //Add the members As per your wish
};

void MakePdb( char *outfile,char *dbid)
{

FILE *outfile;
DWORD ct=0;
//Set the creation time
ct =140*365*24*60*60;

Record rec;
PDBHeader head;
FieldDescrType fd;
 

int REC=100;//You can set the record number
 

strcpy(head.name,dbid);
head.attributes=0;
head.version=0;
head.creationDate=ChangeFormat32(ct);
head.modificationDate=ChangeFormat32(ct);
head.lastBackupDate=ChangeFormat32(ct);
head.modificationNumber=0;
head.appInfoID=0;
head.sortInfoID=0;
head.type=ChangeFormat32('pl00');
head.creator=ChangeFormat32('pl01');
head.unqueIDSeed=0;
head.nextRecordistID=0;
head.numRecords=ChangeFormat16(REC);

fwrite((&head),sizeof(head),1,outfile);

for(int i=0;i<REC;i++)
{
  int offset = 78 +8*(REC) +i*30;
  fd.localChunkID=ChangeFormat32(offset);
  fd.attributes=0;
  fd.uid[0]=0;
  fd.uid[1]=0;
  fd.uid[2]=0;
  fwrite(&fd,sizeof(FieldDescrType),1,outfile);

}

// add records
memset(&rec,0,sizeof(Record));
// Write the code to Fill the Record Structure
and write in the outfile
fwrite(&rec,sizeof(Record),1,outfile);
fwrite(&rec,sizeof(Record),1,outfile);

fclose(outfile);
 


}

WORD ChangeFormat16(short int num)
{

WORD result;
BYTE high = HIBYTE(num);
BYTE low = LOBYTE(num);
result = MAKEWORD(high,low);
return result;


}

DWORD ChangeFormat32(DWORD x)
{

    WORD hiword = HIWORD(x);
    {
         BYTE hibyte = HIBYTE(hiword);
        BYTE lobyte = LOBYTE(hiword);
        hiword = MAKEWORD(hibyte,lobyte);
   }
  WORD loword = LOWORD(x);
   {
       BYTE hibyte = HIBYTE(loword);
       BYTE lobyte = LOBYTE(loword);
       loword = MAKEWORD(hibyte,lobyte);
    }
   DWORD y = MAKELONG(hiword,loword);

return y;

}

Note:    This is a working code . You are free to copy it and use it.