v2 / vlib / os / open_uri_windows.c.v
23 lines · 20 sloc · 770 bytes · 619714008547b5d86b4e1fa5f6d4314cb87edef1
Raw
1module os
2
3import dl
4
5type ShellExecuteWin = fn (voidptr, &u16, &u16, &u16, &u16, int)
6
7// open_uri opens a given uri.
8pub fn open_uri(uri string) ! {
9 mut vopen_uri_cmd := getenv('VOPEN_URI_CMD')
10 if vopen_uri_cmd != '' {
11 result := execute('${vopen_uri_cmd} "${uri}"')
12 if result.exit_code != 0 {
13 return error('unable to open url: ${result.output}')
14 }
15 return
16 }
17 handle := dl.open_opt('shell32', dl.rtld_now)!
18 // https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
19 func := ShellExecuteWin(dl.sym_opt(handle, 'ShellExecuteW')!)
20 // 1 is SW_SHOWNORMAL, but it avoids including winuser.h, and in turn windows.h, which conflicts with raylib
21 func(C.NULL, 'open'.to_wide(), uri.to_wide(), C.NULL, C.NULL, 1)
22 dl.close(handle)
23}
24