小弟我在View文件中定义了HANDLE的变量,可是在App文件中引用的时候说该变量没有定义
我在View文件中定义了HANDLE的变量,可是在App文件中引用的时候说该变量没有定义
我在View文件中定义了HANDLE的变量,
private:
HANDLE hRead;
HANDLE hWrite;
可是在MainFrame类的cpp文件中引用的时候说该变量没有定义
void CMainFrame::OnPipeCreate()
{
// TODO: Add your command handler code here
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle=TRUE;
sa.lpSecurityDescriptor=NULL;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
if (!CreatePipe(&hRead,&hWrite,&sa,0)) //121行
{
MessageBox("创建匿名管道失败!");
return;
}
STARTUPINFO sui;
PROCESS_INFORMATION pi;
ZeroMemory(&sui,sizeof(STARTUPINFO));
sui.cb=sizeof(STARTUPINFO);
sui.dwFlags=STARTF_USESTDHANDLES;
sui.hStdInput=hRead; //131
sui.hStdOutput=hWrite; //132
sui.hStdError=GetStdHandle(STD_ERROR_HANDLE);
if (!CreateProcess("..\\Child\\Debug\\Child.exe",NULL,NULL,NULL,TRUE,0,NULL,NULL,&sui,&pi))
{
CloseHandle(hWrite);
CloseHandle(hRead);
hRead=NULL;
hWrite=NULL;
MessageBox("创建子进程失败!");
return;
}
else
{
CloseHandle(hWrite);
CloseHandle(hRead);
}
}
编译的结果为:
MainFrm.cpp
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(121) : error C2065: 'hRead' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(121) : error C2065: 'hWrite' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(131) : error C2440: '=' : cannot convert from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(132) : error C2440: '=' : cannot convert from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
------解决方案--------------------
晕。你在view中定义,mainframe中当然找不到了。这奇怪吗?
------解决方案--------------------
你为什么不定义在mainframe中呢?
------解决方案--------------------
那你是需要先看看最最最基础的编程书才能明白了。
我在View文件中定义了HANDLE的变量,
private:
HANDLE hRead;
HANDLE hWrite;
可是在MainFrame类的cpp文件中引用的时候说该变量没有定义
void CMainFrame::OnPipeCreate()
{
// TODO: Add your command handler code here
SECURITY_ATTRIBUTES sa;
sa.bInheritHandle=TRUE;
sa.lpSecurityDescriptor=NULL;
sa.nLength=sizeof(SECURITY_ATTRIBUTES);
if (!CreatePipe(&hRead,&hWrite,&sa,0)) //121行
{
MessageBox("创建匿名管道失败!");
return;
}
STARTUPINFO sui;
PROCESS_INFORMATION pi;
ZeroMemory(&sui,sizeof(STARTUPINFO));
sui.cb=sizeof(STARTUPINFO);
sui.dwFlags=STARTF_USESTDHANDLES;
sui.hStdInput=hRead; //131
sui.hStdOutput=hWrite; //132
sui.hStdError=GetStdHandle(STD_ERROR_HANDLE);
if (!CreateProcess("..\\Child\\Debug\\Child.exe",NULL,NULL,NULL,TRUE,0,NULL,NULL,&sui,&pi))
{
CloseHandle(hWrite);
CloseHandle(hRead);
hRead=NULL;
hWrite=NULL;
MessageBox("创建子进程失败!");
return;
}
else
{
CloseHandle(hWrite);
CloseHandle(hRead);
}
}
编译的结果为:
MainFrm.cpp
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(121) : error C2065: 'hRead' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(121) : error C2065: 'hWrite' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(131) : error C2440: '=' : cannot convert from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
D:\Program Files\Microsoft Visual Studio\Program\Parent\MainFrm.cpp(132) : error C2440: '=' : cannot convert from 'int' to 'void *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
------解决方案--------------------
晕。你在view中定义,mainframe中当然找不到了。这奇怪吗?
------解决方案--------------------
你为什么不定义在mainframe中呢?
------解决方案--------------------
那你是需要先看看最最最基础的编程书才能明白了。