duanci3845 2014-09-16 03:44
浏览 348
已采纳

遇到syscall.Syscall和WinAPI的麻烦

I'm trying to use VkKeyScan from the Window's API, however the program crashes whenever that function is called. I've had no problems with other Window's API functions I've imported and used in this way. Is there something wrong with my syscall.Syscall call?

var (
    user32, _ = syscall.LoadLibrary("user32.dll")
    vkKeyScan, _ = syscall.GetProcAddress(user32, "VkKeyScan")
)

func VkKeyScan(char byte) (int16, syscall.Errno) {
    var nargs uintptr = 1
    ret, _, callErr := syscall.Syscall(uintptr(vkKeyScan), nargs, uintptr(char), 0, 0)
    return int16(ret), callErr
}
  • 写回答

1条回答 默认 最新

  • doumeng1143 2014-09-16 04:15
    关注

    VkScanKey works in C because it’s #defined roughly like this:

    #ifdef UNICODE
    #   define VkScanKey VkScanKeyW
    #else
    #   define VkScanKey VkScanKeyA
    #endif
    

    So VkScanKey isn’t the real symbol—VkScanKeyW is, and that’s the only form GetProcAddress will take it in. If you had been doing proper error handling you might have noticed that GetProcAddress was failing rather than Syscall, which might have tipped you off to this fact.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置