main_windows.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //go:build windows
  2. package yu_sys
  3. import (
  4. yu_math "gogs.qqck.cn/s/tools/math"
  5. _ "syscall"
  6. _ "unsafe"
  7. )
  8. //go:linkname SyscallN syscall.SyscallN
  9. func SyscallN(addr Address, args ...uintptr) (r1, r2, err uintptr)
  10. func (t Address) CallGbkToUtf8(args ...any) string {
  11. j_str, _, _ := t.Call(args...)
  12. if j_str == 0 {
  13. return ""
  14. }
  15. j_unicode_len, _, _ := MultiByteToWideChar.Call(936, 0, j_str, uint(yu_math.MaxUint), 0, 0)
  16. if j_unicode_len < 1 {
  17. return ""
  18. }
  19. j_unicode_len *= 2
  20. j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
  21. MultiByteToWideChar.Call(936, 0, j_str, uint(yu_math.MaxUint), j_unicode, j_unicode_len)
  22. j_utf8_size, _, _ := WideCharToMultiByte.Call(65001, 0, j_unicode, uint(yu_math.MaxUint), 0, 0, 0, 0)
  23. j_utf8_size -= 1
  24. if j_utf8_size < 1 {
  25. return ""
  26. }
  27. j_utf8 := make([]byte, j_utf8_size)
  28. WideCharToMultiByte.Call(65001, 0, j_unicode, uint(yu_math.MaxUint), j_utf8, j_utf8_size, 0, 0)
  29. return string(j_utf8)
  30. }
  31. func (t Address) CallUnicodeToUtf8(args ...any) string {
  32. j_ptr, _, _ := t.Call(args...)
  33. if j_ptr == 0 {
  34. return ""
  35. }
  36. j_utf8_size, _, _ := WideCharToMultiByte.Call(65001, 0, j_ptr, uint(yu_math.MaxUint), 0, 0, 0, 0)
  37. j_utf8_size -= 1
  38. if j_utf8_size < 1 {
  39. return ""
  40. }
  41. j_utf8 := make([]byte, j_utf8_size)
  42. WideCharToMultiByte.Call(65001, 0, j_ptr, uint(yu_math.MaxUint), j_utf8, j_utf8_size, 0, 0)
  43. return string(j_utf8)
  44. }
  45. func LoadLibrary(path string) Module {
  46. return Module(LoadLibraryW.CallUintptr(S{Unicode, path}))
  47. }
  48. func (t Module) GetProcAddress(name string) Address {
  49. return Address(GetProcAddress.CallUintptr(uintptr(t), name+"\x00"))
  50. }