golang.zx2c4.com/wireguard/windows@v0.5.4-0.20230123132234-dcc0eb72a04b/embeddable-dll-service/README.md (about) 1 ## Embeddable WireGuard Tunnel Library 2 3 This allows embedding WireGuard as a service inside of another application. Build `tunnel.dll` by running `./build.bat` in this folder. The first time you run it, it will invoke `..\build.bat` simply for downloading dependencies. After, you should have `amd64/tunnel.dll`, `x86/tunnel.dll`, and `arm64/tunnel.dll`. In addition, `tunnel.dll` requires `wireguard.dll`, which can be downloaded from [the wireguard-nt download server](https://download.wireguard.com/wireguard-nt/). 4 5 The basic setup to use `tunnel.dll` is: 6 7 ##### 1. Install a service with these parameters: 8 9 ```text 10 Service Name: "WireGuardTunnel$SomeTunnelName" 11 Display Name: "Some Service Name" 12 Service Type: SERVICE_WIN32_OWN_PROCESS 13 Start Type: StartAutomatic 14 Error Control: ErrorNormal, 15 Dependencies: [ "Nsi", "TcpIp" ] 16 Sid Type: SERVICE_SID_TYPE_UNRESTRICTED 17 Executable: "C:\path\to\example\vpnclient.exe /service configfile.conf" 18 ``` 19 20 Some of these may have to be changed with `ChangeServiceConfig2` after the 21 initial call to `CreateService` The `SERVICE_SID_TYPE_UNRESTRICTED` parameter 22 is absolutely essential; do not forget it. 23 24 ##### 2. Have your program's main function handle the `/service` switch: 25 26 ```c 27 if (wargc == 3 && !wcscmp(wargv[1], L"/service")) { 28 HMODULE tunnel_lib = LoadLibrary("tunnel.dll"); 29 if (!tunnel_lib) 30 abort(); 31 BOOL (_cdecl *tunnel_proc)(_In_ LPCWSTR conf_file); 32 *(FARPROC*)&tunnel_proc = GetProcAddress(tunnel_lib, "WireGuardTunnelService"); 33 if (!tunnel_proc) 34 abort(); 35 return tunnel_proc(wargv[2]); 36 } 37 ``` 38 39 ##### 3. Scoop up logs by implementing a ringlogger format reader. 40 41 There is a sample implementation of bits and pieces of this inside of the `csharp\` directory.