我正在尝试修复一段C++代码,这段代码是我在上课程时遇到的。
我正在使用下面的命令在Debian上编译churrasco.cpp文件...
i686-w64-mingw32-gcc Churrasco.cpp -lws2_32 -o churrasco.exe我最初遇到这个错误,是因为编译器建议我更改一个函数...
root@kali:~/Churrasco# i686-w64-mingw32-gcc Churrasco.cpp -lws2_32 -o churrasco.exe
Churrasco.cpp: In function ‘DWORD RunCommandAsSystem(HANDLE, LPSTR)’:
Churrasco.cpp:125:22: warning: ISO C++ forbids converting a string constant to ‘LPSTR’ {aka ‘char*’} [-Wwrite-strings]
sInfo.lpDesktop= "WinSta0\\Default";
^~~~~~~~~~~~~~~~~~
Churrasco.cpp:147:112: warning: passing NULL to non-pointer argument 7 of ‘WINBOOL CreateProcessAsUserA(HANDLE, LPCSTR, LPSTR, LPSECURITY_ATTRIBUTES, LPSECURITY_ATTRIBUTES, WINBOOL, DWORD, LPVOID, LPCSTR, LPSTARTUPINFOA, LPPROCESS_INFORMATION)’ [-Wconversion-null]
dwRes=CreateProcessAsUser(hToken2, lpComspec, lpCommandTmp, NULL, NULL, TRUE, NULL, NULL, NULL, &sInfo, &pInfo);
^
Churrasco.cpp: In function ‘void* GetSystemToken(HANDLE, DWORD)’:
Churrasco.cpp:226:50: warning: passing NULL to non-pointer argument 2 of ‘void* OpenProcess(DWORD, WINBOOL, DWORD)’ [-Wconversion-null]
hProcess=OpenProcess(PROCESS_DUP_HANDLE,NULL,Pid);
^
Churrasco.cpp: In function ‘int main(int, _TCHAR**)’:
Churrasco.cpp:332:31: error: ‘GetProcessIdOfThread’ was not declared in this scope
if (hThread && dwRpcssPid==GetProcessIdOfThread(hThread)) {
^~~~~~~~~~~~~~~~~~~~
Churrasco.cpp:332:31: note: suggested alternative: ‘GetProcessIoCounters’ // This was the suggested change
if (hThread && dwRpcssPid==GetProcessIdOfThread(hThread)) {
^~~~~~~~~~~~~~~~~~~~
GetProcessIoCounters我这样做了,代码段现在看起来是这样的……
if (hThread && dwRpcssPid==GetProcessIoCounters(hThread)) {
printf ("/churrasco/-->Found Thread: %d \n",Tid);我现在遇到的问题是,我有下面的错误,而我对C++的了解还不够多,无法快速修复它。
Churrasco.cpp: In function ‘int main(int, _TCHAR**)’:
Churrasco.cpp:332:59: error: too few arguments to function ‘WINBOOL GetProcessIoCounters(HANDLE, PIO_COUNTERS)’
if (hThread && dwRpcssPid==GetProcessIoCounters(hThread)) {
^
In file included from /usr/share/mingw-w64/include/windows.h:70,
from /usr/share/mingw-w64/include/winsock2.h:23,
from stdafx.h:10,
from Churrasco.cpp:18:
/usr/share/mingw-w64/include/winbase.h:1153:29: note: declared here所以我的问题是,为了解决这个错误,我需要放置哪些参数,或者需要对新函数进行哪些更改?
编辑:
我添加了对...的引用
#include "stdafx.h"
#include "Processthreadsapi.h"但仍然有以下错误:
Churrasco.cpp: In function ‘void* GetSystemToken(HANDLE, DWORD)’:
Churrasco.cpp:227:50: warning: passing NULL to non-pointer argument 2 of ‘void* OpenProcess(DWORD, WINBOOL, DWORD)’ [-Wconversion-null]
hProcess=OpenProcess(PROCESS_DUP_HANDLE,NULL,Pid);
^
Churrasco.cpp: In function ‘int main(int, _TCHAR**)’:
Churrasco.cpp:333:31: error: ‘GetProcessIdOfThread’ was not declared in this scope
if (hThread && dwRpcssPid==GetProcessIdOfThread(hThread)) {
^~~~~~~~~~~~~~~~~~~~
Churrasco.cpp:333:31: note: suggested alternative: ‘GetProcessIoCounters’
if (hThread && dwRpcssPid==GetProcessIdOfThread(hThread)) {
^~~~~~~~~~~~~~~~~~~~
GetProcessIoCounters
(base) root@kali:~/Churrasco# 工作文件夹:
(base) root@kali:~/Churrasco# ls
32892.txt Churrasco.ncb Churrasco.suo Iphlpapi.h Processthreadsapi.h stdafx.cpp
Churrasco.cpp Churrasco.sln Churrasco.vcproj Ntsecapi.h ReadMe.txt stdafx.h发布于 2019-09-18 07:16:54
编译器提供的建议替代方案是它对您想要的标识符的最佳猜测,假设您输入的是拼写错误(拼写错误)。但是,在您的示例中,标识符是正确的,但是没有包含正确的头。您不希望更改正在调用的函数的名称。
GetProcessIdOfThread是在processthreadsapi.h标头中定义的,因此您需要添加
#include <processthreadsapi.h>添加到源文件中。
https://stackoverflow.com/questions/57982973
复制相似问题