WriteFile function hangs!

Hi,
    I am printing something through the LPT using the API WriteFile. This is
working fine when the printer is connected to the system.But if the printer
is not connected then it hangs!! When debugged it found that the program
hangs in WriteFile function. Its not coming out from that function!! How to
solve it? Pls help...

rgds,
RENAK.


0
7/30/2004 10:35:40 AM
vc.mfc 33608 articles. 0 followers. Follow

2 Replies
609 Views

Similar Articles

[PageSpeed] 46

It may just be trying to write all of the characters and waiting for each to
time out since the printer is not there.  You may want to check for access
to the printer perhaps by trying to write a single innocuous control
character to the printer first (backspace for example) to see if you can
write.  Then you would only have to wait for one character to time out
before getting the failure return or exception.

Tom

"RENJITH A K" <renjith.ak@m2comsys.com> wrote in message
news:uWoZDFidEHA.3616@TK2MSFTNGP10.phx.gbl...
> Hi,
>     I am printing something through the LPT using the API WriteFile. This
is
> working fine when the printer is connected to the system.But if the
printer
> is not connected then it hangs!! When debugged it found that the program
> hangs in WriteFile function. Its not coming out from that function!! How
to
> solve it? Pls help...
>
> rgds,
> RENAK.
>
>


0
tserface (3860)
7/30/2004 5:58:26 PM
Tom Serface wrote:

> It may just be trying to write all of the characters and waiting for each to
> time out since the printer is not there.  You may want to check for access
> to the printer perhaps by trying to write a single innocuous control
> character to the printer first (backspace for example) to see if you can
> write.  Then you would only have to wait for one character to time out
> before getting the failure return or exception.
> 
> Tom
> 
> "RENJITH A K" <renjith.ak@m2comsys.com> wrote in message
> news:uWoZDFidEHA.3616@TK2MSFTNGP10.phx.gbl...
> 
>>Hi,
>>    I am printing something through the LPT using the API WriteFile. This
> 
> is
> 
>>working fine when the printer is connected to the system.But if the
> 
> printer
> 
>>is not connected then it hangs!! When debugged it found that the program
>>hangs in WriteFile function. Its not coming out from that function!! How
> 
> to
> 
>>solve it? Pls help...
>>
>>rgds,
>>RENAK.
>>
>>
> 
> 
> 

 From MSDN: "If hFile was not opened with FILE_FLAG_OVERLAPPED and 
lpOverlapped is NULL, the write operation starts at the current file 
position and WriteFile does not return until the operation has been 
completed."

With that being said I don't think that writing a byte to the LPT port 
would help him out any.

If you are using a standard printer you may consider using 
OpenPrinter/WritePrinter/ClosePrinter functions (these use the system 
spooler rather than trying to write directly to the port).  This is the 
recommended "Windows" way to print.  You can still send custom commands 
via the Escape function.  If it is too slow see about using a text only 
driver.

Another idea is to use Overlapped I/O.   You can implement your own 
timeout mechanism with this and call CancelIo on the HANDLE if the 
timeout expires.  HTH.
0
trevor8686 (35)
7/30/2004 7:33:04 PM
Reply:

Similar Artilces:

Workday function question
I am slightly confused with the Workday function and would appreciate advice. If I have paid someone to work 21 days (Monday to Fridays, weekends (Saturday and Sunday) excluded, starting work on 1st February 2010 then I would expect their last working day to be 1st March 2010. Using the Workday function (not including holidays) then I get an answer of 2nd March 2010. As below =WORKDAY(DATE(2010,2,1),21) To get my required date then I have to put -1 at the end. Is this correct? -- with kind regards Spike Yes. Date calculations exclude the starting day. If you tell...

WriteFile
Hi , I am using WriteFile function for writting some data to harddisk. Is there any limit in size of data it can write. Basically this function is writting imcomplete data. I checked the contents of file. ( Writs encoded data to file then decode the data using Winzip ( MIME data ) no of Bytes are at boundries like : fff, 9fff, ffff ... Any idea why this is hapening ? I'm not sure if there is a limit, or how to find out. Are you checking the parameter that tells the number of bytes written to see if it equals the number of bytes to write? Perhaps you can just keep calling WriteFile...

function tooltips
Hi - Are the function tooltips not available for functions in the Analysis ToolPak? They work on all of the built-in functions. Thanks for any info. G The tooltips don't appear, but you can press Ctrl+Shift + A after you type the first bracket, to see the arguments for the function. Gary wrote: > Hi - > > Are the function tooltips not available for functions in > the Analysis ToolPak? They work on all of the built-in > functions. Thanks for any info. -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html Thank you Debra. Tha...

Function to Find & Replace within Range
How do I find & replace text within a range using a function. I can do this with the Replace command on the Edit menue by selecting a range and filling in the FINE and REPLACE fields then select REPLACE ALL. I want to search the TEXT range (D2:D3032) for the "old_text" given in Cell F3 and replace any matches with the "new_text given in cell G3. Then I want to repeat this process with "old_text" given in Cell F4 and replace any matches with the "new_text given in cell G4. And so on.....until the next cell going down in Column F is blank. Thanks for any h...

wildcards in sumproduct functions
I would prefer to use a wildcard for text criteria in sumproduct counting and adding equations. I have tried versions of "*ABC*" and get false values. You would need to use something like this: =3DSUMPRODUCT(--(ISNUMBER(SEARCH("ABC",A1:A10))), other conditions...) i.e. you are looking to see if ABC is contained within any of the cells in the range A1 to A10. You can use FIND instead of SEARCH if the case of the text string is important. Hope this helps. Pete On Feb 18, 12:38=A0am, K1 <K...@discussions.microsoft.com> wrote: > I would prefer to...

WriteFile and ERROR_INSUFFICIENT_BUFFER
I'm using the WriteFileEx function to write a file asynchronously. However I sometimes get the error code ERROR_INSUFFICIENT_BUFFER (with GetLastError), although the function still returns a success and the data gets written ok. However I don't think it is actually doing an asynchronous write. I open the file with a call to CreateFile, with the flags: FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING To satisfy the No buffering, I use VirtualAlloc and make sure source/dest and size values are all aligned to sector sizes. That bit seems fine. Also, if I try...

MFC/SDI How to access view's function from mainframe
Hi, This is my first time doing SDI applications so this doc/view/ mainframe thing is pretty new to me. Now i'm doing a program where i access to sql database thru ODBC and put data into recordset and everything works fine. However now i need to close that recordset when user quits the program. What i understood that the mainframes OnClose()-function is the one that handles quitting from File/Quit and the X-button, so i need to access to the Views recordset from the mainframes OnClose()-function. And there is other cleanup jobs i need to do when quitting so accessing to View would be good...

What Does This Function Do?
I have a spreadsheet with the following function:- BB!G1 What does it do please? Thanks. It gets the value of cell G1 in worksheet BB. -- HTH Bob Phillips "Saxman" <john.h.williamsREMOVETHIS@btinternet.com> wrote in message news:dcqetf$1t0$2@nwrdmz01.dmz.ncs.ea.ibs-infra.bt.com... > I have a spreadsheet with the following function:- > > BB!G1 > > What does it do please? > > Thanks. Hi Maybe =BB!G1 When yes, then it isn't a function, it is a cell reference - a value from cell G1 on sheet BB is returned. -- Arvi Laanemets ( My real mail ...

functions in excel
i like to know what are the functions available in msexcel>>>>>> kaja48380@gmail.com wrote: > i like to know what are the functions available in msexcel>>>>>> Is this homework? Functions: see http://www.techonthenet.com/excel/formulas/ Your other question: http://office.microsoft.com/en-ca/excel/HA010548461033.aspx?pid=CH062528191033 best wishes -- Bernard V Liengme Microsoft Excel MVP http://people.stfx.ca/bliengme remove caps from email <kaja48380@gmail.com> wrote in message news:15ef1958-9401-4a4e-967a-6798442a7c3c@e6g2000prf.googlegroup...

Time Functions
Hi, I am trying to set up a timesheet whereby I can put in the start time and end time of the job and get it to calculate the amount of time spent on the job. a) Is there anything I can put in a cell that would get it to read the time from the computers clock (and not update as time goes by) b) Is there a function available that would calculate how long I have spent on the job. Thanks in advance. Hi, To get a 'static' time in a cell hold down CTRL + Shift and tap ; Doing this at the start and then end of the task would give you the times. Calculation...

really bugging me now guys/send/recieve hanging
please help guys, outlook still hanging at 80-83% what is causing this? I have done everything even re-entering my account details for all of my accounts. Outlook used to whip through the send and recieve process now it slows at 66% then hangs at 80-83%. I cannot work out anything that would be causing this to happen? ...

Nested IF function
I am having trouble in my excel class again. Nothing seems to be even close to what we do in the book when we get to the assingments. Need to enter a formula using the Nested If function to determine the number of vacation days each employee is eligible for based on the employees job status in column B and on the number of years employed in Column C. criteria is: 17days for full-timeemployees who have worked more than 5 years -- 12days for full-time employees who have worked more then 1 year 7 days for full-time employees who have worked 1 year or less ...

Using the "if" function, the "and" function and the "or" function
I am not sure if or how to use all three in a formula. For example: =if(b2="red", and c3="blue", d6="green") if that makes sense at all. Maybe something like: =if(and(b2="red",c3="blue",d6="green"),"all three match!","not all 3 match") or =if(or(b2="red",c3="blue",d6="green"),"at least one matches","none match") or you can use both to make the criteria more complex =if(and(b2="red",or(c3="blue",d6="green")),then,e...

The IF function
How can i use the IF funvction to find the highest value, from a list of 19 values? Don't use if for that. Use =max(A1:A19) or something like that. Szalapski -- TommySzalapski ------------------------------------------------------------------------ TommySzalapski's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=25561 View this thread: http://www.excelforum.com/showthread.php?threadid=398796 Emma, You don't need an IF function. Instead, use the MAX function. E.g., =MAX(A1:A19) will return the largest value in cells A1:A19. -- Cordially, Chip...

Function to write Weekday
What is the function to write Weekday only (MOnday, Tuesday etc) from the given date. For example, when I write date as 26 September 2005, the function should return the value of Monday. Hello Set a formula refering to the date and simply format cell as dddd HTH Cordially Pascal "Shrikant" <Shrikant@discussions.microsoft.com> a �crit dans le message de news: C9A5BA2A-7626-4C45-B3E7-67B8AC88C6A6@microsoft.com... > What is the function to write Weekday only (MOnday, Tuesday etc) from the > given date. For example, when I write date as 26 September 2005, the > funct...

Workday function not working
Hello, Why does it returns "#NAME?" when I use =WORKDAY function in Excel 2003? My formula is =WORKDAY(D4,-B1,Holiday!A2:E109) where D4 is a date and B1 is the number of days. Any sugguestion, thank you. Hi, Straight from E2003 help If this function is not available, and returns the #NAME? error, install and load the Analysis ToolPak add-in. Tools - Addins and then do what help says -- Mike When competing hypotheses are otherwise equal, adopt the hypothesis that introduces the fewest assumptions while still sufficiently answering the question. &...

WriteFile need help,
Can some one explaint to me why is my output file print out garbage string, event I print BOM at the begining of the file? Did I miss something? output.txt ⁥Tue Feb 07 15:22:02 2006⁢ Testing log file 1. ///////////MY CODE//////////////////// WORD BOM=0xfeff; DWORD cBytes; hFile = CreateFile(szDirectory, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (NULL != hFile && INVALID_HANDLE_VALUE != hFile) { SetFilePointer(hFile, 0, NULL, FILE_BEGIN); WriteFile(hFile, &BOM, sizeof(BOM), &cBytes, NULL); } void WriteToFile(wchar_t* p_...

Is there a solution for writefile fails in vista
I was trying to write from starting sector of the harddisk through writefile function, In vista WriteFile() function fails(Access denied) due to security methods in vista and server 2008. Is there a solution for this ??? There are better Vista programmers here than me, but I think you either need to: Elevate your program to a status that allows this function Have your user run as an administrator account to do this kind of advanced functionality Disable UAC Some things to try anyway. Tom "StudioX" <StudioX@discussions.microsoft.com> wrote in message news:3837A5AB-2FF...

Great Plains 7.5 Hangs when "Manufacturing Orders" window opened
Hi, I'm using Great Plains 7.5 on a 2000 SQL Server. We can open the "Manufacturing Orders" window in a "play company," but when we try to open it in our live company Great Plains freezes and has to be closed by ending the task. No error messages are displayed. What could be the source of this issue? Any ideas would be greatly appreciated. -- Mark Morency Addition to original post: It doesn't hang when "Manufacturing Orders" is initially selected. It only hangs when the sub-items "Entry" or "Quick MO" are clicked from th...

functionality
Hi, I just began to use the calendar function in Outlook 2000. When i tried to "Publish it to web" or to "export" it said i need to install the additional functionality. So, when i tried to install that, it said i needed the Windows 2000 cd-rom, which i don't have becaue windows 2000 came preinstalled. I called Dell and they were not help. Anyone know where i can get this resolved without having the windows 2000 cd-rom. I think the package it said i needed was "DATA1.msi". Any help would be greatly appreciated! austin .. ...

xirr function
Hi, I am using the xirr function and when I enter a large number the result reverts to 0%. Anyone know why? Any help would be appreciated. Thanks, Jim On Apr 22, 4:39=A0pm, "Jim" <jimnormab...@comcast.net> wrote: > Hi, > I am using the xirr function and when I enter a large number the result > reverts to 0%. =A0Anyone know why? =A0Any help would be appreciated. > Thanks, Jim If the number is negative (the sum of the cashflow) you need to provide a negative guess in order for the XIRR function to work. But not sure this is the problem you have encountered. ...

Counting data function
Hello, I am hoping someone can help me out. I have a large spreadsheet which records various data regarding rejected parts. I want to include a function/conditional formatting that will count if there is more than one rejected part number in the last 90 days. There is a date column where the date of rejection is entered. I would like this "part number" cell to turn a different color to identify multiple rejections. Can someone help? You can try to see if this works the way you want. But you will need a helper column. Assume the following: A ...

If function and a range
I have the following function and it is only half working for me as my arguements seem to contradict one another as I want to see if my number falls within a specified range. Any suggestions appreciated =IF(F3<2,"Fail",IF(F3>2,"Pass",IF(F3>16,"Fail",IF(F3<16,"Pass")))) -- mrsatroy >=IF(F3<2,"Fail",IF(F3>2,"Pass",IF(F3>16,"Fail",IF(F3<16,"Pass")))) Here's what your formula is "saying" : =IF(AND(F3>2,F3<16),"Pass","Fail") -- Bif...

Autofill Functions....
Can you autofill functions to the right, and have it increase the numbers... for example... in A1 the formula would be A1 =sheet1!$G2 And B1 is B1 =sheet1!$G7 So I want C1 too equal =sheet1!$G12 Ive put the $ in front of the G so it stays the same... but how do i get the number to increase by 5 each time using autofill Cheers One way: A1: =INDEX($G:$G,(COLUMN()-1)*5+2) In article <42b1cf00$1@clear.net.nz>, "The Boondock Saint" <robport@(no-spam)inspire.net.nz> wrote: > Can you autofill functions to the right, and have it increase the numbers... &g...

Hanging outlook express on XP
I have windows XP and whenever I change identities in outlook express, it hangs for about 5 to 7 minutes then works as usual. I found an article to fix this problem with all versions of windows before XP and it includes editing the registry under Identities. See http://support.microsoft.com/?kbid=274017 I went thorough and deleted all the registry items that had the DWORD type and it still ocurred. I've imported them back in now. Any ideas? Nick wrote: > I have windows XP and whenever I change identities in > outlook express, it hangs for about 5 to 7 minutes then > wo...