修正windows下的golint问题

This commit is contained in:
lwch
2021-11-04 15:15:18 +08:00
parent 77f1ab1bde
commit c0c1091f91
7 changed files with 24 additions and 22 deletions

View File

@@ -37,8 +37,8 @@ const (
) )
const ( const (
// BI_RGB https://docs.microsoft.com/en-us/previous-versions/dd183376(v=vs.85) // BIRGB https://docs.microsoft.com/en-us/previous-versions/dd183376(v=vs.85)
BI_RGB = 0 BIRGB = 0
// DIB_RGB_COLORS https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits // DIBRGBCOLORS https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdibits
DIB_RGB_COLORS = 0 DIBRGBCOLORS = 0
) )

View File

@@ -4,26 +4,26 @@ import "syscall"
var ( var (
libKernel32, _ = syscall.LoadLibrary("kernel32.dll") libKernel32, _ = syscall.LoadLibrary("kernel32.dll")
// FuncWTSGetActiveConsoleSessionId https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid // FuncWTSGetActiveConsoleSessionID https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-wtsgetactiveconsolesessionid
FuncWTSGetActiveConsoleSessionId, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "WTSGetActiveConsoleSessionId") FuncWTSGetActiveConsoleSessionID, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "WTSGetActiveConsoleSessionId")
// FuncGlobalAlloc https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // FuncGlobalAlloc https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
FuncGlobalAlloc, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalAlloc") FuncGlobalAlloc, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalAlloc")
// FuncGlobalFree https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalfree // FuncGlobalFree https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalfree
FuncGlobalFree, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalFree") FuncGlobalFree, _ = syscall.GetProcAddress(syscall.Handle(libKernel32), "GlobalFree")
) )
// PROCESS_ALL_ACCESS https://docs.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights // PROCESSALLACCESS https://docs.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
const PROCESS_ALL_ACCESS = 0x1F0FFF const PROCESSALLACCESS = 0x1F0FFF
const ( const (
// GHND https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // GHND https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GHND = 0x0042 GHND = 0x0042
// GMEM_FIXED https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // GMEMFIXED https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEM_FIXED = 0x0000 GMEMFIXED = 0x0000
// GMEM_MOVEABLE https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // GMEMMOVEABLE https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEM_MOVEABLE = 0x0002 GMEMMOVEABLE = 0x0002
// GMEM_ZEROINIT https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // GMEMZEROINIT https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GMEM_ZEROINIT = 0x0040 GMEMZEROINIT = 0x0040
// GPTR https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc // GPTR https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc
GPTR = 0x0040 GPTR = 0x0040
) )

View File

@@ -65,6 +65,6 @@ type ICONINFO struct {
} }
const ( const (
// CURSOR_SHOWING https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo // CURSORSHOWING https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-cursorinfo
CURSOR_SHOWING = 0x00000001 CURSORSHOWING = 0x00000001
) )

View File

@@ -7,6 +7,7 @@ import (
"github.com/lwch/logging" "github.com/lwch/logging"
) )
// CADEvent handle ctrl+alt+del event
func (p *Process) CADEvent() { func (p *Process) CADEvent() {
ok, _, err := syscall.Syscall(define.FuncSendSAS, 1, 0, 0, 0) ok, _, err := syscall.Syscall(define.FuncSendSAS, 1, 0, 0, 0)
if ok == 0 { if ok == 0 {

View File

@@ -62,13 +62,13 @@ func parseProcessName(exeFile [syscall.MAX_PATH]uint16) string {
} }
func getSessionID() uintptr { func getSessionID() uintptr {
id, _, _ := syscall.Syscall(define.FuncWTSGetActiveConsoleSessionId, 0, 0, 0, 0) id, _, _ := syscall.Syscall(define.FuncWTSGetActiveConsoleSessionID, 0, 0, 0, 0)
return id return id
} }
func getSessionUserTokenWin() windows.Token { func getSessionUserTokenWin() windows.Token {
pid := getLogonPid(getSessionID()) pid := getLogonPid(getSessionID())
process, err := windows.OpenProcess(define.PROCESS_ALL_ACCESS, false, pid) process, err := windows.OpenProcess(define.PROCESSALLACCESS, false, pid)
if err != nil { if err != nil {
return 0 return 0
} }

View File

@@ -92,7 +92,7 @@ func (worker *Worker) capture() error {
logging.Error("get cursor info: %v", err) logging.Error("get cursor info: %v", err)
return nil return nil
} }
if curInfo.Flags == define.CURSOR_SHOWING { if curInfo.Flags == define.CURSORSHOWING {
var info define.ICONINFO var info define.ICONINFO
ok, _, err = syscall.Syscall(define.FuncGetIconInfo, 2, uintptr(curInfo.HCursor), uintptr(unsafe.Pointer(&info)), 0) ok, _, err = syscall.Syscall(define.FuncGetIconInfo, 2, uintptr(curInfo.HCursor), uintptr(unsafe.Pointer(&info)), 0)
if ok == 0 { if ok == 0 {
@@ -110,6 +110,7 @@ func (worker *Worker) capture() error {
return nil return nil
} }
// BITMAPINFOHEADER https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
type BITMAPINFOHEADER struct { type BITMAPINFOHEADER struct {
BiSize uint32 BiSize uint32
BiWidth int32 BiWidth int32
@@ -131,10 +132,10 @@ func (worker *Worker) copyImageData(hdc, bitmap uintptr) {
hdr.BiBitCount = uint16(worker.info.bits) hdr.BiBitCount = uint16(worker.info.bits)
hdr.BiWidth = int32(worker.info.width) hdr.BiWidth = int32(worker.info.width)
hdr.BiHeight = int32(-worker.info.height) hdr.BiHeight = int32(-worker.info.height)
hdr.BiCompression = define.BI_RGB hdr.BiCompression = define.BIRGB
hdr.BiSizeImage = 0 hdr.BiSizeImage = 0
lines, _, err := syscall.Syscall9(define.FuncGetDIBits, 7, hdc, bitmap, 0, uintptr(worker.info.height), lines, _, err := syscall.Syscall9(define.FuncGetDIBits, 7, hdc, bitmap, 0, uintptr(worker.info.height),
worker.buffer, uintptr(unsafe.Pointer(&hdr)), define.DIB_RGB_COLORS, 0, 0) worker.buffer, uintptr(unsafe.Pointer(&hdr)), define.DIBRGBCOLORS, 0, 0)
if lines == 0 { if lines == 0 {
logging.Error("get bits: %v", err) logging.Error("get bits: %v", err)
} }

View File

@@ -100,7 +100,7 @@ func (worker *Worker) updateInfo(hdc uintptr) error {
} }
func (worker *Worker) updateBuffer() error { func (worker *Worker) updateBuffer() error {
addr, _, err := syscall.Syscall(define.FuncGlobalAlloc, 2, define.GMEM_FIXED, uintptr(worker.info.bits*worker.info.width*worker.info.height/8), 0) addr, _, err := syscall.Syscall(define.FuncGlobalAlloc, 2, define.GMEMFIXED, uintptr(worker.info.bits*worker.info.width*worker.info.height/8), 0)
if addr == 0 { if addr == 0 {
return fmt.Errorf("global alloc: %v", err) return fmt.Errorf("global alloc: %v", err)
} }