我正在尝试写一个在Windows上模拟击键的Haskell程序。我尝试调用keybd_event和SendInput,但都没有编译。不过,我可以用解释器运行这个程序。当我尝试构建一个绑定到winable.h中的SendInput的程序时,我得到了错误:
cabal install
...
[1 of 2] Compiling WindowsKeys ( dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.hs, dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.o )
[2 of 2] Compiling Main ( src\Main.hs, dist\build\WindowsKeys\WindowsKeys-tmp\Main.o )
Linking dist\build\WindowsKeys\WindowsKeys.exe ...
dist\build\WindowsKeys\WindowsKeys-tmp\WindowsKeys.o:fake:(.text+0x35d): undefined reference to `SendInput'
collect2: ld returned 1 exit status
cabal: Error: some packages failed to install:
WindowsKeys-0.1.0.0 failed during the building phase. The exception was:
ExitFailure 1详细错误在http://pastebin.com/trg21N0x,但它似乎不包含任何更多线索。当我尝试使用keybd_event时,我得到了一个类似的错误。我编写的hsc文件包含以下标头:
#include "windows.h"
#include "winuser.h"
#include "winable.h"下面是C语言的绑定:
foreign import ccall unsafe "winable.h SendInput"
c_SendInput :: UINT
-> Ptr Input
-> CInt
-> IO UINT我假设我不能在winuser.h上调用SendInput,因为#if:
#if (_WIN32_WINNT >= 0x0403)
WINUSERAPI UINT WINAPI SendInput(UINT,LPINPUT,int);当我为_WIN32_WINNT添加绑定时,值是0x400。
我有2012.4.0.0版本的Haskell平台。它附带了一个包含我所包含的标题的文件夹。在我的计算机上找不到任何具有相同名称的其他标头。我使用的是Windows 7专业版6.1。
谢谢!
下面是WindowsKeys.cabal:
-- Initial WindowsKeys.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: WindowsKeys
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8
extra-source-files: windows.h, winuser.h, winable.h
executable WindowsKeys
main-is: Main.hs
other-modules: WindowsKeys
build-depends: base ==4.5.*, Win32 ==2.2.*
hs-source-dirs: src
build-tools: hsc2hs
extra-libraries: user32
include-dirs: src当我注释掉键盘函数的绑定时,构建就成功了。
发布于 2013-11-07 11:07:26
我最终发现我使用了错误的调用约定。keybd_event和SendInput都需要使用stdcall而不是ccall来调用。
https://stackoverflow.com/questions/19578565
复制相似问题