0
在开发服务器程序的时候,经常需要的是将程序开发为服务模式,以使得程序不需要系统登陆就可以达到启动的目的。对于windows本身服务程序的开发,一般是使用SCM模式。这里我们来了解一下C++Builder6为我们封装好的TService如何来开发服务应用程序。


To create an application that implements a Win32 service:

引用
1  Choose File|New|Other, and double-click Service Application in the New Items dialog box. This adds a global variable named Application to your project, which is of type TServiceApplication.
2  A Service window appears that corresponds to a service (TService). Implement the service by setting its properties and event handlers in the Object Inspector.
3  You can add additional services to your service application by choosing File|New|Other, and double-click Service in the New Items dialog box. Do not add services to an application that is not a service application. While a TService object can be added, the application will not generate the requisite events or make the appropriate Windows calls on behalf of the service.

4  Once your service application is built, you can install its services with the Service Control Manager (SCM). Other applications can then launch your services by sending requests to the SCM.


上面是C++Builder6的帮助告诉我们应该如何来实现服务程序。大致翻译方法如下:
1:选择 File|New|Other,双击Service Application
2:通过在设计器中输入服务程序的参数,可以为我们的服务定义一些属性。另外可以注意到的是该服务应用程序是从TService继承而来的。
3:注意事项包含我们可以为我们的服务程序添加更多的服务,但是不可以为某个非服务的应用程序添加服务。
4:一旦你的服务程序编译,你可以通过SCM来安装你的服务,其他应用程序可以通过发送请求给SCM来调用你的服务程序。

下面我们来看一下帮助中为了我们提供的例子。

引用
1  To create the example, choose File|New|Other and select Service Application from the New Items dialog box. The Service1 window appears.
2  From the Internet page of the Component palette, add a ServerSocket component to the service window (Service1).
3  Add a private data member of type TMemoryStream to the TService1 class. The header for your unit should now look like this:


1:新建一个Service
2:添加一个ServerSocket 组件到TService模块中
3:添加一个私有变量TMemoryStream 给类TService1



对ServerSocket编写ClientRead事件



Finally, select Service1 by clicking in the window's client area (but not on the ServiceSocket). In the Object Inspector, double click the OnExecute event and add the following event handler:
说明:在对象Inspector区,双击OnExecute 事件为该服务执行时候编写方法:

Tags: , , | 引用(0)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]