⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 本站的wince代码比较少
💻 CS
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -