/* Copyright (c) 1990, Silverwood Software
 * Placed in the public domain, 11/01/90
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * Library decendant class to initialize, etc Novell's Btrieve DLL */!!

inherit(Library, #Btrv, nil, 2, nil)!!

now(class(Btrv))!!

now(Btrv)!!

/* This method uses method WBtrv to close a Btrieve database file */
Def closeDat(self,rec)
{ ^WBtrv(self,vClose,gPBlk(rec),gDBuf(rec),gDLen(rec),
         gKBuf(rec),255,gKNdx(rec));
}
!!

/* This method uses method WBtrv to open a Btrieve database */
Def openDat(self,rec,datNm,ownNm,ownNmSz,mode)
{ setKeyBuf(rec,datNm);
  if ownNm<>nil then
    setDatBuf(rec,asciiz(ownNm));
    setDatLen(rec,ownNmSz+1);
  endif;  
  ^WBtrv(self,vOpen,
         gPBlk(rec),gDBuf(rec),gDLen(rec),
         gKBuf(rec),255,mode);
}
!!

/* Remove the Btrieve database manager from memory */
Def stopBtrv(self)
{ pcall(procs(self)[#WBTRVSTOP],nil);
}
!!

/* Free memory used by Btrieve DLL */
Def freeDLL(self)
{ free(self);
}
!!

/* Make call to the Btrieve DLL from Actor.  Return
 * the status code as an integer. */
Def WBtrv(self,op,posBlk,datBuf,datLen,keyBuf,keyLen,ndx)
{ ^low(pcall(procs(self)[#BTRCALL],
             op,posBlk,datBuf,datLen,keyBuf,
             keyLen,ndx));
}  
!!

/* Initialize the Btrieve database manager */
Def initBtrv(self,sPram)
{ pcall(procs(self)[#WBTRVINIT],lP(sPram));
}
!!

/* Load the Btrieve DLL.  Does not include #WBRQSHELLINIT since the
 * Windows Btrieve Requester is not available as yet (Nov, '90) */
Def loadDLL(self | windowsPath, name)
{ windowsPath:=new(String,144);
  Call GetWindowsDirectory(windowsPath,size(windowsPath));
  windowsPath:=removeNulls(windowsPath);
  if windowsPath[size(windowsPath)-1]='\' then
    name:="\wbtrcall.dll"; /* if '\' returned then root dir */
  else  
    name:=windowsPath+"\wbtrcall.dll";
  endif;  
  setName(self,name);
  add(self,#WBTRVINIT,1,#(1));
  add(self,#WBTRVSTOP,nil,nil);
  add(self,#BTRCALL,0,#(0 1 1 1 1 0 0));
  load(self);
}
!!
