home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual Foxpro 6.0 (Ent. Edition) / Vf6ent Extractor.EXE / API / SAMPLES / MEMREPL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-26  |  2.2 KB  |  88 lines

  1. /*
  2. **
  3. *
  4. * MEMREPL.C - Sample API routine.
  5. *
  6. * Copyright (c) 1989-1993 Microsoft Corporation as an unpublished
  7. * licensed proprietary work.  All rights reserved.
  8. *
  9. * Description:
  10. *        This is an example of an API routine that reads in the current
  11. *       work area's memo field and then replaces the Memo Field of the specified
  12. *        record number.
  13. *
  14. *        This routine takes two parameters (the second is optional).
  15. *
  16. *            <expN1>   ----> The field number of the memo.
  17. *            [<expN2>] ----> The record number the replace should be made into.
  18. *
  19. *
  20. *
  21. **
  22.  */
  23.  
  24. #include  <pro_ext.h>
  25.  
  26. #define WORKAREA        1
  27. #define BADHANDLE       0
  28.  
  29. MHANDLE dbhand = 0;
  30.  
  31.  
  32. void FAR memrepl(ParamBlk  FAR *param)
  33. {
  34.     Locator locate;
  35.     Value val;
  36.         int memchan,skip;
  37.         long memseek, memread, memfind;
  38.  
  39.  
  40.  
  41.     locate.l_type = 'R';
  42.     locate.l_where = 1;
  43.     locate.l_NTI = 1;
  44.  
  45. //      Store the offset of the memo field.
  46.     locate.l_offset = param->p[0].val.ev_long - 1;
  47.     memchan = _MemoChan(WORKAREA);              // Get the FCHAN to the memo file
  48.  
  49.     if((memfind = _FindMemo(&locate)) < 0)      // Find the offset of the memo
  50.         _Error((int) memfind);
  51.  
  52.     memread = _MemoSize(&locate);               // Find the size of the memo field
  53.  
  54.     memseek = _FSeek(memchan, memfind, 0);      // Move the file pointer
  55.  
  56. //      Read in the memo field into our handle.
  57.     if ((dbhand = _AllocHand((unsigned) memread)) == BADHANDLE) // Read from the memo file
  58.         _Error(182);                            // Insufficient Memory.
  59.  
  60.     memread = _FRead(memchan, _HandToPtr(dbhand), (int) memread);
  61.  
  62.  
  63.     val.ev_type = 'C';
  64.     val.ev_handle = dbhand;
  65.     val.ev_length = memread;
  66.  
  67. //      Move to the correct record in the database.
  68.     if (param->pCount == 2)
  69.        _DBRead(WORKAREA, param->p[1].val.ev_long);
  70.     else
  71.        _DBSkip(WORKAREA, 1);
  72.  
  73.  
  74.     skip = _DBReplace(&locate,&val);        // Replace the memo field.
  75.  
  76.     _FreeHand(dbhand);                      // Free the handle previously allocated.
  77.  
  78. }
  79.  
  80. FoxInfo myFoxInfo[] ={
  81.         {"MEMREPL", (FPFI) memrepl, 2, "I,.I"},
  82. };
  83.  
  84.  
  85. FoxTable _FoxTable = {
  86.     (FoxTable FAR *)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo
  87. };
  88.