这里是我编写的函数,当然其他调用函数我也写了。只要是单独uint8\uint16\uint32,包括string类型的引用,基本都没有问题。但现在遇到[]byte,一直报错:
func M_TermRecord(control string) (
pData [1000]byte,
noUpLoadNum int16,
recordBaseOver byte,
cardMapOver byte,
err error) {
var (
nargs uintptr = 5
)
//pData, _ = syscall.ByteSliceFromString("pData")
bControl, _ := syscall.BytePtrFromString(control)
ret, _, callErr := syscall.Syscall6(uintptr(termRecord),
nargs,
uintptr(unsafe.Pointer(bControl)),
uintptr(unsafe.Pointer(&pData[0])),
uintptr(unsafe.Pointer(&noUpLoadNum)),
uintptr(unsafe.Pointer(&recordBaseOver)),
uintptr(unsafe.Pointer(&cardMapOver)),
0)
if callErr != 0 && callErr != syscall.ERROR_IO_PENDING {
abort("Failed in func M_TermRecord.", callErr)
}
if ret == 0 {
return pData,
noUpLoadNum,
recordBaseOver,
cardMapOver,
errors.New("M_TermRecord: Failed!")
}
return
}
下面是dll函数说明
function TermRecord(Control:Byte;pData: pbyte;var NoUpLoadNum:Word; var RecordBaseOver,CardMapOver:Boolean): integer;stdcall;external 'DllTermCommPrj.dll';
错误如下:
panic: invalid memory address or nil pointer dereference
fatal error: panic during malloc
[signal 0xc0000005 code=0x0 addr=0x20 pc=0x41d1fa]
runtime stack:
runtime.panic(0x4b3c80, 0x5b00d8)
C:/Users/ADMINI~1/AppData/Local/Temp/2/makerelease529514319/go/src/pkg/runtime/panic.c:233 +0x2b
runtime: unexpected return pc for runtime.asmstdcall called from 0x123d09d0
goroutine 1 [syscall]:
runtime.cgocall(0x422020, 0x202618)
C:/Users/ADMINI~1/AppData/Local/Temp/2/makerelease529514319/go/src/pkg/runtime/cgocall.c:149 +0x1
有疑问加站长微信联系(非本文作者)