Click here to Skip to main content
15,898,373 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:07
SandipG 25-Feb-09 1:07 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 1:12
coding_ram25-Feb-09 1:12 
GeneralRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:16
SandipG 25-Feb-09 1:16 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 1:20
coding_ram25-Feb-09 1:20 
GeneralRe: Reg: Dialogue size change Pin
SandipG 25-Feb-09 1:21
SandipG 25-Feb-09 1:21 
AnswerRe: Reg: Dialogue size change Pin
David Crow25-Feb-09 3:20
David Crow25-Feb-09 3:20 
GeneralRe: Reg: Dialogue size change Pin
coding_ram25-Feb-09 18:14
coding_ram25-Feb-09 18:14 
QuestionWhy am I not able to get handle of file? Pin
SherTeks25-Feb-09 0:53
SherTeks25-Feb-09 0:53 
Hello,

I've a code snippet. Please follow the comments.

//Create a directory if it doesn't exist
if ( !PathFileExists("C:\\TestDir") )
{
CreateDirectory("C:\\TestDir", NULL);
}

//Create a batch file in the directory
CFile cfBatchFile( "C:\\TestDir\\TestBatch.bat", CFile::modeCreate| CFile::modeRead | CFile::modeWrite );

//Write 'C:\\windows\\system32\cmd.exe" ipconfig>C:\\TestDir\\Test.txt in the batch file
cfBatchFile.Write( "\"C:\\windows\\system32\cmd.exe\" ipconfig>C:\\TestDir\\Test.txt", MAX_PATH );

cfBatchFile.Close();

//ShellExecute runs "C:\\TestDir\\TestBatch.bat" and generates output for 'ipconfig' and redirects it to text file "C:\\TestDir\\Test.txt"
if ( ShellExecute(NULL, "open", "C:\\TestDir\\TestBatch.bat", NULL, NULL, SW_HIDE) > (HINSTANCE)32)
{
    CFile* pcfTxt = NULL;

    //Trying to open 'C:\\TestDir\\Test.txt' for reading BUT CRASH HAPPENS HERE (unhandled Exception)
    pcfTxt = new CFile(_T("C:\\TestDir\\Test.txt"), CFile::modeRead | CFile::shareDenyNone);

    INT nLogTxtLen = pcfTxt->GetLength();
}


In Debug mode (without a Debug point), the crash is shown at

pcfTxt = new CFile(_T("C:\\TestDir\\Test.txt"), CFile::modeRead | CFile::shareDenyNone);

But if I place a debug point at :

pcfTxt = new CFile(_T("C:\\TestDir\\Test.txt"), CFile::modeRead | CFile::shareDenyNone);

and then continue, no crash arises.

I guess the issue is something to do with the handle of 'C:\\TestDir\\Test.txt' file.

How could I rectify this.

Is some Sleep() required to wait for the handle to be available.

Replies would be appreciated.

Thanks
Edit/Delete Message
AnswerRe: Why am I not able to get handle of file? Pin
SandipG 25-Feb-09 1:05
SandipG 25-Feb-09 1:05 
GeneralRe: Why am I not able to get handle of file? Pin
ky_rerun25-Feb-09 3:47
ky_rerun25-Feb-09 3:47 
GeneralRe: Why am I not able to get handle of file? Pin
SandipG 25-Feb-09 4:38
SandipG 25-Feb-09 4:38 
QuestionRe: Why am I not able to get handle of file? Pin
David Crow25-Feb-09 3:22
David Crow25-Feb-09 3:22 
AnswerRe: Why am I not able to get handle of file? Pin
ky_rerun25-Feb-09 5:58
ky_rerun25-Feb-09 5:58 
AnswerRe: Why am I not able to get handle of file? Pin
Stuart Dootson25-Feb-09 12:06
professionalStuart Dootson25-Feb-09 12:06 
QuestionSerial coms worker thread not working Pin
jimjim73324-Feb-09 23:30
jimjim73324-Feb-09 23:30 
AnswerRe: Serial coms worker thread not working Pin
Cedric Moonen24-Feb-09 23:40
Cedric Moonen24-Feb-09 23:40 
GeneralRe: Serial coms worker thread not working Pin
jimjim73325-Feb-09 0:20
jimjim73325-Feb-09 0:20 
QuestionFew doubts in MFC application?? Pin
kapardhi24-Feb-09 23:22
kapardhi24-Feb-09 23:22 
AnswerRe: Few doubts in MFC application?? Pin
Iain Clarke, Warrior Programmer24-Feb-09 23:45
Iain Clarke, Warrior Programmer24-Feb-09 23:45 
QuestionCreateProcess in WinCE Pin
vijaywithu24-Feb-09 22:48
vijaywithu24-Feb-09 22:48 
AnswerRe: CreateProcess in WinCE Pin
Sethuraman.K24-Feb-09 23:33
Sethuraman.K24-Feb-09 23:33 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K24-Feb-09 23:49
Sethuraman.K24-Feb-09 23:49 
GeneralRe: CreateProcess in WinCE Pin
vijaywithu24-Feb-09 23:50
vijaywithu24-Feb-09 23:50 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K25-Feb-09 0:07
Sethuraman.K25-Feb-09 0:07 
GeneralRe: CreateProcess in WinCE Pin
Sethuraman.K25-Feb-09 0:31
Sethuraman.K25-Feb-09 0:31 

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.