WMI + Windows Services?  
Author Message
Andreia M

PostPosted: Visual C++ Language, WMI + Windows Services? Top

Dear everyone,

So. I'm quite new to programming and even more so to C++/Visual C++/Windows programming in general. I come from an *nix background, so bear with me. Because I'm really bored, I started playing around with Visual Studio 2005.

What I'm trying to do is create a Windows Service that will monitor the CPU and memory usage and send a structrure back to a client when requested. It should be running perpetually, unless the user stops it or the computer shuts down, naturally.

Now, I've already created the server as an usual application, and it works perfectly. I'm trying to convert it into a service, as it would be better for my project as a whole.

I used the template to create a service (using C++), which is fine. I tweaked the properties to my liking, which is also fine. I've followed the walkthroughs for installing, setup projects and the likes. Everything runs smoothly until I actually start to adding code to it. It boils down to questions:

- First, I added all the includes I used in my non-service application to the template-generated stdafx.h, but it complains that comutil.h cannot be used with /clr:pure. If I disable /clr:pure it gives me other errors, so I'm stuck in a rut. I need comutil.h for the WMI half of it and clr:pure for the service part of it. What can I do

- Second, the contents of my non-service app's Main should go under the OnStart method, correct It only does socket stuff (sets up sockets, connects, sends data, etc etc.).

- Third, what happens when the "onStart" execution reaches the end

That's it for now. Many excuses if it's out of topic for this forum, but I didn't know where to post it other than this place. Also excuse the poor english. I'm foreign.

Visual C++8  

PostPosted: Visual C++ Language, WMI + Windows Services? Top

Excuse my poor english either, I'm even poorer than you are.

Your problem is not the problem itself. It seems that you are not familiar with the difference between "managed code" and "native code". You were mixing those two kind of codes and causing your problem. Of cause, mixed codes do work well if you code properly.But I'd suggest you use either "managed" or "native", not the both.

You can try creating an ATL service project and add your WMI code to ATL service. I think that will meet your needs. 

Simple Samples

PostPosted: Visual C++ Language, WMI + Windows Services? Top

You can try the CodeProject and CodeGuru forums.

There are abundant articles and samples that use code that worked in previous versions of VC that will also work in current versions. The MSDN documentation of Services has sample code for a service that was written a long time before managed code was an idea. The MSDN Platform SDK newsgroup can probably provide all the help you need.