Annotation of mstools/samples/sdktools/pviewer/instdata.c, revision 1.1

1.1     ! root        1: 
        !             2: /******************************************************************************\
        !             3: *       This is a part of the Microsoft Source Code Samples. 
        !             4: *       Copyright (C) 1993 Microsoft Corporation.
        !             5: *       All rights reserved. 
        !             6: *       This source code is only intended as a supplement to 
        !             7: *       Microsoft Development Tools and/or WinHelp documentation.
        !             8: *       See these sources for detailed information regarding the 
        !             9: *       Microsoft samples programs.
        !            10: \******************************************************************************/
        !            11: 
        !            12: 
        !            13: /******************************************************************************
        !            14: 
        !            15:                             I N S T A N C E   D A T A
        !            16: 
        !            17:     Name:       instdata.c
        !            18: 
        !            19:     Description:
        !            20:         This module contains functions that access instances of an object
        !            21:         type in performance data.
        !            22: 
        !            23:     Functions:
        !            24:         FirstInstance
        !            25:         NextInstance
        !            26:         FindInstanceN
        !            27:         FindInstanceParent
        !            28:         InstanceName
        !            29: 
        !            30: 
        !            31: ******************************************************************************/
        !            32: 
        !            33: #include <windows.h>
        !            34: #include <winperf.h>
        !            35: #include "perfdata.h"
        !            36: 
        !            37: 
        !            38: 
        !            39: 
        !            40: //*********************************************************************
        !            41: //
        !            42: //  FirstInstance
        !            43: //
        !            44: //      Returns pointer to the first instance of pObject type.
        !            45: //      If pObject is NULL then NULL is returned.
        !            46: //
        !            47: PPERF_INSTANCE   FirstInstance (PPERF_OBJECT pObject)
        !            48: {
        !            49:     if (pObject)
        !            50:         return (PPERF_INSTANCE)((PCHAR) pObject + pObject->DefinitionLength);
        !            51:     else
        !            52:         return NULL;
        !            53: }
        !            54: 
        !            55: 
        !            56: 
        !            57: 
        !            58: //*********************************************************************
        !            59: //
        !            60: //  NextInstance
        !            61: //
        !            62: //      Returns pointer to the next instance following pInst.
        !            63: //
        !            64: //      If pInst is the last instance, bogus data maybe returned.
        !            65: //      The caller should do the checking.
        !            66: //
        !            67: //      If pInst is NULL, then NULL is returned.
        !            68: //
        !            69: PPERF_INSTANCE   NextInstance (PPERF_INSTANCE pInst)
        !            70: {
        !            71: PERF_COUNTER_BLOCK *pCounterBlock;
        !            72: 
        !            73:     if (pInst)
        !            74:         {
        !            75:         pCounterBlock = (PERF_COUNTER_BLOCK *)((PCHAR) pInst + pInst->ByteLength);
        !            76:         return (PPERF_INSTANCE)((PCHAR) pCounterBlock + pCounterBlock->ByteLength);
        !            77:         }
        !            78:     else
        !            79:         return NULL;
        !            80: }
        !            81: 
        !            82: 
        !            83: 
        !            84: 
        !            85: //*********************************************************************
        !            86: //
        !            87: //  FindInstanceN
        !            88: //
        !            89: //      Returns the Nth instance of pObject type.  If not found, NULL is
        !            90: //      returned.  0 <= N <= NumInstances.
        !            91: //
        !            92: 
        !            93: PPERF_INSTANCE FindInstanceN (PPERF_OBJECT pObject, DWORD N)
        !            94: {
        !            95: PPERF_INSTANCE pInst;
        !            96: DWORD          i = 0;
        !            97: 
        !            98:     if (!pObject)
        !            99:         return NULL;
        !           100:     else if (N >= (DWORD)(pObject->NumInstances))
        !           101:         return NULL;
        !           102:     else
        !           103:         {
        !           104:         pInst = FirstInstance (pObject);
        !           105: 
        !           106:         while (i != N)
        !           107:             {
        !           108:             pInst = NextInstance (pInst);
        !           109:             i++;
        !           110:             }
        !           111: 
        !           112:         return pInst;
        !           113:         }
        !           114: }
        !           115: 
        !           116: 
        !           117: 
        !           118: 
        !           119: //*********************************************************************
        !           120: //
        !           121: //  FindInstanceParent
        !           122: //
        !           123: //      Returns the pointer to an instance that is the parent of pInst.
        !           124: //
        !           125: //      If pInst is NULL or the parent object is not found then NULL is
        !           126: //      returned.
        !           127: //
        !           128: PPERF_INSTANCE FindInstanceParent (PPERF_INSTANCE pInst, PPERF_DATA pData)
        !           129: {
        !           130: PPERF_OBJECT    pObject;
        !           131: 
        !           132:     if (!pInst)
        !           133:         return NULL;
        !           134:     else if (!(pObject = FindObject (pData, pInst->ParentObjectTitleIndex)))
        !           135:         return NULL;
        !           136:     else
        !           137:         return FindInstanceN (pObject, pInst->ParentObjectInstance);
        !           138: }
        !           139: 
        !           140: 
        !           141: 
        !           142: 
        !           143: //*********************************************************************
        !           144: //
        !           145: //  InstanceName
        !           146: //
        !           147: //      Returns the name of the pInst.
        !           148: //
        !           149: //      If pInst is NULL then NULL is returned.
        !           150: //
        !           151: LPTSTR  InstanceName (PPERF_INSTANCE pInst)
        !           152: {
        !           153:     if (pInst)
        !           154:         return (LPTSTR) ((PCHAR) pInst + pInst->NameOffset);
        !           155:     else
        !           156:         return NULL;
        !           157: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.