这是我的代码:
package main
import (
"fmt"
"syscall"
"unsafe"
)
var (
WinSCard, _ = syscall.LoadLibrary("C:\\windows\\system32\\WinSCard.dll")
procSCardListReaders, _ = syscall.GetProcAddress(WinSCard, "SCardListReaders")
procSCardEstablishContext, _ = syscall.GetProcAddress(WinSCard, "SCardEstablishContext")
)
func abort(funcname string, err error) {
panic(fmt.Sprintf("%s failed: %v", funcname, err))
}
func SCardEstablishContext(dwScope uint32, pvReserved1 *uint32, pvReserved2 *uint32, phContext uintptr) int32 {
ret, _, callErr := syscall.Syscall6(uintptr(procSCardEstablishContext),
4,
uintptr(unsafe.Pointer(&dwScope)),
uintptr(unsafe.Pointer(pvReserved1)),
uintptr(unsafe.Pointer(pvReserved2)),
phContext,
0,
0)
if callErr != 0 {
abort("Err:", callErr)
}
return int32(ret)
}
func main() {
var Hwd uintptr
defer syscall.FreeLibrary(WinSCard)
rt := SCardEstablishContext(0, nil, nil, Hwd)
fmt.Println(rt)
}
返回 -2146435068 表示 0x80100004 表示 SCARD_E_INVALID_PARAMETER。一个或多个提供的参数无法正确解释。
func SCardEstablishContext:
LONG WINAPI SCardEstablishContext(
_In_ DWORD dwScope,
_In_ LPCVOID pvReserved1,
_In_ LPCVOID pvReserved2,
_Out_ LPSCARDCONTEXT phContext
)
我的参数有什么问题?多谢!!
怎么样
func SCardListReaders(hContext *syscall.Handle, mszGroups string, mszReaders *byte, pcchReaders *uint32) (err error) {
r1, _, e1 := syscall.Syscall6(
uintptr(procSCardListReaders),
4,
uintptr(unsafe.Pointer(hContext)),
uintptr(unsafe.Pointer(syscall.StringBytePtr(mszGroups))),
uintptr(unsafe.Pointer(mszReaders)),
uintptr(unsafe.Pointer(pcchReaders)),
0,
0,
)
if r1 != 0 {
if e1 != 0 {
err = error(e1)
} else {
err = syscall.EINVAL
}
}
return
}
var Groups string
var Readers byte
var pcchReaders uint32
er1 := SCardListReaders(&context, Groups, &Readers, &pcchReaders)
if er1 != nil {
fmt.Println("SCardListReaders:", er1)
return
}
返回:无效参数