From 1c10d6c89f0b0c5b4413aeee9dc4fdf79b415ca0 Mon Sep 17 00:00:00 2001 From: Starainrt Date: Sun, 14 Oct 2018 17:58:47 +0800 Subject: [PATCH] first commit --- shell32.go | 88 +++++++++++++++++++++++++++++++++++++++++++++++ shell32typedef.go | 24 +++++++++++++ win32api.go | 49 ++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 shell32.go create mode 100644 shell32typedef.go create mode 100644 win32api.go diff --git a/shell32.go b/shell32.go new file mode 100644 index 0000000..02bd648 --- /dev/null +++ b/shell32.go @@ -0,0 +1,88 @@ +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 +} +*/ + +func ShellExecuteEx(muzika SHELLEXECUTEINFOW) error { + 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(&muzika)), 0, 0, 0, 0, 0) + if r != 0 { + return errors.New("Error Recured") + } + return nil +} diff --git a/shell32typedef.go b/shell32typedef.go new file mode 100644 index 0000000..e739fbf --- /dev/null +++ b/shell32typedef.go @@ -0,0 +1,24 @@ +package win32api + +type SHELLEXECUTEINFOW struct { + cbSize DWORD + fMask ULONG + hwnd HWND + lpVerb string + lpFile string + lpParameters string + lpDirectory string + nShow int + hInstApp HINSTANCE + lpIDList LPVOID + lpClass string + hkeyClass HKEY + dwHotKey DWORD + union UNION + hProcess HANDLE +} + +type UNION struct { + hIcon HANDLE + hMonitor HANDLE +} diff --git a/win32api.go b/win32api.go new file mode 100644 index 0000000..8dc327d --- /dev/null +++ b/win32api.go @@ -0,0 +1,49 @@ +package win32api + +import "unsafe" + +type ( + ATOM uint16 + BOOL int32 + COLORREF uint32 + DWM_FRAME_COUNT uint64 + DWORD uint32 + HACCEL HANDLE + HANDLE uintptr + HBITMAP HANDLE + HBRUSH HANDLE + HCURSOR HANDLE + HDC HANDLE + HDROP HANDLE + HDWP HANDLE + HENHMETAFILE HANDLE + HFONT HANDLE + HGDIOBJ HANDLE + HGLOBAL HANDLE + HGLRC HANDLE + HHOOK HANDLE + HICON HANDLE + HIMAGELIST HANDLE + HINSTANCE HANDLE + HKEY HANDLE + HKL HANDLE + HMENU HANDLE + HMODULE HANDLE + HMONITOR HANDLE + HPEN HANDLE + HRESULT int32 + HRGN HANDLE + HRSRC HANDLE + HTHUMBNAIL HANDLE + HWND HANDLE + LPARAM uintptr + LPCVOID unsafe.Pointer + LPVOID unsafe.Pointer + LRESULT uintptr + PVOID unsafe.Pointer + QPC_TIME uint64 + ULONG uint32 + ULONG_PTR uintptr + WPARAM uintptr + TRACEHANDLE uintptr +)