HOW To Write Windows API in GOLANG

1,119 views
Skip to first unread message

kumargv

unread,
Sep 2, 2016, 8:12:19 AM9/2/16
to golang-nuts
Hello friends,

i am trying to write some win api in golang ,because  these API not implemented any PKG.
"syscall"
"github.com/contester/runlib/win32"
"golang.org/x/sys/windows"

API are code in C++

OpenDesktop
	hdesk = OpenDesktop(
		_T("default"),     // the interactive window station 
		0,             // no interaction with other desktop processes
		FALSE,         // handle is not inheritable
		READ_CONTROL | // request the rights to read and write the DACL
		WRITE_DAC | 
		DESKTOP_WRITEOBJECTS | 
		DESKTOP_READOBJECTS);


OpenWindowStation

	hwinsta = OpenWindowStation(
		_T("winsta0"),                   // the interactive window station 
		FALSE,                       // handle is not inheritable
		READ_CONTROL | WRITE_DAC);
is my implemention correct or i did some mistake.

Now my implemented code in GOLANG
func OpenWindowStation() (win32.Hwinsta, error) {

    winst, _ := syscall.UTF16FromString("winsta0")
    //    r1, _, e1 := syscall.Syscall(procOpenWindowStation.Addr(), uintptr(unsafe.Pointer(&winst[0])), uintptr(0), uintptr(READ_CONTROL), uintptr(WRITE_DAC))
    r1, _, e1 := procOpenWindowStation.Call(
        uintptr(unsafe.Pointer(&winst[0])),
        uintptr(0),
        uintptr(READ_CONTROL),
        uintptr(WRITE_DAC))

    if int(r1) == 0 {
        return win32.Hwinsta(r1), os.NewSyscallError("OpenWindowStation", e1)
    }
    return win32.Hwinsta(r1), nil
}
func OpenDesktop(lpszDesktop *uint16, dwFlags uint32, fInherit uint32) (win32.Hdesk, error) {

    r1, _, e1 := procOpenDesktop.Call(
        uintptr(unsafe.Pointer(lpszDesktop)),
        uintptr(dwFlags),
        uintptr(READ_CONTROL),
        uintptr(WRITE_DAC),
        uintptr(DESKTOP_WRITEOBJECTS),
        uintptr(DESKTOP_READOBJECTS),
        uintptr(fInherit))

    if int(r1) == 0 {
        return win32.Hdesk(r1), os.NewSyscallError("OpenWindowStation", e1)
    }
    return win32.Hdesk(r1), nil
}

My another question is when to use which function listed below like (syscal.syscall,logonProc.Addr(),logonProc.call())
But i am not able to understand some time 
>>>>>>>syscall.Syscall6(logonProc.Addr(), 6, uintptr(unsafe.Pointer(&pu[0])),
        uintptr(unsafe.Pointer(&domain[0])),
        uintptr(unsafe.Pointer(&pp[0])),
        LOGON32_LOGON_NETWORK,
        LOGON32_PROVIDER_DEFAULT,
        uintptr(unsafe.Pointer(&token)))

>>>>>>>>logonProc.Call()
>>>>>>>>syscall.Syscall()
>>>>>>>>syscall.Syscall9()


Please suggest from where do i get this info.
Thanks

mura

unread,
Sep 2, 2016, 10:39:38 AM9/2/16
to golang-nuts
I don't know the answer but if I were you, I would start from looking at Windows applications written in Go and see how they have done.
For instance, the package https://github.com/lxn/walk has implemented lots of Windows GUI stuff. It would probably provide the information you are looking for.
Reply all
Reply to author
Forward
0 new messages