Summary C ++ development skills

Source: Internet
Author: User

During C ++ development, just its syntax, features, and standard library are already a very advanced course. Therefore, when you start learning, you must be careful, in this way, you can compile the programs you want in a timely and accurate manner.

When I wrote the first NT Service, I went to MSDN to find an example. I found an article written by Nigel Thompson: "Creating a Simple Win32 Service in C ++". This article comes with a C ++ example. Although this article provides a good explanation of the service development process.

However, I still feel that the important information I need is missing. I want to understand what framework, what function to call, and when to call, but C ++ does not make me much easier in this regard. The object-oriented method is convenient, but the underlying Win32 function calls are encapsulated by classes.

  • How to Use Visual C ++ to create a news reader
  • How to use C ++ to create a Windows Shutdown event
  • Solve the Problem of automatically generated Test in C ++ Test
  • Several Methods for converting C ++ Language
  • Difficulties and secrets in C ++ programs

It is not conducive to learning the basic knowledge of service programs. This is why I think C ++ is more suitable for writing basic service programs or implementing simple backend tasks. After you have a thorough understanding of the service program, you can easily write it in C ++. When I leave my original job and have to transfer my knowledge to another person, using the example I wrote in C ++ makes it very easy to explain the NT Service.

  • How to Use Visual C ++ to create a news reader
  • How to use C ++ to create a Windows Shutdown event
  • Solve the Problem of automatically generated Test in C ++ Test
  • Several Methods for converting C ++ Language
  • Difficulties and secrets in C ++ programs

A service is a console program that runs in the background and implements tasks that do not require user interaction. The Windows NT/2000/XP operating system provides special support for service programs. People can use the Service Control Panel to configure the installed service programs, that is, Windows 2000/XP Control Panel | "service" in the management tool (or in the "Start" | "run" dialog box, enter services. msc/s-Translator's note ). You can set

First, include the required header file. In this example, Win32 function (windows. h) and disk file write (stdio. h) are called ):

 
 
  1. #include   
  2. #include 

Then, two constants are defined:

 
 
  1. #define SLEEP_TIME 5000   
  2. #define LOGFILE "C:\\MyServices\\memstatus.txt" 

SLEEP_TIME specifies the millisecond interval between two consecutive queries of available memory. Use this constant when writing a service workflow in step 2. LOGFILE defines the path of the log file. You will use the WriteToLog function to output the memory query results to this file. The WriteToLog function is defined as follows:

 
 
  1. int WriteToLog(char* str)   
  2. {   
  3. FILE* log;   
  4. log = fopen(LOGFILE, "a+");   
  5. if (log == NULL)   
  6. return -1;   
  7. fprintf(log, "%s\n", str);   
  8. fclose(log);   
  9. return 0;   

Declare several global variables. C ++ can share their values among multiple functions of the program.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.