Skip to content

Commit 0dfbc25

Browse files
authored
Windows service improvements for hosting, testing, fallback, and extended commands (#3662)
1 parent e07f6bb commit 0dfbc25

File tree

14 files changed

+505
-148
lines changed

14 files changed

+505
-148
lines changed

.github/workflows/test.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ jobs:
141141
run: cargo test -p sample_service_sys --target ${{ matrix.target }}
142142
- name: Test sample_service_thread
143143
run: cargo test -p sample_service_thread --target ${{ matrix.target }}
144+
- name: Test sample_service_time
145+
run: cargo test -p sample_service_time --target ${{ matrix.target }}
144146
- name: Test sample_shell
145147
run: cargo test -p sample_shell --target ${{ matrix.target }}
146148
- name: Test sample_simple
@@ -159,10 +161,10 @@ jobs:
159161
run: cargo test -p sample_uiautomation --target ${{ matrix.target }}
160162
- name: Test sample_wmi
161163
run: cargo test -p sample_wmi --target ${{ matrix.target }}
162-
- name: Test sample_xml
163-
run: cargo test -p sample_xml --target ${{ matrix.target }}
164164
- name: Clean
165165
run: cargo clean
166+
- name: Test sample_xml
167+
run: cargo test -p sample_xml --target ${{ matrix.target }}
166168
- name: Test test_agile
167169
run: cargo test -p test_agile --target ${{ matrix.target }}
168170
- name: Test test_agile_reference
@@ -261,10 +263,10 @@ jobs:
261263
run: cargo test -p test_metadata --target ${{ matrix.target }}
262264
- name: Test test_msrv
263265
run: cargo test -p test_msrv --target ${{ matrix.target }}
264-
- name: Test test_no_std
265-
run: cargo test -p test_no_std --target ${{ matrix.target }}
266266
- name: Clean
267267
run: cargo clean
268+
- name: Test test_no_std
269+
run: cargo test -p test_no_std --target ${{ matrix.target }}
268270
- name: Test test_no_use
269271
run: cargo test -p test_no_use --target ${{ matrix.target }}
270272
- name: Test test_noexcept
@@ -311,6 +313,8 @@ jobs:
311313
run: cargo test -p test_return_handle --target ${{ matrix.target }}
312314
- name: Test test_return_struct
313315
run: cargo test -p test_return_struct --target ${{ matrix.target }}
316+
- name: Test test_services
317+
run: cargo test -p test_services --target ${{ matrix.target }}
314318
- name: Test test_standalone
315319
run: cargo test -p test_standalone --target ${{ matrix.target }}
316320
- name: Test test_string_param
@@ -361,12 +365,12 @@ jobs:
361365
run: cargo test -p tool_msvc --target ${{ matrix.target }}
362366
- name: Test tool_standalone
363367
run: cargo test -p tool_standalone --target ${{ matrix.target }}
368+
- name: Clean
369+
run: cargo clean
364370
- name: Test tool_test_all
365371
run: cargo test -p tool_test_all --target ${{ matrix.target }}
366372
- name: Test tool_workspace
367373
run: cargo test -p tool_workspace --target ${{ matrix.target }}
368-
- name: Clean
369-
run: cargo clean
370374
- name: Test tool_yml
371375
run: cargo test -p tool_yml --target ${{ matrix.target }}
372376
- name: Test windows

crates/libs/services/readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ fn main() {
2020
windows_services::Service::new()
2121
.can_pause()
2222
.can_stop()
23-
.run(|command| {
23+
.run(|service, command| {
2424
// Respond to service commands...
2525
})
26+
.unwrap();
2627
}
2728
```

crates/libs/services/src/bindings.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#![allow(
2-
non_snake_case,
3-
non_upper_case_globals,
4-
non_camel_case_types,
5-
dead_code,
6-
clippy::all
7-
)]
8-
9-
windows_link::link!("advapi32.dll" "system" fn RegisterServiceCtrlHandlerW(lpservicename : PCWSTR, lphandlerproc : LPHANDLER_FUNCTION) -> SERVICE_STATUS_HANDLE);
1+
windows_link::link!("advapi32.dll" "system" fn RegisterServiceCtrlHandlerExW(lpservicename : PCWSTR, lphandlerproc : LPHANDLER_FUNCTION_EX, lpcontext : *const core::ffi::c_void) -> SERVICE_STATUS_HANDLE);
102
windows_link::link!("advapi32.dll" "system" fn SetServiceStatus(hservicestatus : SERVICE_STATUS_HANDLE, lpservicestatus : *const SERVICE_STATUS) -> BOOL);
113
windows_link::link!("advapi32.dll" "system" fn StartServiceCtrlDispatcherW(lpservicestarttable : *const SERVICE_TABLE_ENTRYW) -> BOOL);
124
pub type BOOL = i32;
135
pub type ENUM_SERVICE_TYPE = u32;
14-
pub type LPHANDLER_FUNCTION = Option<unsafe extern "system" fn(dwcontrol: u32)>;
6+
pub type LPHANDLER_FUNCTION_EX = Option<
7+
unsafe extern "system" fn(
8+
dwcontrol: u32,
9+
dweventtype: u32,
10+
lpeventdata: *mut core::ffi::c_void,
11+
lpcontext: *mut core::ffi::c_void,
12+
) -> u32,
13+
>;
1514
pub type LPSERVICE_MAIN_FUNCTIONW =
1615
Option<unsafe extern "system" fn(dwnumservicesargs: u32, lpserviceargvectors: *mut PWSTR)>;
16+
pub const NO_ERROR: WIN32_ERROR = 0u32;
1717
pub type PCWSTR = *const u16;
1818
pub type PWSTR = *mut u16;
1919
pub const SERVICE_ACCEPT_PAUSE_CONTINUE: u32 = 2u32;
@@ -55,3 +55,4 @@ impl Default for SERVICE_TABLE_ENTRYW {
5555
}
5656
}
5757
pub const SERVICE_WIN32_OWN_PROCESS: ENUM_SERVICE_TYPE = 16u32;
58+
pub type WIN32_ERROR = u32;

0 commit comments

Comments
 (0)