Error 87 with VB Tool Kit and the Function NetAuditRead
  
PSS ID Number: Q101832
Article last modified on 09-30-1994
 
2.10 2.10A 2.20
 
MS-DOS
 

SYMPTOMS
========
 
An invalid parameter returns an error 87 when you use the NetAuditRead
function in the Visual Basic Tool Kit for LAN Manager.
 
CAUSE
=====
 
This can result from using 0 for the pszReserved2 field of the
NetAuditRead call, because you are attempting to pass a null pointer
to the function. Passing 0 as an integer sets the offset and the lower
half of the pointer to 0, but the upper half of the pointer will not
point to a valid segment because it will not have been initialised.
pszReserved2 has to be an unsigned long that initializes the segment
and offset of the pointer to 0, which is a null pointer in C.
 
When NetAuditRead is called in Visual Basic, the parameters are passed
according the function prototype. The following function prototype is
included in the Visual Basic Tool Kit for LAN Manager in the file
AUDIT.TXT.
 
Declare Function NetAuditRead% Lib "NETAPI.DLL" (ByVal pszServer$,
                       ByVal pszReserved1$, phAuditLog As HLog,
                       ByVal ulOffset&, pusReserved2%,
                       ByVal ulReserved3&, ByVal flOffset&,
                       ByVal pbBuffer&, ByVal cbBuffer%, pcbReturned%,
                       pcbTotalAvail%)
 
Another source of potential trouble is the parameter pszReserved1,
which changed between LAN Manager versions 2.0 and 2.1. The C function
prototype now used is:
 
extern API_FUNCTION
  NetAuditRead ( const char far *     pszServer,
                 const char far *     pszServiceName,
                 HLOG far *           phAuditLog,
                 unsigned long        ulOffset,
                 unsigned short far * pusReserved2,
                 unsigned long        ulReserved3,
                 unsigned long        flOffset,
                 char far *           pbBuffer,
                 unsigned short       cbBuffer,
                 unsigned short far * pcbReturned,
                 unsigned short far * pcbTotalAvail );
 
Where HLOG is the following data structure:
 
typedef struct loghandle
    {unsigned long time;         /* Timestamp of first record */
     unsigned long last_flags;   /* Last call's flags */
     unsigned long offset;       /* Current offset in log */
     unsigned long rec_offset;   /* Current record offset in log */
    } HLOG;
 
The parameter pszServiceName is specific to the name of the service
that owns the audit log that the audit operation will be applied to.
NetAuditRead determines if the service name is valid. To generate a
log filename, NetAuditRead truncates the service name to eight bytes
(if on a FAT system) and appends .AUD. The log file is created and
operated from the \LANROOT\lOGS directory. If the service name is
NULL, the service used is NET, the LAN Manager system log.
 
RESOLUTION
==========
 
Change the field pszReserved2% (in the function prototype, which is in
the include file AUDIT.TXT) to ByVal pszReserved&, so the declaration
for NetAuditRead is:
 
  Declare Function NetAuditRead% Lib "NETAPI.DLL" (ByVal pszServer$,
                            ByVal pszReserved1$, phAuditLog As HLog,
                            ByVal ulOffset&, ByVal pusReserved2&,
                            ByVal ulReserved3&, ByVal flOffset&,
                            ByVal pbBuffer&, ByVal cbBuffer%,
                            pcbReturned%, pcbTotalAvail%)
 
The function NetAuditRead then has to be called with 0& for the
pszReserved field:
 
Result% = NetAuditRead(ServerName$, NetStr$, hLogHandle, 0&, 0&, 0&,
0&, BufferPoint&, BufferSize%, BytesRead%, BytesAvail%)
 
REFERENCES
==========
 
LAN Manager Programmer's Reference, Update Version 2.1. (Document
number NT30108-0292).
 
KBCategory: kbnetwork
KBSubcategory:
Additional reference words: 2.10 2.10a 2.20 2.1 2.1a 2.2 NetAuditRead
error87
 
=============================================================================
 
Copyright Microsoft Corporation 1994.
