|
Hello, this is a very simple program to test asynchronous device io.
But when this program runs on Vista, io is always asynchronous; when it is XP, io is always synchronous.
I don't know why? Does Vista's io more efficient than XP?
Thank you!
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE g_hIOCP = ::CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, 0, 0);
if (g_hIOCP == NULL)
{
cout<<"can not create io completion port"<<endl;
return 1;
}
HANDLE hFile = CreateFile(L"d:\\test.abc", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (hFile == NULL)
{
cout<<"can not open file"<<endl;
}
HANDLE hTest = ::CreateIoCompletionPort(hFile, g_hIOCP, (ULONG_PTR)hFile, 0);
if (hTest != g_hIOCP)
{
cout<<"failed to associate file to completion port"<<GetLastError()<<endl;
return 0;
}
for(int i = 0; i < 5; ++i)
{
OVERLAPPED ov = {0};
char szBuf[128];
DWORD lpNumberOfBytesRead = 0;
BOOL b = ::ReadFile(hFile, szBuf, 128, &lpNumberOfBytesRead, &ov);
if (b == FALSE)
{
cout<<"ReadFile failed,last error code is:"<<::GetLastError()<<endl;
if (::GetLastError() == ERROR_IO_PENDING)
{
cout<<"read file asynchronously"<<endl;
}
}
else
{
cout<<"read file synchronously"<<lpNumberOfBytesRead<<"bytes"<<endl;
}
}
return 0;
}
A Chinese VC++ programmer
|
|
|
|
|
I don't know why it is different in XP and Vista, but specifying the FILE_FLAG_OVERLAPPED flag in CreateFile() means that it is an asynchronous call; however, this article may be of use.
[Edit]
Apologies I didn't see your FLAG_FILE_OVERLAPPED remark in your code sample - the article may still be useful to you though
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Thank you!
I'll read this article
A Chinese VC++ programmer
|
|
|
|
|
There is a MSKB on Asynchronous IO with details on Synchronous I/O occuring even when the file is opened using FILE_FLAG_OVERLAPPED attribute. See if this helps -
Asynchronous I/O Still Appears to be Synchronous[^]
Sohail
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I blindly believe that if FILE_FLAG_OVERLAPPED flag was set, then all the i/o operation will be processed asynchronously, but it seems that not quite right.
Thank you!
A Chinese VC++ programmer
|
|
|
|
|
Glad I could help
Sohail
Please mark helpful answers
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hi,
I am migrating my code to VS2005 from VS2003. We have certain components which are .dll files but they are named as .ddl files .When i migrate to VS2005 and i open my client exe in dependency walker than the dependant .ddl file is shown as unavailable(with a question mark) in the walker.
this mainly happens coz it has been renamed from .dll to .ddl(as per requirement).
My question is , why does this happen in vs2005 only and how do i solve this?. Will it create problem at runtime?.
NOTE: in VS2003 the file was seen available in the dependency walker.
Replies are welcome
Regards,
Shailesh H
|
|
|
|
|
why do you need them to be called ddl files?
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
Well the reason for naming DDL is non technical. Its only to recognize the dll file thats the project requirement which we cannot change.
thanks
|
|
|
|
|
Check whether it isnt a writing mistake of some non-IT typ of manager.
After all it is bad style
Greetings from Germany
|
|
|
|
|
Its a bad style.. but it works in VS2003 and problems in VS2005.
|
|
|
|
|
Did the DLL project's linker option for output file get set to
$(OutDir)\$(ProjectName).dll
instead of what you want it to be?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
I am geting error this
[code]
error C2228: left of '.ErrorMessage' must have class/struct/union
error C3861: '_com_error': identifier not found
[/code]
Plz help me
|
|
|
|
|
so what's your code dude ?
you must have the object at left of method ErrorMessage() of type class, struct or union....
show us the line of code incriminated.
|
|
|
|
|
ok here is code
[code]
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
for(int i=0; i<sizeof(GUID_DEVINTERFACE_LIST)/sizeof(GUID); i++) {
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_LIST[i];
hDevNotify = RegisterDeviceNotification(this->GetSafeHwnd(), &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
if( !hDevNotify ) {
AfxMessageBox(CString("Can't register device notification: ")
+ _com_error(GetLastError()).ErrorMessage(), MB_ICONEXCLAMATION);
return FALSE;
}
[/code]
|
|
|
|
|
Probably you need to include comdef.h header (and link with the corrensponding library, see the Requirements section of this page [^]) in your application).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[Image resize DLL]
|
|
|
|
|
i had comdef.h header but i havn't found comsuppw.lib or comsuppwd.lib .So how can i download it..
Plz help me
|
|
|
|
|
Probably you have a different version of Visual Studio (the link in my post was about VS 2008 ). Check out the documentation appropriate for your system, for instance the library needed, when using VS 2003 , is comsupp.lib , see [^]).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[Image resize DLL]
|
|
|
|
|
|
Then you should found both the libraries (comsuppw.lib & comsuppwd.lib ) inside <your VS installation path>\VC\lib , I suppose.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[Image resize DLL]
|
|
|
|
|
Hi ,
http://www.codeproject.com/KB/printing/QPrint.aspx[^]
There is any option in table for set table column width according to text.
Because now here if the data is larger than the column than it not print all data.
I want column width is automatically incresed when data is large.
Thanks in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
You have already asked this question at the discussion forum of the article page. Can you please wait until the author responds? You could have asked it here if the author didn't respond in a day or two.
You had to post it here in another two minutes after asking there? You see, cross-posting is just plain rude (even if it is urgentz).
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche
.·´¯`·->Rajesh<-·´¯`·.
[Microsoft MVP - Visual C++]
|
|
|
|
|
Ok sir.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
This code is taken from "http://www.codeproject.com/KB/list/lvcustomdraw.aspx" an MFC project. i made changes in the code to suitable for a Win32 project. But this code is not working.
i am able to get CDDS_PREPAINT but not ITEMPREPAINT or (CDDS_ITEMPREPAINT | CDDS_SUBITEM).
if( ((NMHDR*)lParam)->code == NM_CUSTOMDRAW )
{
pLVCD = reinterpret_cast<nmlvcustomdraw*>( lParam );
if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
{
return CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{
return CDRF_NOTIFYSUBITEMDRAW;
}
else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{
COLORREF crText, crBkgnd;
if ( 0 == pLVCD->iSubItem )
{
crText = RGB(255,0,0);
crBkgnd = RGB(128,128,255);
}
else if ( 1 == pLVCD->iSubItem )
{
crText = RGB(0,255,0);
crBkgnd = RGB(255,0,0);
}
else
{
crText = RGB(128,128,255);
crBkgnd = RGB(0,0,0);
}
pLVCD->clrText = crText;
pLVCD->clrTextBk = crBkgnd;
return CDRF_DODEFAULT;
}
}
Thanks & Regards
|
|
|
|
|
Hi all,
This may seem very elementary, but why "&a + 1" and "a + 1" are different in the following code
int a[5] = {1, 2, 3, 4, 5};
int* ptr = (int*)(&a + 1);
printf("%d, %d", *(a + 1), *(ptr-1));
Thanks,
|
|
|
|