Go language lets windows make a sound or play music

Source: Internet
Author: User

The go language allows Windows to make sounds or play music as an example: Alert alert sounds

(This is written by my group member for help, if you need to know the calling principle or process or more of the Go language call Win32API, Dabigatran: 218160862, the answer I told you)

Package Main

Func Main () {

WinSound ()

}

//Golang Let Windows warn the sound todo needs to perfect play MP3 and the like

Func WinSound () {

Funindllfile, err: = Syscall. LoadLibrary ("Winmm.dll")//DLL file called

If err! = Nil {

print ("Cant not call:syscall. LoadLibrary, ErrorInfo: "+ Err. Error ())

}

Defer syscall. FreeLibrary (Funindllfile)

The functions inside the called DLL are:

Funname: = "PlaySound"

//Register a long string of call codes, simplifying to _win32fun variables.

Win32fun, err: = Syscall. GetProcAddress (Syscall. Handle (Funindllfile), funname)

//Through Syscall. SYSCALL6 () to call the Win32 XXX function, because the XXX function has 3 parameters, so need to take Syscall6 to put down. The last 3 parameters, set to 0

                                       _, Err = Syscall. SYSCALL6 (

                                                 UIntPtr (Win32fun),                                                                                //called function name

                                                 3,                                                                                                          //Indicates the number of arguments to the function

UIntPtr (unsafe. Pointer (Syscall. Stringtoutf16ptr ("alert")),//parameter 1 of the function. function names can be searched by MSDN for parameter meanings

                                                // Systemstart

                                                 uintptr (0),                                                                                           //Parameter 2 of the function.                                   

                                                 UIntPtr (0),                                                                                          //Parameter 3 of the function.               

                                                                                                 

                                                 0,                                                      

                                                 0,                                                      

0)

}

Go language lets windows make a sound or play music

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.