/*********************************************************
   VECSUM.C sample DLL for Windows Visual C++
   Not restricted to 64K maximum addressable limit
*********************************************************/
#include <windows.h>

#if !defined (NO_HUGE)
typedef char huge *HPSTR;
typedef long huge *HPLONG;
#define INC_HUGE (x) (x)++
#else
typedef char far *HPSTR;
typedef long far *HPLONG;
#define INC_HUGE (x) inc_huge(&(x), sizeof(*(x)))
#define WORD_MAX 0xFFFF
#define NEXT_DESCR (0x0001 << 3)
static void inc_huge (LPVOID *x, WORD size);
#endif

int FAR PASCAL
LibMain (HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
{
    if (wHeapSize > 0)
        UnlockData (0);
    return (1);
}

int FAR PASCAL _export
WEP (int nParameter)
{
    return (1);
}

void FAR PASCAL _export
VectorSum (HPLONG hplVector, HPLONG hplLength, HPLONG hplSum)
{
     long lLength, lSum;
     HPLONG hplVecPtr;

     lSum = 0L;
     hplVecPtr = hplVector;
     for (lLength = *hplLength; lLength > 0; lLength--,
            INC_HUGE (hplVecPtr))
          lSum += *hplVecPtr;
     *hplSum = lSum;
}

#if defined (NO_HUGE)
static void
inc_huge (LPVOID *x, WORD size)
{
      WORD sel, off;

      sel = SELECTOROF (*x);
      off = OFFSETOF (*x);
      if ((DWORD)off + (DWORD)size > WORD_MAX)
           sel += NEXT_DESCR;
      *x = MAKELP (sel, off + size);
}
#endif
