<p>Does anybody know of a method for creating custom Performance Counters using ordinary unmanaged Visual C++?</p>

<p>I know that it can be done easily using managed C++, but I need to do it using an unmanaged Windows service.</p>

<p>I also know that you can retrieve performance counter data, but I need to create some custom counters and increment them during the applications runtime.</p>

[{'answer_id': 55885, 'author': 'Johannes Passing', 'author_id': 4372, 'author_profile': 'https://Stackoverflow.com/users/4372', 'pm_score': 4, 'selected': True, 'text': '<p>See here: \n<a href="http://msdn.microsoft.com/en-us/library/aa371925.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/aa371925.aspx</a></p>\n\n<p>It is not really hard, but a bit tedious as the API involves extensive usage of self-referential, variable-length structures and has to employ some IPC mechanism to obtain the data from the monitored process. </p>\n'}, {'answer_id': 56036, 'author': 'Anthony K', 'author_id': 1682, 'author_profile': 'https://Stackoverflow.com/users/1682', 'pm_score': 1, 'selected': False, 'text': '<p>I was looking for something a litte easier to implement.  I will probably have to use this approach.  I was also shown by a colleague (thanks PJ) that there is a Scribble tutorial that has been modified to show how to add a Performance Counter using ATL classes:\n<a href="http://msdn.microsoft.com/en-us/library/z1xc8ye3(VS.80).aspx" rel="nofollow noreferrer" title="PerformanceScribble Sample: Performance Monitoring in an MFC Application">PerformanceScribble Sample: Performance Monitoring in an MFC Application</a></p>\n\n<p>The big drawback here is that currently my application doesn\'t use MFC or ATL, and I would have to add the support for it.</p>\n'}, {'answer_id': 56048, 'author': '1800 INFORMATION', 'author_id': 3146, 'author_profile': 'https://Stackoverflow.com/users/3146', 'pm_score': 2, 'selected': False, 'text': "<p>Don't use the ATL performance monitor classes. I know they are easy to add and they have a wizard and all, but they are hopelessly bugged. I added them to one of my development apps at work, then had to go through and rip the code out 6 months later. All in all about 3 weeks work lost to that noise.</p>\n"}, {'answer_id': 30605296, 'author': 'Dale Wilson', 'author_id': 391806, 'author_profile': 'https://Stackoverflow.com/users/391806', 'pm_score': 3, 'selected': False, 'text': '<p>The support for adding C++ performance counters changed in Vista and beyond.   The Performance DLL approach suggested in another answer still works, but the new technique described <a href="https://msdn.microsoft.com/en-us/library/aa965334(v=vs.85).aspx" rel="noreferrer">here</a> is easier to use.</p>\n\n<p>In this approach you write a manifest that describes your counters, run CTRPP, a tool that generates code from your manifest. Compile and link this code with your application, and add a call to initialize the process (it starts a background thread), and add code to update the counters as necessary.  The details of publishing the counters are handled by the background thread running the generated code.</p>\n\n<p>You also need to run lodctr /m:[manifest file] to register your counters before they can be used. This must be run as an admin.</p>\n\n<p>BTW: Another program, unlodctr reverse the effect of lodctr and must be used if you make any changes to your counters because there is no "replace" operation, only delete the old, then install the new.</p>\n\n<p>&lt;RANT&gt;Documentation for all the above is just plain awful. For example lodctr was completely reworked for Vista, but the doc in MSDN is all for the XP version and no longer applies.   If you visit MSDN please use the "This documentation is not helpful" button liberally and maybe Microsoft will get the message.&lt;/RANT&gt;</p>\n'}]
['https://Stackoverflow.com/questions/55753', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1682/']