aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-10-08 10:59:06 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-09 09:44:03 +0200
commiteda67e08cd8eb9a54692d0999d8fb5780cda9f36 (patch)
treedfec681d4b1129ee08e0383ea621ccee898028c7
parenttunnel: print wintun version in debug log (diff)
downloadwireguard-windows-eda67e08cd8eb9a54692d0999d8fb5780cda9f36.tar.xz
wireguard-windows-eda67e08cd8eb9a54692d0999d8fb5780cda9f36.zip
embeddable-dll-service: do not marshall go strings
-rw-r--r--embeddable-dll-service/csharp/Service.cs14
-rw-r--r--embeddable-dll-service/main.go4
2 files changed, 4 insertions, 14 deletions
diff --git a/embeddable-dll-service/csharp/Service.cs b/embeddable-dll-service/csharp/Service.cs
index 1375a3cb..4ad9fe47 100644
--- a/embeddable-dll-service/csharp/Service.cs
+++ b/embeddable-dll-service/csharp/Service.cs
@@ -19,20 +19,8 @@ namespace Tunnel
private const string LongName = "Example WireGuard Tunnel Client";
private const string Description = "A WireGuard tunnel created by example code.";
- [StructLayout(LayoutKind.Sequential)]
- private struct GoString
- {
- public string str;
- public long len;
- }
-
[DllImport("tunnel.dll", EntryPoint = "WireGuardTunnelService", CallingConvention = CallingConvention.Cdecl)]
- private static extern bool WireGuardTunnelService(GoString configFile);
-
- public static bool Run(string configFile)
- {
- return WireGuardTunnelService(new GoString { str = configFile, len = configFile.Length });
- }
+ public static extern bool Run([MarshalAs(UnmanagedType.LPWStr)] string configFile);
public static NamedPipeClientStream GetPipe(string configFile)
{
diff --git a/embeddable-dll-service/main.go b/embeddable-dll-service/main.go
index edf72fba..27fca4ee 100644
--- a/embeddable-dll-service/main.go
+++ b/embeddable-dll-service/main.go
@@ -9,6 +9,7 @@ import (
"C"
"golang.org/x/crypto/curve25519"
+ "golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/windows/conf"
"golang.zx2c4.com/wireguard/windows/tunnel"
@@ -20,7 +21,8 @@ import (
)
//export WireGuardTunnelService
-func WireGuardTunnelService(confFile string) bool {
+func WireGuardTunnelService(confFile16 *uint16) bool {
+ confFile := windows.UTF16ToString((*[(1 << 30) - 1]uint16)(unsafe.Pointer(confFile16))[:])
conf.PresetRootDirectory(filepath.Dir(confFile))
tunnel.UseFixedGUIDInsteadOfDeterministic = true
err := tunnel.Run(confFile)