Re: WriteFile Error
From: Scott McPhillips [MVP] (scottmcp_at_mvps.org.nothere)
Date: 04/26/04
- Next message: Charles R: "VC++ Memory debug window"
- Previous message: Scott McPhillips [MVP]: "Re: Structure sizes"
- In reply to: Reis: "WriteFile Error"
- Messages sorted by: [ date ] [ thread ]
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]
- Next message: Charles R: "VC++ Memory debug window"
- Previous message: Scott McPhillips [MVP]: "Re: Structure sizes"
- In reply to: Reis: "WriteFile Error"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|