diff --git a/edge-ai-platform/tools/test_driver_install/main.go b/edge-ai-platform/tools/test_driver_install/main.go new file mode 100644 index 0000000..29aebb0 --- /dev/null +++ b/edge-ai-platform/tools/test_driver_install/main.go @@ -0,0 +1,75 @@ +// Small test tool to call DiInstallDriverW and print the result. +// Build: GOOS=windows GOARCH=amd64 go build -o test_driver_install.exe . +// Run on Windows: .\test_driver_install.exe "C:\Users\User\AppData\Local\EdgeAIPlatform\drivers\kneron_winusb.inf" + +package main + +import ( + "fmt" + "os" + "syscall" + "unsafe" +) + +func main() { + if len(os.Args) < 2 { + fmt.Println("Usage: test_driver_install.exe ") + os.Exit(1) + } + + infPath := os.Args[1] + fmt.Printf("INF path: %s\n", infPath) + + // Check file exists + if _, err := os.Stat(infPath); err != nil { + fmt.Printf("ERROR: file not found: %v\n", err) + os.Exit(1) + } + + newdev, err := syscall.LoadDLL("newdev.dll") + if err != nil { + fmt.Printf("ERROR: LoadDLL(newdev.dll): %v\n", err) + os.Exit(1) + } + defer newdev.Release() + fmt.Println("newdev.dll loaded OK") + + proc, err := newdev.FindProc("DiInstallDriverW") + if err != nil { + fmt.Printf("ERROR: FindProc(DiInstallDriverW): %v\n", err) + os.Exit(1) + } + fmt.Println("DiInstallDriverW found OK") + + infPathUTF16, err := syscall.UTF16PtrFromString(infPath) + if err != nil { + fmt.Printf("ERROR: UTF16PtrFromString: %v\n", err) + os.Exit(1) + } + + const DIIRFLAG_FORCE_INF = 0x00000002 + var needReboot int32 + + fmt.Println("Calling DiInstallDriverW...") + fmt.Println("(If a Windows Security dialog appears, click 'Install this driver software anyway')") + + ret, _, lastErr := proc.Call( + 0, // hwndParent = NULL + uintptr(unsafe.Pointer(infPathUTF16)), + DIIRFLAG_FORCE_INF, + uintptr(unsafe.Pointer(&needReboot)), + ) + + fmt.Printf("Return value: %d\n", ret) + fmt.Printf("NeedReboot: %d\n", needReboot) + fmt.Printf("LastError: %v\n", lastErr) + + if ret == 0 { + fmt.Println("FAILED - DiInstallDriverW returned FALSE") + // Get actual error code + errCode := lastErr.(syscall.Errno) + fmt.Printf("Error code: %d (0x%X)\n", errCode, errCode) + } else { + fmt.Println("SUCCESS - driver installed!") + } +} diff --git a/edge-ai-platform/tools/test_driver_install/test_driver_install.exe b/edge-ai-platform/tools/test_driver_install/test_driver_install.exe new file mode 100755 index 0000000..02b6528 Binary files /dev/null and b/edge-ai-platform/tools/test_driver_install/test_driver_install.exe differ