Subject:  NEW ERA AND C
From: david@inform.co.nz (David Paulo)
te: Thu, 3 Oct 1996 00:23:44 GMT
Newsgroups: comp.databases.informix

Here are a couple of modules that we find usefull.

------------------------------------------------------------------------
-- $Id$
------------------------------------------------------------------------
-- Virtual Operating System Module
-- To provide a wrapper around operating system type calls
--
-- Author: David Paulo
-- Date: 6/6/1996
-- Copyright (c)  InForm Group Ltd., 1996
------------------------------------------------------------------------
-- Change History
-----------------
-- $Log$
------------------------------------------------------------------------
CLASS VOS

-- Constructor - does nothing - need never be called
  FUNCTION VOS()

-- To count the number of instances of ModuleName running on the system
  shared public function countModule(aModuleName char(*)) returning integer

-- To create a directory
-- return code of 0 indicates success else os specific error code
-- Directory already exists is counted as success
  shared public function mkDir(aDirPath char(*)) returning integer

END CLASS

include "vos.4gh"

BEGIN_C
#include <windows.h>
#include <toolhelp.h>
#include <direct.h>
#include <errno.h>
END_C


function VOS::VOS()

end function

function VOS::countModule(aModuleName char(*)) returning integer

variable alreadyloaded Integer = 0
variable ModuleName char(*)

BEGIN_C
MODULEENTRY Module;
END_C

LET ModuleName = aModuleName clipped

BEGIN_C
// This section gets a count of the number of instances
// of this module that are running
Module.dwSize = sizeof(MODULEENTRY);
for (alreadyloaded=0,ModuleFirst(&Module);ModuleNext(&Module);){
  if (strcmp(Module.szModule,modulename)==0) {
    alreadyloaded++;
  }
}
END_C

return alreadyloaded

END FUNCTION


function VOS::mkDir(aDirPath char(*)) returning integer
variable nErrorcode Integer = 0
variable cDirPath char(*)

LET cDirPath = aDirPath clipped

BEGIN_C
if (_mkdir(cdirpath) != 0) {
  if (errno != EACCES) {
    nerrorcode = errno;
  }
}
END_C

return nErrorCode
END FUNCTION



  ----------------------------------------------------------------------
    David Paulo, InForm Group Ltd.,PO Box 1444, Wellington, New Zealand.
    Ph: +64 4 472 0996  Fax: +64 4 473 2407   Email: david@inform.co.nz 
       =  What would you do if you knew that you could not fail =
  ----------------------------------------------------------------------
