You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
win32api/shell32.go

103 lines
3.0 KiB
Go

6 years ago
package win32api
import (
"errors"
"strconv"
"syscall"
"unsafe"
)
func ShellExecute(hwnd HWND, lpOperation, lpFile, lpParameters, lpDirectory string, nShowCmd int) error {
shell32, err := syscall.LoadLibrary("shell32.dll")
var op, param, directory uintptr
if err != nil {
return errors.New("Can't Load Shell32 API")
}
defer syscall.FreeLibrary(shell32)
ShellExecute, err := syscall.GetProcAddress(syscall.Handle(shell32), "ShellExecuteW")
if err != nil {
return errors.New("Can't Load ShellExecute API")
}
if len(lpOperation) != 0 {
op = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpOperation)))
}
if len(lpParameters) != 0 {
param = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpParameters)))
}
if len(lpDirectory) != 0 {
directory = uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpDirectory)))
}
r, _, _ := syscall.Syscall6(uintptr(ShellExecute), 6,
uintptr(hwnd),
op,
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(lpFile))),
param,
directory,
uintptr(nShowCmd))
if r < 32 {
return errors.New("ERROR:" + strconv.Itoa(int(r)))
}
return nil
}
/**
func ShellExecuteEX2(hwnd HWND, lpVerb, lpFile, lpParameters, lpDirectory string, nShow int) error {
var newcmd SHELLEXECUTEINFOW
newcmd.cbSize = DWORD(unsafe.Sizeof(newcmd))
newcmd.hwnd = hwnd
newcmd.lpVerb = lpVerb
newcmd.lpFile = lpFile
newcmd.lpParameters = lpParameters
newcmd.lpDirectory = lpDirectory
newcmd.nShow = nShow
shell32, err := syscall.LoadLibrary("shell32.dll")
if err != nil {
return errors.New("Can't Load Shell32 API")
}
defer syscall.FreeLibrary(shell32)
ShellExecuteEx, err := syscall.GetProcAddress(syscall.Handle(shell32), "ShellExecuteExW")
if err != nil {
return errors.New("Can't Load ShellExecuteEx API")
}
r, _, _ := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(&newcmd)), 0, 0, 0, 0, 0)
fmt.Println(strconv.Itoa(int(r)))
fmt.Println(strconv.Itoa(int(newcmd.hInstApp)))
if r != 0 {
return errors.New("Error Recured")
}
return nil
}
*/
6 years ago
func ShellExecuteEx(muzika *SHELLEXECUTEINFOW) error {
6 years ago
shell32, err := syscall.LoadLibrary("shell32.dll")
if err != nil {
return errors.New("Can't Load Shell32 API")
}
defer syscall.FreeLibrary(shell32)
ShellExecuteEx, err := syscall.GetProcAddress(syscall.Handle(shell32), "ShellExecuteExW")
if err != nil {
return errors.New("Can't Load ShellExecuteEx API")
}
3 years ago
r, _, errno := syscall.Syscall6(ShellExecuteEx, 1, uintptr(unsafe.Pointer(muzika)), 0, 0, 0, 0, 0)
6 years ago
if r == 0 {
3 years ago
return error(errno)
6 years ago
}
return nil
}
func DragQueryFile(hDrop HDROP, iFile DWORD, lpszFile *uint16, cch DWORD) (DWORD, error) {
shell32, err := syscall.LoadLibrary("shell32.dll")
if err != nil {
return 0, err
}
defer syscall.FreeLibrary(shell32)
dqf, err := syscall.GetProcAddress(syscall.Handle(shell32), "DragQueryFileW")
if err != nil {
return 0, err
}
r, _, _ := syscall.Syscall6(dqf, 4, uintptr(hDrop), uintptr(iFile), uintptr(unsafe.Pointer(lpszFile)), uintptr(cch), 0, 0)
return DWORD(r), nil
}