golang调用dll传递数组参数问题

func qztPreview2(w http.ResponseWriter, req *http.Request) {
req.ParseForm() //解析参数,默认是不会解析的
for k, v := range req.Form {
fmt.Println("key:", k)
fmt.Println("val:", strings.Join(v, ""))
}

font_path:=[]string{"C://Windows/Fonts/AdobeHeitiStd-Regular.otf","C://Windows/Fonts/AdobeFanHeitiStd-Bold.otf"}
fontCount := 2
fontSize := 12
fd := make([]byte,1000000)
var imgSize []int64
var stSubImgPoslist []StSubImgPos

dll, _  := syscall.LoadLibrary("libOperFont_x64.dll")
getFontPreview, _ := syscall.GetProcAddress(dll, "GetFontPreview")

ret, _, callErr := syscall.Syscall9(getFontPreview,
    7,
    uintptr(unsafe.Pointer(&font_path)),//字体路径
    uintptr(fontCount),//字体个数
    StrPtr("aaa测试"),//显示文字
    uintptr(fontSize),//字体大小
    uintptr(unsafe.Pointer(&fd)),//返回字节流
    uintptr(unsafe.Pointer(&imgSize)),//每个图片大小
    uintptr(unsafe.Pointer(&stSubImgPoslist)),
    0,0)
if callErr != 0 {
    println("error:",callErr)
}
println("get the result:",ret)
w.Write(fd)

}

报错信息:
2016/08/05 17:22:10 http: panic serving 127.0.0.1:51780: runtime error: slice bounds out of range
goroutine 5 [running]:
net/http.(*conn).serve.func1(0xc04205e280)
C:/Go/src/net/http/server.go:1492 +0x131
panic(0x60e460, 0xc042004040)
C:/Go/src/runtime/panic.go:458 +0x251
net/http.DetectContentType(0xa1a0a0d474e5089, 0x524448490d000000, 0x0, 0xc, 0x777ec0)
C:/Go/src/net/http/sniff.go:23 +0x1aa
net/http.(*chunkWriter).writeHeader(0xc04203d628, 0xa1a0a0d474e5089, 0x524448490d000000, 0x0)
C:/Go/src/net/http/server.go:1130 +0xe5b
net/http.(*chunkWriter).Write(0xc04203d628, 0xa1a0a0d474e5089, 0x524448490d000000, 0x0, 0x0, 0x49583b, 0xc04205e2e8)
C:/Go/src/net/http/server.go:311 +0x356
bufio.(*Writer).Write(0xc04200a740, 0xa1a0a0d474e5089, 0x524448490d000000, 0x0, 0x1, 0x64ffb2, 0x1)
C:/Go/src/bufio/bufio.go:595 +0x15f
net/http.(*response).write(0xc04203d5f0, 0x524448490d000000, 0xa1a0a0d474e5089, 0x524448490d000000, 0x0, 0x0, 0x0, 0xc04202dad0, 0x42bfa7, 0x777488)
C:/Go/src/net/http/server.go:1340 +0x147
net/http.(*response).Write(0xc04203d5f0, 0xa1a0a0d474e5089, 0x524448490d000000, 0x0, 0x1, 0x0, 0x73f180)
C:/Go/src/net/http/server.go:1312 +0x6b
main.qztPreview(0x741200, 0xc04203d5f0, 0xc0420b60f0)
D:/workspase_go/qzt_server/src/qzt_preview.go:50 +0x655
net/http.HandlerFunc.ServeHTTP(0x66fcf8, 0x741200, 0xc04203d5f0, 0xc0420b60f0)
C:/Go/src/net/http/server.go:1727 +0x4b
net/http.(*ServeMux).ServeHTTP(0x75ae40, 0x741200, 0xc04203d5f0, 0xc0420b60f0)
C:/Go/src/net/http/server.go:2023 +0x86
net/http.serverHandler.ServeHTTP(0xc04205e200, 0x741200, 0xc04203d5f0, 0xc0420b60f0)
C:/Go/src/net/http/server.go:2203 +0x84
net/http.(*conn).serve(0xc04205e280, 0x7415c0, 0xc04200a600)
C:/Go/src/net/http/server.go:1580 +0x4be
created by net/http.(*Server).Serve
C:/Go/src/net/http/server.go:2296 +0x44e

1个回答

数组越界了。你传入的数组是不是有问题

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问