Files
umbrix-libcore/admin_service/cmd/main.go

57 lines
1.1 KiB
Go
Raw Normal View History

2024-01-29 21:55:01 +01:00
package main
/*
#cgo LDFLAGS: bin/libcore.dll
#include <stdlib.h>
#include <stdint.h>
// Import the function from the DLL
2024-02-02 13:47:41 +01:00
char* AdminServiceStart(const char* arg);
2024-01-29 21:55:01 +01:00
*/
import "C"
import (
2024-02-02 13:47:41 +01:00
"fmt"
2024-01-29 21:55:01 +01:00
"os"
2024-02-02 13:47:41 +01:00
"strings"
"unsafe"
2024-01-29 21:55:01 +01:00
)
func main() {
args := os.Args
// Check if there is at least one command-line argument
if len(args) < 2 {
println("Usage: hiddify-service.exe empty/start/stop/uninstall/install")
// os.Exit(1)
args = append(args, "")
}
// fmt.Printf("os.Args: %+v", args)
os.Chdir(os.Args[0])
// Convert the Go string to a C string
arg := C.CString(args[1])
// defer C.free(unsafe.Pointer(arg))
// Call AdminServiceStart with the C string
2024-02-02 13:47:41 +01:00
result := C.AdminServiceStart(arg)
goRes := C.GoString(result)
defer C.free(unsafe.Pointer(result))
parts := strings.SplitN(goRes, " ", 2)
var parsedExitCode int
_, err := fmt.Sscanf(parts[0], "%d", &parsedExitCode)
parsedOutMessage := parts[1]
if err != nil {
fmt.Println("Error parsing the string:", err)
return
}
fmt.Printf("%d %s", parsedExitCode, parsedOutMessage)
if parsedExitCode != 0 {
os.Exit(int(parsedExitCode))
}
2024-01-29 21:55:01 +01:00
}