form1.cs

来自「windows CE 一些有用的源代码 比如camera」· CS 代码 · 共 64 行

CS
64
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ServiceControl
{
    public partial class Form1 : Form
    {
        [DllImport("CoreDLL.DLL")]
        private static extern IntPtr RegisterService(string lpszType, int dwIndex, string lpszLib, int dwInfo);

        [DllImport("CoreDLL.DLL")]
        private static extern int DeregisterService(IntPtr Handle);

        [DllImport("CoreDLL.DLL")]
        private static extern int DeviceIoControl(  IntPtr hDevice, 
                                                    int dwIoControlCode, 
                                                    IntPtr lpInBuffer, 
                                                    int nInBufferSize, 
                                                    IntPtr lpOutBuffer, 
                                                    int nOutBufferSize, 
                                                    IntPtr lpBytesReturned, 
                                                    IntPtr lpOverlapped);


        [DllImport("CoreDLL.DLL")]
        private static extern int GetLastError();

        [DllImport("CoreDLL.DLL")]
        private static extern IntPtr ActivateService( string lpszDevKey, int dwClientInfo);
        
        public Form1()
        {
            InitializeComponent();
        }
        private IntPtr ServiceHandle;

        private void button1_Click(object sender, EventArgs e)
        {
            ServiceHandle = RegisterService("PSV", 0, @"\windows\ServiceWrapper.DLL", 0);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // Run
            DeviceIoControl(ServiceHandle, 2048, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DeviceIoControl(ServiceHandle, 2049, IntPtr.Zero, 0, IntPtr.Zero, 0, IntPtr.Zero, IntPtr.Zero);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            DeregisterService(ServiceHandle);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?