|
All,
I have a routine that writes to a USB device using the WriteFile API. The problem is, the USB device I'm writing to has a low battery, so when the WriteFile attemps to send data, it never gets a response back from the device.
The WriteFile gets its handle from an HID driver (Human Interface Device). I am calling the WriteFile with the LPOVERLAPPED structure (I need it for the ReadFile API, and you can't mix and match overlapped with non-overlapped). I would like to have the function return if it doesn't get a response back after X number of retires or X number of seconds...either or.
Any suggestions on how I can do this?
Regards,
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
What do you mean the function does not return? Given that the design is non-blocking via OVERLAPPED I/O, WriteFile() should return immediately.
Kuphryn
|
|
|
|
|
Since the USB device I'm writing to has a low battery, there is never a return message packet sent back to Windows from the WriteFile. So, the system just hangs in the WriteFile event forever. I put a breakpoint on the line after the WriteFile and it never gets there. Is there any way to cancel the IO after say 5 seconds of inactivity?
Regards,
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
Interesting. In terms of C++, one solution is be an exception try/catch.
Kuphryn
|
|
|
|
|
I have a CFormView and I need to capture the ESC key. The control the has the focus always receive the OnChar but the form never does. I don't want to use an Accelerator nor any code on the controls.
Any Ideas?
|
|
|
|
|
Just a guess:
Override PreTranslateMessage in your CFormView.
Mazy
"And the carpet needs a haircut, and the spotlight looks like a prison break
And the telephone's out of cigarettes, and the balcony is on the make
And the piano has been drinking, the piano has been drinking...not me...not me-Tom Waits
|
|
|
|
|
PreTranslateMessage is never called on the CFormView
|
|
|
|
|
thats how i did it.. here is some code from one of my dialogs that is derived from CFormView..
in my .h
BOOL PreTranslateMessage(MSG* pMsg);
in my .cpp
BOOL CST3WKSHT::PreTranslateMessage(MSG* pMsg)
{
CSCTaxApp* pApp = (CSCTaxApp*)AfxGetApp();
if(pMsg->message==WM_KEYDOWN && pApp->m_bEnterAsTab)
{
if(pMsg->wParam==VK_RETURN)
pMsg->wParam=VK_TAB;
}
return CFormView::PreTranslateMessage(pMsg);
} this converts my keypresses from enters to tabs.. and it does work.. hope that helps
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
Thank for the help. I had a problem in my code:
MSDN Library:<br />
PRB: Modal Dialog Box Prevents Calls to PreTranslateMessage <br />
ID: Q126874
|
|
|
|
|
Hello,
After using VS6 a lot I found out how to save my work environment (window positions, toolbar and menu bar content and positions, fonts, colors etc.) by experimenting with the registry. This is extremely useful when you reinstall your machine or if you use a lot of test machines where you just don't want to reconfigure everything.
While migrating to VS7 I find that this is no longer possible. I just don't know where my settings are stored. I tried saving all the registry settings I could find (and this is bad, because I only would like to save the parts that are related to the UI - and is of no help anyway), the files I thought that are worth saving but I am still unable to backup my environment.
Anyone knows where all this stuff gets saved?
Regards,
Levente
------------------------------------------->>
Life is tough. Then die you do. [Yoda]
|
|
|
|
|
Levente Farkas wrote:
Anyone knows where all this stuff gets saved?
Unfortunately, not me. But I have often wondered about this myself.
From what I have heard the config is stored all over the show, registry, config files, etc.
If any one figures this out. Please share.
[edit]
It seems we're not alone... How do I move my VS.NET Studio Settings to another Computer?[^]
Oh and this message probably should be in the VS.NET IDE Issues forum.
[/edit]
Bruce Duncan, CP#9088, CPUA 0xA1EE, Sonork 100.10030 Blackadder: Baldrick, have you no idea what irony is? Baldrick: Yeah, it's like goldy and bronzy only it's made of iron.
|
|
|
|
|
Yeah, right. I just saw that there is such a forum called "VS.NET IDE issues".
------------------------------------------->>
Life is tough. The die you do. [Yoda]
|
|
|
|
|
How do you make a toolbar or dialogbar in a DLL that you can dock with the main window in mfc, and if possible have the DLL handle the messages output from the toolbar.
Is there any easy way to do this?
|
|
|
|
|
I used Seagate Crystal Report 8.5 with my VC project. It's excelent on printing and preview. But when I export the datasheet to MsWord or MsExcel, the column's borders and the row's borders disappear (but when I export to Acrobat PDF, it works)
Just a question: why Seagate can't export completely with border on MsWord and MsExcel ?
=======================
Nothing is perfect
|
|
|
|
|
Hi,
I am looking for books that will help me learn about windows networking API's. Say I want to know the ways by which I can transfer a file from one computer to another under windows 2k. Obviously FTP is the answer, but are there any other ways ?
I am looking forward to your suggestions.
~ Vimal
|
|
|
|
|
if you are just copying a file and its a local network then you can use regular file copy commands and just pass the network name of the computer and path.. like '\\mycomp\uploads\'.. it really depends on the use as to what methods you would want to use.. obviously you wouldn't want to use ftp unless you are going to have machines running ftp servers as well..
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
|
But why buy expensive books when u learn learn learn from the internet!
It's how i got all my knowledge (not that its that much lol) and the books i did buy (3 now, and only 1 is about C/C++) didn't help me much at all!
Oh wait.. there's a simple answer to my first question. Don't say it! To pay the authors salary because we might end up writing a book of our own one day and we would want people to buy it and not just look it all up on the internet.
Kuniva
--------------------------------------------
|
|
|
|
|
I highly recommend Network Programming for Microsoft Windows, Second Edition
by Anthony Jones and Jim Ohmund.
Kuphryn
|
|
|
|
|
Hi,
How can I access to I/O port in NT Windows?
Thank you for your guides, beforehand.
|
|
|
|
|
You can use WinRT http://www.pds-site.com/Bsquare/WinRT/default.htm[^].
Or you could write your own device driver.
However, user mode code isn't allowed to access i/o ports directly since that would be a security violation.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
i am so utterly frustrated right now.. i have been trying to pass a string from VB into a function, modify it and return it back to VB.. but i just cannot understand this BSTR crap.. i have tried to accomplish this 2 ways and im stuck both.. so im gunna list em both, and maybe someone will know how to fix one? thanks a bunch for any advice..
Problem number 1:
I pass 3 variables into my function..
FindBankName(strFilename, strRoutingNumber, strBankName)
when i call this function from VB i pass it these values in this order:
("C:\\FedACHdir.txt", "282976020", "bankname")
but as you will see below my c++ function does not get them in this order..
c++ function:
void __stdcall CFpsPayTaxxApp::FindBankName(BSTR strFilename, BSTR strRoutingNumber, BSTR strBankName)
{
CString strTemp;
strTemp = "The Filename passed is: >" + (CString) (LPCTSTR)strFilename + "<";
AfxMessageBox(strTemp);
strTemp = "The RoutingNumber passed is: >" + (CString)(LPCTSTR)strRoutingNumber + "<";
AfxMessageBox(strTemp);
strTemp = "The BankName passed is: >" + (CString)(LPCTSTR)strBankName + "<";
AfxMessageBox(strTemp);
}
what i get for output is 3 message boxes.. the first says ">282976020<", the second ">bankname<", and the third has funky characters.. so the first parameter is never seen.. i have tried passing by reference, not by reference, passing with a return value, without a return value, passing as char* instead of BSTR, but i never get the first parameter.. the other problem with this approach is that i crash when i modify the passed in BSTR's..
Problem number 2:
I tried to take an ATL dll that is on CP which has examples involving BSTR's.. i got that dll to work fine with the parameters being passed.. the function even modified the string and returned it as modified (which i cant seem to do in the first method at all without crashing).. the problem here is that i can't seem to modify the string and return it.. probably because i am not handling the BSTR's properly.. but at least the example works, its just way to cryptic for me.. here is what i have trying to just return the variable modified.. it doesn't work either..
void __stdcall GetBankName(BSTR strFilename, BSTR strRoutingNumber, BSTR strBankName, BSTR strErrResponce)
{
strBankName = "what the?";
} this doesnt change the text.. and the example i have i cant even follow..http://www.codeproject.com/dll/superdll.asp[^]
Conclusion:
problem #1 working would be alot better for me because i could use CStrings and other MFC things, where as problem #2 uses ATL and I am so lost dealing with these BSTR strings.. all I need to do is be able to set a char* array to a BSTR.. but i just cant seem to follow it..
if you have any idea what im doing wrong in #1, or can offer some suggestions on understanding modifying BSTR's in problem #2 i would be very appreciative.. thanks
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
"(CString) (LPCTSTR)strFilename " is very bad idea.
try
a)
#include "comdef.h"
CString str = _bstr_t(strFilename);
b.)
CString str = OLE2T(strFilename);
|
|
|
|
|
ill keep that in mind.. how would i turn it back to a CString, or better yet how would i turn a BSTR to a char* and then back to a BSTR?
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
void functionF(BSTR bstr)
{
CComBSTR cBstr = bstr;
CString str(bstr);
CString strAppend;
strAppent = str + CString(bstr); //Appending Strings
strAppend += str;
//Similiar with CComBSTR and _bstr_t
}
|
|
|
|