Click here to Skip to main content
15,903,033 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Extract numbers from string Pin
Niklas L5-Oct-10 8:28
Niklas L5-Oct-10 8:28 
QuestionTabbed dialog problrm Pin
g_sandipan5-Oct-10 1:12
g_sandipan5-Oct-10 1:12 
AnswerRe: Tabbed dialog problrm Pin
Cool_Dev5-Oct-10 1:52
Cool_Dev5-Oct-10 1:52 
QuestionReadFile asynchronously Pin
MKC0025-Oct-10 0:06
MKC0025-Oct-10 0:06 
AnswerRe: ReadFile asynchronously Pin
CPallini5-Oct-10 1:42
mveCPallini5-Oct-10 1:42 
GeneralRe: ReadFile asynchronously Pin
MKC0025-Oct-10 21:36
MKC0025-Oct-10 21:36 
GeneralRe: ReadFile asynchronously Pin
CPallini5-Oct-10 22:23
mveCPallini5-Oct-10 22:23 
GeneralRe: ReadFile asynchronously Pin
MKC0025-Oct-10 22:50
MKC0025-Oct-10 22:50 
Without using overlapped, Sometime ReadFile takes very long time(say 5 minutes) to read some data. And this create a big issue for me because after that ReadFile does not read any data from any offset. So i decided to use IO overlapped. Passed FILE_FLAG_OVERLAPPED in CreateFile and OVERLAPPED structure in ReadFile.
But here also when i call GetOverlappedResult after ReadFile program hangs because GetOverlappedResult takes 5 minutes. So i decided to create event for OVERLAPPED STRUCTURE. After creating event i call a thread where i check the elapse time. And if time pass more than 1 minutes then i call CancelIO operation to cancel the GetOverlappedResult but still it did not help me. Please check my below code and suggest

in header file, define 2 variables
OVERLAPPED osReadOperation;
HANDLE hFile;

in cpp file

void myfunc()
{
TCHAR szFileName[255];
memset(szFileName,0,sizeof(szFileName));
sprintf(szFileName,"\\\\.\\PHYSICALDRIVE0");
hFile = CreateFile(szFileName,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);

if (hFile == INVALID_HANDLE_VALUE)
return;

BOOL fOverlapped = FALSE;
char* pDataBuf = new char[83886081];
memset(pDataBuf,0,sizeof(pDataBuf));
DWORD NumberOfBytesRead = 0;

DWORD NumberOfBytesTransferred = 0;
memset(&osReadOperation,0,sizeof(osReadOperation));
osReadOperation.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
SetEvent(osReadOperation.hEvent);
AfxBeginThread(myThread, this);
int result = 0;
if (!ReadFile(hFile,pDataBuf,83886080,&NumberOfBytesRead,&osReadOperation ))
{
if (GetLastError() != ERROR_IO_PENDING)
return;
else
fOverlapped = TRUE;
}
else
fOverlapped = FALSE;

if (fOverlapped)
{
if (GetOverlappedResult( hFile,&osReadOperation,&NumberOfBytesTransferred,TRUE))
result = 1;
else
return;
}
else
result = 1;
CloseHandle(osReadOperation.hEvent);
osReadOperation.hEvent = NULL;
}

void CAlldrivesDlg::canceltheoperation()
{
CancelIo(hFile);
}
UINT myThread(LPVOID me)
{
CAlldrivesDlg *th = (CAlldrivesDlg*)me;
OVERLAPPED * self = &th->osReadOperation;
DWORD ww = WaitForSingleObject(self->hEvent, 1000);
int bm=2;
switch(ww)
{ /* waitfor */
case 0:
th->canceltheoperation();
break;
default:

break;
} /* waitfor */
ResetEvent(self->hEvent);


return 0;
}
GeneralRe: ReadFile asynchronously Pin
CPallini5-Oct-10 23:19
mveCPallini5-Oct-10 23:19 
GeneralRe: ReadFile asynchronously Pin
MKC0026-Oct-10 0:09
MKC0026-Oct-10 0:09 
QuestionCustomize CMFCPropertyGrid Pin
silversamand4-Oct-10 23:57
silversamand4-Oct-10 23:57 
QuestionCan we create a multi layer tiff image as it is in Photoshop with the help of Libtiff library? Pin
002comp4-Oct-10 18:13
002comp4-Oct-10 18:13 
AnswerRe: Can we create a multi layer tiff image as it is in Photoshop with the help of Libtiff library? Pin
002comp4-Oct-10 20:57
002comp4-Oct-10 20:57 
AnswerRe: Can we create a multi layer tiff image as it is in Photoshop with the help of Libtiff library? Pin
Chris Losinger5-Oct-10 3:54
professionalChris Losinger5-Oct-10 3:54 
GeneralRe: Can we create a multi layer tiff image as it is in Photoshop with the help of Libtiff library? Pin
kakan6-Oct-10 21:04
professionalkakan6-Oct-10 21:04 
GeneralRe: Can we create a multi layer tiff image as it is in Photoshop with the help of Libtiff library? Pin
Chris Losinger7-Oct-10 1:13
professionalChris Losinger7-Oct-10 1:13 
QuestionChange the content of a tooltip Pin
Schehaider_Aymen4-Oct-10 10:45
Schehaider_Aymen4-Oct-10 10:45 
AnswerRe: Change the content of a tooltip Pin
LunaticFringe4-Oct-10 12:01
LunaticFringe4-Oct-10 12:01 
QuestionOnInitialUpdate Pin
john56324-Oct-10 6:33
john56324-Oct-10 6:33 
AnswerRe: OnInitialUpdate Pin
josda10004-Oct-10 6:38
josda10004-Oct-10 6:38 
QuestionRe: OnInitialUpdate Pin
David Crow4-Oct-10 7:31
David Crow4-Oct-10 7:31 
AnswerRe: OnInitialUpdate Pin
Schehaider_Aymen4-Oct-10 10:47
Schehaider_Aymen4-Oct-10 10:47 
QuestionRedirect Message Box Messages, Pin
Joschwenk6664-Oct-10 5:00
Joschwenk6664-Oct-10 5:00 
AnswerRe: Redirect Message Box Messages, Pin
Code-o-mat4-Oct-10 9:23
Code-o-mat4-Oct-10 9:23 
GeneralRe: Redirect Message Box Messages, Pin
Sameerkumar Namdeo4-Oct-10 22:27
Sameerkumar Namdeo4-Oct-10 22:27 

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.