Update New API\

master
兔子 6 years ago
parent 40b9dba9f0
commit 739e939fc3

@ -3,6 +3,7 @@ package win32api
import ( import (
"errors" "errors"
"syscall" "syscall"
"unsafe"
) )
func WTSGetActiveConsoleSessionId() (DWORD, error) { func WTSGetActiveConsoleSessionId() (DWORD, error) {
@ -34,3 +35,51 @@ func CloseHandle(hObject HANDLE) error {
} }
return nil return nil
} }
func CreateToolhelp32Snapshot(dwFlags, th32ProcessID DWORD) (HANDLE, error) {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return 0, errors.New("Can't Load Kernel32 API")
}
defer syscall.FreeLibrary(kernel32)
CTS, err := syscall.GetProcAddress(syscall.Handle(kernel32), "CreateToolhelp32Snapshot")
if err != nil {
return 0, errors.New("Can't Load CreateToolhelp32Snapshot API")
}
r, _, err := syscall.Syscall(uintptr(CTS), 2, uintptr(dwFlags), uintptr(th32ProcessID), 0)
if int(r) == -1 {
return 0, err
}
return HANDLE(r), nil
}
func Process32Next(hSnapshot HANDLE, lppe *PROCESSENTRY32) error {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return errors.New("Can't Load Kernel32 API")
}
defer syscall.FreeLibrary(kernel32)
PN, err := syscall.GetProcAddress(syscall.Handle(kernel32), "Process32Next")
if err != nil {
return errors.New("Can't Load Process32Next API")
}
r, _, err := syscall.Syscall(uintptr(PN), 2, uintptr(hSnapshot), uintptr(unsafe.Pointer(lppe)), 0)
if int(r) != 1 {
return err
}
return nil
}
func GetProcessId(Process HANDLE) uint32 {
kernel32, err := syscall.LoadLibrary("kernel32.dll")
if err != nil {
return 0
}
defer syscall.FreeLibrary(kernel32)
GPI, err := syscall.GetProcAddress(syscall.Handle(kernel32), "GetProcessId")
if err != nil {
return 0
}
r, _, _ := syscall.Syscall(uintptr(GPI), 1, uintptr(Process), 0, 0)
return uint32(r)
}

@ -0,0 +1,17 @@
package win32api
type Ulong int32
type Ulong_ptr uintptr
type PROCESSENTRY32 struct {
DwSize Ulong
CntUsage Ulong
Th32ProcessID Ulong
Th32DefaultHeapID Ulong_ptr
Th32ModuleID Ulong
CntThreads Ulong
Th32ParentProcessID Ulong
PcPriClassBase Ulong
DwFlags Ulong
SzExeFile [260]byte
}

@ -69,7 +69,7 @@ func ShellExecuteEX2(hwnd HWND, lpVerb, lpFile, lpParameters, lpDirectory string
} }
*/ */
func ShellExecuteEx(muzika SHELLEXECUTEINFOW) error { func ShellExecuteEx(muzika *SHELLEXECUTEINFOW) error {
shell32, err := syscall.LoadLibrary("shell32.dll") shell32, err := syscall.LoadLibrary("shell32.dll")
if err != nil { if err != nil {
@ -80,9 +80,9 @@ func ShellExecuteEx(muzika SHELLEXECUTEINFOW) error {
if err != nil { if err != nil {
return errors.New("Can't Load ShellExecuteEx API") return errors.New("Can't Load ShellExecuteEx API")
} }
r, _, _ := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(&muzika)), 0, 0, 0, 0, 0) r, _, err := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(muzika)), 0, 0, 0, 0, 0)
if r != 0 { if r == 0 {
return errors.New("Error Recured") return err
} }
return nil return nil
} }

@ -1,24 +1,24 @@
package win32api package win32api
type SHELLEXECUTEINFOW struct { type SHELLEXECUTEINFOW struct {
cbSize DWORD CbSize DWORD
fMask ULONG FMask ULONG
hwnd HWND Hwnd HWND
lpVerb string LpVerb uintptr
lpFile string LpFile uintptr
lpParameters string LpParameters uintptr
lpDirectory string LpDirectory uintptr
nShow int NShow int
hInstApp HINSTANCE HInstApp HINSTANCE
lpIDList LPVOID LpIDList LPVOID
lpClass string LpClass uintptr
hkeyClass HKEY HkeyClass HKEY
dwHotKey DWORD DwHotKey DWORD
union UNION UnionorHMonitor HANDLE
hProcess HANDLE HProcess HANDLE
} }
type UNION struct { type UNION struct {
hIcon HANDLE HIcon HANDLE
hMonitor HANDLE HMonitor HANDLE
} }

Loading…
Cancel
Save