救命吖!关于createfile函数,老师出错,GetLastError返回值是998,请大侠们赐教吖!!!
这里是代码,我主要是想测试标准输入输出重定向而已,问题就在于这里“HANDLEhFile=CreateFile(str1,GENERIC_WRITE,0,&sa,OPEN...
这里是代码,我主要是想测试标准输入输出重定向而已,问题就在于这里“HANDLE hFile=CreateFile(str1,GENERIC_WRITE,0,&sa,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
int i;
if(hFile==INVALID_HANDLE_VALUE)
{
i=GetLastError();
printf("Createfle has Error.\nError code is:%d",i);
return 0;
}
”createfile老是返回-1
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=TRUE;
STARTUPINFO si={0};
si.cb=sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.cb=sizeof(STARTUPINFO);
char *str="123.exe";
char str1[10];
ZeroMemory(str1,10);
strcpy(str1,"123.txt");
HANDLE hFile=CreateFile(str1,GENERIC_WRITE,0,&sa,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
int i;
if(hFile==INVALID_HANDLE_VALUE)
{
i=GetLastError();
printf("Createfle has Error.\nError code is:%d",i);
return 0;
}
si.dwFlags=STARTF_USESTDHANDLES;
si.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
si.hStdError=hFile;
si.hStdOutput=hFile;
PROCESS_INFORMATION pi;
for (i=0;i<10;i++)
{
BOOL bl=CreateProcess(str,NULL,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi);
int m=GetLastError();
CloseHandle(pi.hProcess);
}
CloseHandle(hFile);
getchar();
getchar();
return 0;
} 展开
int i;
if(hFile==INVALID_HANDLE_VALUE)
{
i=GetLastError();
printf("Createfle has Error.\nError code is:%d",i);
return 0;
}
”createfile老是返回-1
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
SECURITY_ATTRIBUTES sa;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle=TRUE;
STARTUPINFO si={0};
si.cb=sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.cb=sizeof(STARTUPINFO);
char *str="123.exe";
char str1[10];
ZeroMemory(str1,10);
strcpy(str1,"123.txt");
HANDLE hFile=CreateFile(str1,GENERIC_WRITE,0,&sa,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
int i;
if(hFile==INVALID_HANDLE_VALUE)
{
i=GetLastError();
printf("Createfle has Error.\nError code is:%d",i);
return 0;
}
si.dwFlags=STARTF_USESTDHANDLES;
si.hStdInput=GetStdHandle(STD_INPUT_HANDLE);
si.hStdError=hFile;
si.hStdOutput=hFile;
PROCESS_INFORMATION pi;
for (i=0;i<10;i++)
{
BOOL bl=CreateProcess(str,NULL,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi);
int m=GetLastError();
CloseHandle(pi.hProcess);
}
CloseHandle(hFile);
getchar();
getchar();
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询