Click here to Skip to main content
15,924,318 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to change background color of CRichEditCtrl? Pin
includeh105-May-05 0:03
includeh105-May-05 0:03 
AnswerRe: how to change background color of CRichEditCtrl? Pin
mpallavi5-May-05 1:59
mpallavi5-May-05 1:59 
AnswerRe: how to change background color of CRichEditCtrl? Pin
David Crow5-May-05 2:29
David Crow5-May-05 2:29 
AnswerRe: how to change background color of CRichEditCtrl? Pin
Maximilien5-May-05 3:00
Maximilien5-May-05 3:00 
GeneralRe: how to change background color of CRichEditCtrl? Pin
includeh105-May-05 4:47
includeh105-May-05 4:47 
Questionwhat are differences between std* and GetStdHandle()? Pin
includeh104-May-05 23:58
includeh104-May-05 23:58 
AnswerRe: what are differences between std* and GetStdHandle()? Pin
David Crow5-May-05 2:31
David Crow5-May-05 2:31 
GeneralRe: what are differences between std* and GetStdHandle()? Pin
includeh105-May-05 4:56
includeh105-May-05 4:56 
Hi,
this dos app is an interface between other 2 apps, it is very short, here is all code:
1.if relacing GetStdHandle() with std*, the program is not working.
2. it works on win98, but doesn't work on XP, what is wrong?

//=============================================
int WINAPI Thread_Read(void*pv);
int WINAPI Thread_OutWrite(void*pv);
int WINAPI Thread_ErrWrite(void*pv);

struct BaseHandles
{
HANDLE hInWrite,hOutRead,hErrRead;
};

BOOL CreateProcessMe(char*pszCmdLine,PROCESS_INFORMATION&pi,STARTUPINFO&si)
{
void*psd=0;
LPSECURITY_ATTRIBUTES psa=0;

DWORD bNT=(GetVersion()>=0x80000000)?0:1;
if(bNT)
{
psd=::GlobalAlloc(GPTR,SECURITY_DESCRIPTOR_MIN_LENGTH);
::InitializeSecurityDescriptor(psd,SECURITY_DESCRIPTOR_REVISION);
::SetSecurityDescriptorDacl(psd,-1,0,0);

psa=(LPSECURITY_ATTRIBUTES)::GlobalAlloc(GPTR,sizeof(SECURITY_ATTRIBUTES));
psa->nLength=sizeof(SECURITY_ATTRIBUTES);
psa->lpSecurityDescriptor=psd;
psa->bInheritHandle=1;
}

const BOOL bOK=CreateProcess(0,pszCmdLine,psa,0,1,0,0,0,&si,&pi);

if(psa) ::GlobalFree(psa);
if(psd) ::GlobalFree(psd);
::CloseHandle(pi.hThread);

return bOK;
}

BOOL CreateDupPipe(HANDLE&hRead,HANDLE&hWrite,const BOOL bWrite)
{
SECURITY_ATTRIBUTES saPipe;
saPipe.nLength=sizeof( SECURITY_ATTRIBUTES );
saPipe.lpSecurityDescriptor=0;
saPipe.bInheritHandle=1;

HANDLE hTemp;
BOOL b;

HANDLE hProcess=::GetCurrentProcess();

if(bWrite)
{
b=::CreatePipe(&hRead,&hTemp,&saPipe,0);
::DuplicateHandle(hProcess,hTemp,hProcess,&hWrite,0,0,DUPLICATE_SAME_ACCESS);
}
else
{
b=::CreatePipe(&hTemp,&hWrite,&saPipe,0);
::DuplicateHandle(hProcess,hTemp,hProcess,&hRead,0,0,DUPLICATE_SAME_ACCESS);
}

::CloseHandle(hTemp);
return b;
}

int main(int argc,char* argv[])
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
char szCmd[256];
int i,iLen=0;

if(argc<2) return 1;

szCmd[0]=0;
for(i=1;i<argc;i++)
="" {
="" strcat(szcmd,argv[i]);
="" strcat(szcmd,"="" ");
="" }

="" ------------------------------------------
="" memset(&pi,0,sizeof(pi));
="" memset(&si,0,sizeof(si));

="" si.cb="sizeof(si);
" si.dwflags="STARTF_USESTDHANDLES;

" basehandles="" bh;
="" dword="" dwid;
="" handle="" hthread;

="" createduppipe(si.hstdinput,bh.hinwrite,1);
="" hthread="::CreateThread((LPSECURITY_ATTRIBUTES)0,0,
" (lpthread_start_routine)thread_read,
="" &bh,0,&dwid);


="" createduppipe(bh.houtread,si.hstdoutput,0);
="" (lpthread_start_routine)thread_outwrite,
="" &bh,0,&dwid);

="" createduppipe(bh.herrread,si.hstderror,0);
="" (lpthread_start_routine)thread_errwrite,
="" const="" bool="" bok="CreateProcessMe(szCmd,pi,si);

" if(bok="=0)" return="" 1;

="" waitforsingleobject(pi.hprocess,infinite);
="" closehandle(pi.hprocess);
="" closehandle(pi.hthread);
="" 0;
}=""

int="" winapi="" thread_read(void*pv)
{
="" basehandles*pbh="(BaseHandles*)pv;
" hread="GetStdHandle(STD_INPUT_HANDLE);

" b;
="" dw;
="" char="" sz[1024];

="" while(1)
="" b="::ReadFile(hRead,sz,1023,&dw,0);
" if(b="=0)" break;
="" if(dw<="0)" sz[dw]="0;

" ::writefile(pbh-="">hInWrite,sz,dw,&dw,0);
}
return 1;
}

int WINAPI Thread_OutWrite(void*pv)
{
const BaseHandles*pBh=(BaseHandles*)pv;
const HANDLE hOutWrite=GetStdHandle(STD_OUTPUT_HANDLE);

BOOL b;
DWORD dw;
char sz[1024];

while(1)
{
b=::ReadFile(pBh->hOutRead,sz,1023,&dw,0);
if(b==0) break;
if(dw<=0) break;
sz[dw]=0;

::WriteFile(hOutWrite,sz,dw,&dw,0);
}
return 1;
}

int WINAPI Thread_ErrWrite(void*pv)
{
const BaseHandles*pBh=(BaseHandles*)pv;
const HANDLE hErrWrite=GetStdHandle(STD_ERROR_HANDLE);

BOOL b;
DWORD dw;
char sz[1024];

while(1)
{
b=::ReadFile(pBh->hErrRead,sz,1023,&dw,0);
if(b==0) break;
if(dw<=0) break;
sz[dw]=0;

::WriteFile(hErrWrite,sz,dw,&dw,0);
}
return 1;
}


includeh10
GeneralRe: what are differences between std* and GetStdHandle()? Pin
David Crow5-May-05 6:20
David Crow5-May-05 6:20 
Generalhelp needed Pin
aleks_grid4-May-05 23:23
aleks_grid4-May-05 23:23 
GeneralInternal Complier Error in VC++ 1.52 Pin
LongHornGuy4-May-05 23:23
LongHornGuy4-May-05 23:23 
GeneralRe: Internal Complier Error in VC++ 1.52 Pin
David Crow5-May-05 2:35
David Crow5-May-05 2:35 
General'ICC_STANDARD_CLASSES' : undeclared identifier Pin
stolid_rock4-May-05 22:54
stolid_rock4-May-05 22:54 
GeneralRe: 'ICC_STANDARD_CLASSES' : undeclared identifier Pin
David Crow5-May-05 2:38
David Crow5-May-05 2:38 
GeneralRe: 'ICC_STANDARD_CLASSES' : undeclared identifier Pin
Michael Dunn5-May-05 6:36
sitebuilderMichael Dunn5-May-05 6:36 
Generalconstructor in private section Pin
Rajesh_K_Sharma4-May-05 22:35
Rajesh_K_Sharma4-May-05 22:35 
GeneralRe: constructor in private section Pin
«_Superman_»4-May-05 22:51
professional«_Superman_»4-May-05 22:51 
GeneralRe: constructor in private section Pin
Priyank Bolia4-May-05 23:51
Priyank Bolia4-May-05 23:51 
GeneralRe: constructor in private section Pin
Zdeslav Vojkovic5-May-05 0:51
Zdeslav Vojkovic5-May-05 0:51 
GeneralRe: constructor in private section Pin
Priyank Bolia5-May-05 2:59
Priyank Bolia5-May-05 2:59 
GeneralRe: constructor in private section Pin
Zdeslav Vojkovic6-May-05 2:12
Zdeslav Vojkovic6-May-05 2:12 
GeneralRe: constructor in private section Pin
toxcct5-May-05 0:53
toxcct5-May-05 0:53 
QuestionHow to stop Recording..? Pin
mpallavi4-May-05 22:07
mpallavi4-May-05 22:07 
GeneralMS Word Automation Pin
Imtiaz Murtaza4-May-05 21:32
Imtiaz Murtaza4-May-05 21:32 
QuestionHow to create this button? Pin
exploreman4-May-05 21:30
exploreman4-May-05 21:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.