The Lifecycle of the Performance DLL
When a performance DLL is loaded into the PerfMon address space, the regular actions of a DLL are taken; that is, the DllMain function is called and a DLL_PROCESS_ ATTACH value is passed to it. After that, a DLL can receive many DLL_THREAD_ATTACH calls and then their DLL_THREAD_DETACH calls are signaled once the thread or process is terminated.
Once the initial setup process is finished, PerfMon indirectly calls the three exported functions that are listed in the registry under the PO key. The first one called is the open function, or in this case, the OpenPerfData function. It is called to give your performance DLL time to do any setup that is needed to get your objects in a ready state.
Next, PerfMon retrieves the information for the POs and COs that this DLL will be handling. It gets this information from the DLL's collect function or (in my sample) the exported CollectPerfData function. This function takes four parameters: the second of the four is a data buffer where the performance DLL will put its PO and CO information. The third parameter is the total number of bytes that all the PO and CO information have taken up in the data buffer. The last parameter indicates how many performance objects were put into the data buffer.
The first parameter has a dual role in the collect functions. First of all, it's just a unicode string value that's passed in. However, there are two values that can be contained within the string. The first is a value of Global, the second can be a space-delimited string of numbers (or PO index values). The Global string value is passed in as a "who is this" flag, and at this time the performance DLL will fill in the data buffer with the PO and CO information. The Global flag is passed in each time the Add to Chart dialog box is brought up.
Once the function exits, the next time it will be called is if you had selected a particular counter to be monitored by PerfMon. If you have, then the value that is passed into the function the next time is the space-delimited string with all the PO index values that are currently being monitored. It is the DLL's responsibility to go through this list and provide the proper PO and CO information for the ones it handles.
The last function that is called is the DLL's close function (ClosePerfData). When PerfMon exits it is called to do cleanup and allow any memory to be freed.