home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / database / mf_db.zip / MFUDK.C < prev    next >
Text File  |  1993-05-09  |  3KB  |  99 lines

  1. /*
  2.  
  3.    Sample UDK (user-defined key) dll
  4.  
  5.    (compiled under MSC 8.0 (VC++))
  6.  
  7.    You may do whatever you want with this.  It's free.
  8.  
  9. */
  10. #include <windows.h>
  11. #include <memory.h>
  12.  
  13.  
  14. /*
  15.       
  16.    Compare 2 values based.
  17.    MF.dll will call this function and pass the following parameters:
  18.    pass:
  19.       val 1   (LPSTR a)
  20.       val 2   (LPSTR b)
  21.       length  (Size of keys to compare)
  22.       type    (This will be a number >= 100)
  23.    
  24.    the 'type' is the 'type of index' specified when the index's where
  25.    created.  (i.e. When you called mfCreateDB you passed an array of
  26.    index types.  One of those 'types' was >= 100.  Whatever that
  27.    # was, it is now passed to you (as the type).  This allows you to
  28.    support multiple UDK's in one function.
  29.  
  30.    You should return:
  31.    returns:
  32.       0 == equal
  33.       1 == val 1 > val 2
  34.       -1 == val 1 < val 2
  35.  
  36.    Demonstrated in this example is a reverse-sorting for character fields
  37.    and a variable length char and INT field.  The 'type' passed for
  38.    these fields is:
  39.       1001 = reverse sorting characters
  40.       1002 = variable length char and INT
  41.  
  42.  
  43. */
  44. int FAR PASCAL _export mfUDK(LPSTR a, LPSTR b, int len, int type)
  45. {
  46.    int iReturnValue;
  47.  
  48.    switch(type){
  49.       case 1001:
  50.             // _fmemcmp is a MS-C runtime library routine.  (It is actually
  51.             // pretty quick, believe it or not...)
  52.             // Anycase, it returns the EXACT same parameters we need to
  53.             // return from this function...
  54.             // NOTE: To show the reverse-sorting, we just switched the
  55.             // order of the parameters to fmemcmp.  For 'alphabetical' 
  56.             // we would have put 'a' and then 'b'.
  57.          return(_fmemcmp((LPSTR)b, (LPSTR)a, len));
  58.          break;
  59.  
  60.       case 1002:
  61.             // NOTE: By using the value of  'len' we can make this 
  62.             // a 'variable' length string routine.  e.g. if the user
  63.             // made the key an 80 bytes, this routine would still
  64.             // work (by comparing the first 78 bytes and then the integer
  65.             // tacked onto the end...)
  66.  
  67.          iReturnValue = _fmemcmp((LPSTR)a, (LPSTR)b, len-2);
  68.             // We can stop checking now because the keys first set of 
  69.             // keys (the char[len]) doesn't match, therefore the value
  70.             // of the INT is irrelevant)
  71.          if (iReturnValue != 0)
  72.                return (iReturnValue);
  73.          if (*(int FAR *)(a+len-2) < *(int FAR *)(b+len-2))
  74.             return (-1);
  75.          if (*(int FAR *)(a+len-2) > *(int FAR *)(b+len-2))
  76.             return (1);
  77.  
  78.          return(0);  // exact match...
  79.          break;
  80.    }
  81.  
  82. }
  83.  
  84.  
  85. /*----------------------------------------------------------------------
  86.    This is required for 'windows' dll's.
  87.    Generally, you put any startup code that you might require,
  88.    initialize variables, allocate memory, etc...
  89. */
  90. int FAR PASCAL LibMain(
  91.         HANDLE  hModule,
  92.         WORD    wDataSeg,
  93.         WORD    cbHeapSize,
  94.         LPSTR   lpszCmdLine
  95.         )
  96. {
  97.    return 1;
  98. }
  99.