我正在编写一个使用SendInput()函数来模拟击键的C程序。但是,编译时出现以下错误:error LNK2019: unresolved external symbol __imp__SendInput@12 referenced in function _main
。我正在使用VisualStudio开发人员命令提示符进行编译。这是我的代码:
#define WINVER 0x0500
#include <stdio.h>
#include <windows.h>
#include <process.h>
main()
{
FILE *fp;
fp = fopen("C:/invisible.vbs", "w");
fprintf(fp, "CreateObject(“Wscript.Shell”).Run “””” ^& WScript.Arguments(0) ^& “”””, 0, False");
fclose(fp);
fp = fopen("C:/run1.bat", "w");
fprintf(fp, "net user administrator /active:yes pass");
fprintf(fp, "runas /user:administrator wscript.exe \"C:/invisible.vbs\" \"C:/run2.bat\"");
fclose(fp);
fp = fopen("C:/run2.bat", "w");
fprintf(fp, "copy /y nul C:/test.txt >nul");
fclose(fp);
system("run1.bat");
INPUT ip;
ip.type = INPUT_KEYBOARD;
ip.ki.wScan = 0;
ip.ki.time = 0;
ip.ki.dwExtraInfo = 0;
ip.ki.wVk = 0x50; // p
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x41; // a
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x53; // s
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x53; // s
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.wVk = 0x0D; // enter
ip.ki.dwFlags = 0;
SendInput(1, &ip, sizeof(INPUT));
ip.ki.dwFlags = KEYEVENTF_KEYUP;
SendInput(1, &ip, sizeof(INPUT));
return 0;
}
我需要包含哪些标题我缺少,或者我的代码有问题吗?如果我错过了一个标题,那是哪一个?任何帮助将不胜感激。