Skip to content

Commit 355b863

Browse files
authored
Merge pull request #41 from ntoskrnl7/chore/nuget-docs-release-name-alignment
chore: improve NuGet README examples for IOCTL/RPC consumer usage
2 parents c5989e3 + 75c76e5 commit 355b863

1 file changed

Lines changed: 173 additions & 11 deletions

File tree

nuget/README.md

Lines changed: 173 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ It brings managed access to selected MSVC/C++ runtime, CRT/STL style APIs, and
55
NTL abstractions so WDK driver code can be written in a more natural C++ flow.
66

77
This NuGet package is for **Visual Studio/MSBuild** consumers (`crtsys.<version>.nupkg`).
8-
It is not a CMake package.
98

10-
## Quick start (MSBuild)
9+
## Quick start
1110

1211
```powershell
1312
Install-Package crtsys
@@ -17,7 +16,15 @@ Install-Package crtsys
1716
- Driver projects (WDK) get automatic WDK linkage for
1817
`crtsys.lib` / `Ldk.lib` (x64/ARM64).
1918

20-
Example (driver entry concept):
19+
What this NuGet package is for:
20+
21+
- Modern C++ ownership for control-plane code (`ntl::driver`, `ntl::device`,
22+
unload callback)
23+
- Small, readable status/error flow with `ntl::status`
24+
- Shared user↔kernel contracts from a single header source (`shared/*.hpp`)
25+
- Reliable RAII-style lifecycle for driver resources and cleanup
26+
27+
Example (minimal driver entry):
2128

2229
```cpp
2330
#include <ntl/driver>
@@ -30,6 +37,162 @@ ntl::status ntl::main(ntl::driver& driver,
3037
}
3138
```
3239
40+
### IOCTL sample (kernel + app pair)
41+
42+
Shared header (`shared/demo_ioctl.hpp`):
43+
44+
```cpp
45+
// shared/demo_ioctl.hpp
46+
#pragma once
47+
48+
#define DEMO_DEVICE_NAME L"demo_device"
49+
#define DEMO_IOCTL_ECHO \
50+
CTL_CODE(FILE_DEVICE_UNKNOWN, 0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)
51+
```
52+
53+
Kernel side:
54+
55+
```cpp
56+
#include <string>
57+
#include <wdm.h>
58+
#include <ntl/driver>
59+
#include "shared/demo_ioctl.hpp" // DEMO_DEVICE_NAME/DEMO_IOCTL_*
60+
61+
ntl::status ntl::main(ntl::driver& driver,
62+
const std::wstring& registry_path) {
63+
(void)registry_path;
64+
65+
auto options = ntl::device_options()
66+
.name(DEMO_DEVICE_NAME)
67+
.type(FILE_DEVICE_UNKNOWN)
68+
.exclusive(false);
69+
70+
auto device = driver.create_device<void>(options);
71+
device->on_device_control([](const ntl::device_control::code& code,
72+
const ntl::device_control::in_buffer& in,
73+
ntl::device_control::out_buffer& out) {
74+
// register IRP_MJ_DEVICE_CONTROL logic without switch-heavy boilerplate
75+
if (code == DEMO_IOCTL_ECHO && in.ptr && out.ptr) {
76+
const auto bytes = in.size < out.size ? in.size : out.size;
77+
RtlCopyMemory(out.ptr, in.ptr, bytes);
78+
out.size = bytes;
79+
}
80+
});
81+
82+
driver.on_unload([device]() mutable {
83+
// keep cleanup in one place; shared_ptr reset happens on unload
84+
device.reset();
85+
});
86+
87+
return ntl::status::ok();
88+
}
89+
```
90+
91+
App side:
92+
93+
```cpp
94+
#define WIN32_LEAN_AND_MEAN
95+
#include <windows.h>
96+
#include <winioctl.h>
97+
#include <iostream>
98+
#include "shared/demo_ioctl.hpp"
99+
100+
int wmain() {
101+
const HANDLE device = CreateFileW(
102+
L"\\\\?\\Global\\GLOBALROOT\\Device\\" DEMO_DEVICE_NAME,
103+
GENERIC_READ | GENERIC_WRITE,
104+
0, nullptr, OPEN_EXISTING, 0, nullptr);
105+
106+
if (device == INVALID_HANDLE_VALUE) {
107+
std::cerr << "failed to open device\n";
108+
return 1;
109+
}
110+
111+
char request[] = "hello";
112+
char reply[sizeof request] = {};
113+
DWORD returned = 0;
114+
const BOOL ok = DeviceIoControl(device,
115+
DEMO_IOCTL_ECHO,
116+
request,
117+
static_cast<DWORD>(sizeof request),
118+
reply,
119+
static_cast<DWORD>(sizeof reply),
120+
&returned,
121+
nullptr);
122+
CloseHandle(device);
123+
if (!ok) {
124+
std::cerr << "DeviceIoControl failed\n";
125+
return 1;
126+
}
127+
return 0;
128+
}
129+
```
130+
131+
### RPC sample (kernel + app pair)
132+
133+
Shared header (`shared/demo_rpc.hpp`):
134+
135+
```cpp
136+
// shared/demo_rpc.hpp
137+
#pragma once
138+
139+
NTL_RPC_BEGIN(demo_rpc)
140+
141+
NTL_ADD_CALLBACK_2(demo_rpc, int, add, int, a, int, b, {
142+
return a + b;
143+
})
144+
145+
NTL_ADD_CALLBACK_1(demo_rpc, int, negate, int, value, {
146+
return -value;
147+
})
148+
149+
NTL_RPC_END(demo_rpc)
150+
```
151+
152+
Kernel side:
153+
154+
```cpp
155+
#include <memory>
156+
#include <ntl/driver>
157+
#include <ntl/rpc/server>
158+
#include "shared/demo_rpc.hpp" // generated RPC contract header
159+
160+
ntl::status ntl::main(ntl::driver& driver,
161+
const std::wstring& registry_path) {
162+
(void)registry_path;
163+
164+
auto rpc_server = demo_rpc::init(driver); // creates \\Device\\demo_rpc endpoint
165+
166+
driver.on_unload([rpc_server]() mutable {
167+
rpc_server.reset(); // remove endpoint before driver unload completes
168+
});
169+
170+
return ntl::status::ok();
171+
}
172+
```
173+
174+
App side:
175+
176+
```cpp
177+
#include <exception>
178+
#include <iostream>
179+
#include <ntl/rpc/client>
180+
#include "shared/demo_rpc.hpp" // same shared contract header
181+
182+
int wmain() {
183+
try {
184+
std::wcout << L"40 + 2 = " << demo_rpc::add(40, 2) << L"\n";
185+
ntl::rpc::client client(L"demo_rpc");
186+
auto value = client.invoke<int>(demo_rpc::negate_1_index, 7);
187+
std::wcout << L"negate(7) = " << value << L"\n";
188+
} catch (const std::exception& e) {
189+
std::cerr << "RPC call failed: " << e.what() << "\n";
190+
return 1;
191+
}
192+
return 0;
193+
}
194+
```
195+
33196
This package does not install the WDK/SDK itself and does not convert a normal C++
34197
project into a driver project.
35198

@@ -40,14 +203,13 @@ project into a driver project.
40203
- prebuilt libs:
41204
`lib/native/{x64,ARM64}/{Debug,Release}/(crtsys.lib|Ldk.lib)`
42205

43-
## Release artifacts (same version, not NuGet)
44-
45-
GitHub Release publishes these in addition to the `.nupkg`:
46-
47-
- `crtsys-<version>-prebuilt.zip`
48-
- `crtsys-<version>-SHA256SUMS.txt`
206+
## Release artifacts
49207

50-
These two are release-only artifacts and are **not part of the NuGet package**.
208+
- `crtsys-<version>-prebuilt.zip`
209+
A prebuilt bundle containing headers, libraries, documentation, and CMake helpers.
210+
It includes `CrtSys.cmake` for CMake-based consumers, and also carries the same native MSBuild build support files.
211+
- `crtsys-<version>-SHA256SUMS.txt`
212+
Checksum file for offline/manual verification.
51213

52-
For full release workflow, CMake distribution, and API usage details, see:
214+
For full package usage, release details, and API reference, see:
53215
- <https://github.com/ntoskrnl7/crtsys/blob/main/README.md>

0 commit comments

Comments
 (0)