chore: add test tool for DiInstallDriverW debugging on Windows

Build: already cross-compiled as test_driver_install.exe
Usage: .\test_driver_install.exe "C:\path\to\kneron_winusb.inf"

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jim800121chen 2026-03-10 00:15:31 +08:00
parent cc1edfc89d
commit faa4e86a19
2 changed files with 75 additions and 0 deletions

View File

@ -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 <path-to-inf>")
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!")
}
}