Re: WriteFile Error

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Scott McPhillips [MVP] (scottmcp_at_mvps.org.nothere)
Date: 04/26/04


Date: Mon, 26 Apr 2004 13:04:09 -0500

Reis wrote:

> Hi guys,
>
> I'm quite new to this area but've managed to get some help from online
> searches
> and created the following program. A bit crude & messy for now. I
> apologise for that.
>
> However, I'm unable to send any bytes using WriteFile. Kept on getting
> error.
>
> Here's the code which I'm having an issue with :
>
> ------------------------------------------------------------------
>
> LPSTR szText;
> UCHAR * cl;
> unsigned long BytesWritten;
> bool bResult;
>
> cl = converted_value_str;
> _tochar sztext((char *)cl);
> DWORD write = sizeof(cl);
> if( ! PurgeComm( h, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR |
> PURGE_RXCLEAR ) )
> {
> printf("\nPurgeComm error!!");
> }
>
> bResult = WriteFile(h, cl, sizeof(cl) + 1, &BytesWritten, NULL);
> DWORD dw1 = GetLastError();
> printf("\nbResult1 = %b", bResult);
> printf("\nGetLastError1 = %u", dw1);
> printf("\nsizeof(cl) = %i", sizeof(cl));
> printf("\nBytesWritten1 = %u", &BytesWritten);
>
> ------------------------------------------------------------------
>
> This is the error which I've got :
>
> Enter a command (y/n) : y
> Please enter a long string: 11
>
> Buf_Len = 2
> GetLastError1 = 87
> sizeof(cl) = 4
> bResult1 = 0
> BytesWritten1 = 9305948
>
> Can someone advise me why I'm having this error and how I can send any
> data to my serial port? Fyi, I'm using COM1. Pls help!! Need this
> urgently for my project.
>
> Thanks in adv!
>
>
> Yours Sincerely,
> GK

It is not clear what you are doing to cl, but it is probably an invalid
address. Also, sizeof(cl) is always going to be 4 because it is a
pointer type. You can't use sizeof to get the size of a string.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: Pi$$ed Off Ticket Staff / Ticket Price Anomalies
    ... There isn't a fares manual tied to every railway booking counter by a ... but you'd probably have to be tied to the counter with a bit of string ... I've done it twice (and now know for sure what the cheapest legal way to get to/from London in the peaks, without buying a peak ticket is). ... But it took me about half an hour painfully plodding through Avantix, and would have taken even longer using a more public online resource. ...
    (uk.railway)
  • Re: String select
    ... > indicates the number of males online and the third number indicates ... > the number of females online. ... > Put the first string and put it in a variable called: ...
    (comp.lang.cpp)
  • Re: String select
    ... > I am making a program which grabs some data of the internet and puts ... > The second string is the number of males online and the third one is ... as similar but you're requiring to split the string at a ' ' chars ...
    (comp.lang.cpp)
  • unit messages
    ... Please advise on the small amount of code b/c I am ... Use of uninitialized value in concatenation or ... Online features of the VxFS File System ...
    (perl.beginners)
  • Re: WriteFile Error
    ... "Reis" wrote in message ... > I'm quite new to this area but've managed to get some help from online ... It is signaling an invalid parameter. ... OVERLAPPED structure and not a NULL pointer. ...
    (microsoft.public.vc.language)