小弟创建了一个win32 console application 应用程序出现错误windows.h也加了就是找不到错误求解啊_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3234 | 回复: 0   主题: 小弟创建了一个win32 console application 应用程序出现错误windows.h也加了就是找不到错误求解啊        下一篇 
    本主题由 Administrator 于 2014-10-17 23:31:17 移动
dream0110
注册用户
等级:中士
经验:242
发帖:87
精华:0
注册:2012-2-15
状态:离线
发送短消息息给dream0110 加好友    发送短消息息给dream0110 发消息
发表于: IP:您无权察看 2014-10-17 10:52:20 | [全部帖] [楼主帖] 楼主

小弟创建了一个win32 console application 应用程序出现错误windows.h也加了就是找不到错误求解啊 [问题点数:40分,无满意结帖,结帖人bai_wen_ping] 

    不显示删除回复 显示所有回复 显示星级回复 显示得分回复 只显示楼主 

    程序源码:

#include <stdio.h>
#include <windows.h>
#include <string.h>
#define SUCCESS 1
#define FAILURE -1
int Display_all_proc();/*显示系统当前所有进程*/
int Create_proc();/*创建进程*/
int Kill_proc();/*终止一个进程*/
int main()
{
      int n=0;
      while(n!=4)
      {
            printf("1 查看进程\n");
            printf("2 创建进程\n");
            printf("3 终止进程\n");
            printf("4 结束\n");
            printf("请选择:");
            scanf(" %d",&n);
            switch(n)
            {
                  case 1:
                  Display_all_proc();
                  break;
                  case 2:
                  Create_proc();
                  break;
                  case 3:
                  Kill_proc();
                  break;
                  case 4:
                  break;
                  default:
                  printf("输入有误!\n");
                  break;
            }
      }
      return 0;
}
int Display_allproc()
{
PROCESSENTRY32 pe32;/*用来存储进程信息的结构体*/
HANDLE hProcessSnap= CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
BOOL bProc;
pe32.dwSize=sizeof(pe32);/*设置成员的大小*/
/*获取进程快照(当前系统所有进程),调用成功,返回快照的句柄,调用失败,返回INVALID_HANDLE_VALUE*/
if( hProcessSnap==INVALID_HANDLE_VALUE)/*调用失败*/
{
      printf("调用失败\n");
      return FAILURE;
}
bProc= Process32First(hProcessSnap,&pe32);/*获取快照中第一个进程*/
while(bProc)/*如果进程快照中有进程*/
{
      printf("%5d %s\n",pe32.th32ProcessID,pe32.szExeFile);//输出进程ID和进程名
      bProc=Process32Next(hProcessSnap,&pe32);/*获取下一个进程*/
}
CloseHandle(hProcessSnap);/*关闭进程快照*/
return SUCCESS;
}
int Creatproc()
{
char str[256]={0};
      PROCESS_INFORMATION pi;/*该结构返回有关新进程及其主线程的信息*/
      BOOL bret
      printf("请输入可执行文件路径(*.exe):\n");
      scanf(" %s",str);
      /*STARTUPINFO结构用于指定新进程的主窗口特性,

    **当Windows创建新进程时,它将使用该结构的有关成员至少应该将该结构中的所有成员初始化为零,然后将cb成员设置为该结构的大小

    */
STARTUPINFO si={0};/*指定新进程各个字段均为null*/
      si.cb=sizeof(STARTUPINFO);/*STARTUPINFO结构中的字节数*/
      si.dwFlags=STARTF_USESHOWWINDOW;/*使用wShowWindow 成员*/
      si.wShowWindow=SW_SHOW;
      /*CreateProcess用来创建一个新的进程和它的主线程,这个新进程运行指定的可执行文件*/
      bret=CreateProcess(
      NULL,/*这个字符串可以是可执行模块的绝对路径,也可以是相对路径,在后一种情况下,函数使用当前驱动器和目录建立可执行模块的路径。

    这个参数可以被设为NULL,在这种情况下,可执行模块的名字必须处于 lpCommandLine 参数最前面并由空格符与后面的字符分开*/
      str,
      NULL,/*指向一个SECURITY_ATTRIBUTES结构体,这个结构体决定是否返回的句柄可以被子进程继承,如果lpProcessAttributes参数为空,那么句柄不能被继承*/
      NULL,/*同lpProcessAttribute,不过这个参数决定的是线程是否被继承,通常置为NULL*/
      FALSE,/*指定当前进程内的句柄不可以被子进程继承 */
      0,
      NULL,/*指向一个新进程的环境块。如果此参数为空,新进程使用调用进程的环境*/
      NULL, /*这个字符串用来指定子进程的工作路径,字符串必须是一个包含驱动器名的绝对路径,如果这个参数为空,新进程将使用与调用进程相同的驱动器和目录*/
      &si,/*指向一个用于决定新进程的主窗体如何显示的STARTUPINFO结构体*/
      &pi);/*指向一个用来接收新进程的识别信息的PROCESS_INFORMATION结构体*/
      if (!bret)
      {
            printf("创建失败\n");
            return FAILURE;
      }
      else
      {
            printf("创建成功\n");
            printf("进程号:%d\n",pi.dwProcessId);
      }
      return SUCCESS;
}
int Kill_proc()
{
DWORD ProcessID;
HANDLE hProcess=OpenProcess(PROCESS_TERMINATE,FALSE,ProcessID);//打开对应进程句柄
printf("请输入想要终止的进程ID\n");
scanf(" %d",&ProcessID);
if (hProcess==NULL)
{
      printf("失败\n");
      return FAILURE;
}
if (!TerminateProcess(hProcess,0))//关闭进程
printf("关闭失败\n");
else
printf("关闭成功\n");
CloseHandle(hProcess);
return SUCCESS;
}


 报错如下:

    H:\操作系统\cp\mian.c(51) : error C2065: 'PROCESSENTRY32' : undeclared identifier

    H:\操作系统\cp\mian.c(51) : error C2146: syntax error : missing ';' before identifier 'pe32'

    H:\操作系统\cp\mian.c(51) : error C2065: 'pe32' : undeclared identifier

    H:\操作系统\cp\mian.c(53) : error C2275: 'HANDLE' : illegal use of this type as an expression

h:\vc98\include\winnt.h(207) : see declaration of 'HANDLE'


 H:\操作系统\cp\mian.c(53) : error C2146: syntax error : missing ';' before identifier 'hProcessSnap'

    H:\操作系统\cp\mian.c(53) : error C2065: 'hProcessSnap' : undeclared identifier

    H:\操作系统\cp\mian.c(53) : warning C4013: 'CreateToolhelp32Snapshot' undefined; assuming extern returning int

    H:\操作系统\cp\mian.c(53) : error C2065: 'TH32CS_SNAPPROCESS' : undeclared identifier

    H:\操作系统\cp\mian.c(54) : error C2275: 'BOOL' : illegal use of this type as an expression

h:\vc98\include\windef.h(142) : see declaration of 'BOOL'


 H:\操作系统\cp\mian.c(54) : error C2146: syntax error : missing ';' before identifier 'bProc'

    H:\操作系统\cp\mian.c(54) : error C2065: 'bProc' : undeclared identifier

    H:\操作系统\cp\mian.c(55) : error C2224: left of '.dwSize' must have struct/union type

    H:\操作系统\cp\mian.c(57) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *'

    H:\操作系统\cp\mian.c(62) : warning C4013: 'Process32First' undefined; assuming extern returning int

    H:\操作系统\cp\mian.c(65) : error C2224: left of '.th32ProcessID' must have struct/union type

    H:\操作系统\cp\mian.c(65) : error C2224: left of '.szExeFile' must have struct/union type

    H:\操作系统\cp\mian.c(66) : warning C4013: 'Process32Next' undefined; assuming extern returning int

    H:\操作系统\cp\mian.c(68) : warning C4022: 'CloseHandle' : pointer mismatch for actual parameter 1

    H:\操作系统\cp\mian.c(76) : error C2146: syntax error : missing ';' before identifier 'printf'

    H:\操作系统\cp\mian.c(81) : error C2275: 'STARTUPINFO' : illegal use of this type as an expression

h:\vc98\include\winbase.h(3818) : see declaration of 'STARTUPINFO'


 H:\操作系统\cp\mian.c(81) : error C2146: syntax error : missing ';' before identifier 'si'

    H:\操作系统\cp\mian.c(81) : error C2065: 'si' : undeclared identifier

    H:\操作系统\cp\mian.c(81) : error C2059: syntax error : '{'

    H:\操作系统\cp\mian.c(82) : error C2224: left of '.cb' must have struct/union type

    H:\操作系统\cp\mian.c(83) : error C2224: left of '.dwFlags' must have struct/union type

    H:\操作系统\cp\mian.c(84) : error C2224: left of '.wShowWindow' must have struct/union type

    H:\操作系统\cp\mian.c(97) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct _STARTUPINFOA *' 

    系统上传图片提示写文件失败,可以读取查看图片。请高手帮忙分析原因。 

    现在如果想自考计算机及应用专业,先学哪些科目比较好? 

    我写了一个简单的APP,用到了数据库,在程序中我自动建立了一个数据库,可以在File Explorer中找到,然后我把软件安装到虚拟机可以运行。 

    有关JSP取struts2内容的问题 

    技术讨论:MQ的应用与产生背景 

    基于extjs的web desktop应用框架 

    求助 路过的大神给个思路 

    用CreateFile()打开usb设备时,如何填写devicepath这个值? 

PROCESSENTRY32
Describes an entry from a list that enumerates the processes residing in the system address space when a snapshot was taken.
typedef struct tagPROCESSENTRY32 {
      DWORD dwSize;
      DWORD cntUsage;
      DWORD th32ProcessID;
      DWORD th32DefaultHeapID;
      DWORD th32ModuleID;
      DWORD cntThreads;
      DWORD th32ParentProcessID;
      LONG pcPriClassBase;
      DWORD dwFlags;
      char szExeFile[MAX_PATH];
} PROCESSENTRY32;
typedef PROCESSENTRY32 * PPROCESSENTRY32;
typedef PROCESSENTRY32 * LPPROCESSENTRY32;
Members
dwSize
Specifies the length, in bytes, of the structure. Before calling the Process32First function, set this member to sizeof(PROCESSENTRY32). If you do not initialize dwSize, Process32First will fail.
cntUsage
Number of references to the process. A process exists as long as its usage count is nonzero. As soon as its usage count becomes zero, a process terminates.
th32ProcessID
Identifier of the process. The contents of this member can be used by Win32 API elements.
th32DefaultHeapID
Identifier of the default heap for the process. The contents of this member has meaning only to the tool help functions. It is not a handle, nor is it usable by Win32 API elements.
th32ModuleID
Module identifier of the process. The contents of this member has meaning only to the tool help functions. It is not a handle, nor is it usable by Win32 API elements.
cntThreads
Number of execution threads started by the process.
th32ParentProcessID
Identifier of the process that created the process being examined. The contents of this member can be used by Win32 API elements.
pcPriClassBase
Base priority of any threads created by this process.
dwFlags
Reserved; do not use.
szExeFile
Path and filename of the executable file for the process.
QuickInfo
Windows NT: Requires version 5.0 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in
tlhelp32.h.
See Also
Tool Help Library Overview, Tool Help Structures


--转自 北京联动北方科技有限公司


该贴由system转至本版2014-10-17 23:31:17



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论