Click here to Skip to main content
15,850,445 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Matrix! HELP!!!! Pin
Anonymous28-Jun-03 10:29
Anonymous28-Jun-03 10:29 
GeneralGetting the rect of the text in a Static Pin
Tommy2k27-Jun-03 12:21
Tommy2k27-Jun-03 12:21 
GeneralRe: Getting the rect of the text in a Static Pin
basementman27-Jun-03 12:41
basementman27-Jun-03 12:41 
GeneralRe: Getting the rect of the text in a Static Pin
Tommy2k27-Jun-03 12:58
Tommy2k27-Jun-03 12:58 
GeneralRe: Getting the rect of the text in a Static Pin
John M. Drescher27-Jun-03 13:33
John M. Drescher27-Jun-03 13:33 
GeneralRe: Getting the rect of the text in a Static Pin
Tommy2k27-Jun-03 13:38
Tommy2k27-Jun-03 13:38 
GeneralRe: Getting the rect of the text in a Static Pin
valikac27-Jun-03 12:42
valikac27-Jun-03 12:42 
GeneralRead a line from a file HANDLE Pin
Blueapples27-Jun-03 12:14
Blueapples27-Jun-03 12:14 
Hi. I'm doing a project where I open a COM port with CreateFile() to do some device accessing. I have writing working fine, but now I'm trying to figure out how to read one line of text from the COM port. The function fgets() would be nice, but it's for FILE structures and I have a HANDLE pointer to the open file.

Is their either
a) a function to create a FILE structure from a HANDLE, or
b) an existing function that does what I want?

I have created a function that I thought would read a file, but it crashes in the Kernel on my call to ReadFile(). Besides, I feel stupid writing such a basic function that I think must be already part of the Win API

I post in this forum because I actually am doing this in an MFC program, and I'm open to MFC solutions.

Thanks in advance.
<br />
/* My function... */<br />
LPSTR ReadLine( HANDLE hFile )<br />
{<br />
    char            c;<br />
    LPSTR            szBuffer;<br />
    unsigned int    pos = 0;<br />
    BOOL            fContinue = true, fCR = false;<br />
    LPDWORD            lpBytesRead = 0;<br />
<br />
    szBuffer = (LPSTR)malloc( 256 );<br />
<br />
    if( szBuffer != NULL )<br />
    {<br />
        while( ReadFile( hFile, &c, 1, lpBytesRead, NULL ) != 0 && fContinue )   ////// ** crashes here ** /////<br />
        {<br />
            switch( c )<br />
            {<br />
            case 0x0A:<br />
                fCR = true;<br />
                break;<br />
            case 0x0D:<br />
                if( fCR )<br />
                {<br />
                    fContinue = false;<br />
                    fCR = false;<br />
                }<br />
                break;<br />
            default:<br />
                fCR = false;<br />
                szBuffer[pos] = c;<br />
                pos ++;<br />
                if( pos == sizeof( szBuffer ) ) <br />
                    fContinue = false;<br />
            }<br />
        }<br />
<br />
        szBuffer[pos] = 0;<br />
    }<br />
<br />
    return szBuffer;<br />
}

GeneralRe: Read a line from a file HANDLE Pin
basementman27-Jun-03 12:43
basementman27-Jun-03 12:43 
GeneralRe: Read a line from a file HANDLE Pin
Blueapples27-Jun-03 13:00
Blueapples27-Jun-03 13:00 
GeneralRe: Read a line from a file HANDLE Pin
Toni7827-Jun-03 13:15
Toni7827-Jun-03 13:15 
GeneralRe: Read a line from a file HANDLE Pin
od@ananzi.co.za15-Sep-03 10:33
od@ananzi.co.za15-Sep-03 10:33 
QuestionMaking an MFC program? Pin
DaveE9th27-Jun-03 11:50
DaveE9th27-Jun-03 11:50 
AnswerRe: Making an MFC program? Pin
Toni7827-Jun-03 13:18
Toni7827-Jun-03 13:18 
GeneralRe: Making an MFC program? Pin
DaveE9th27-Jun-03 20:24
DaveE9th27-Jun-03 20:24 
GeneralRe: Making an MFC program? Pin
Toni7828-Jun-03 10:26
Toni7828-Jun-03 10:26 
QuestionRecommended reading on MFC? Pin
DaveE9th27-Jun-03 9:25
DaveE9th27-Jun-03 9:25 
AnswerRe: Recommended reading on MFC? Pin
Matt Newman27-Jun-03 9:29
Matt Newman27-Jun-03 9:29 
AnswerRe: Recommended reading on MFC? Pin
NormDroid27-Jun-03 10:51
professionalNormDroid27-Jun-03 10:51 
AnswerRe: Recommended reading on MFC? Pin
Cambalindo27-Jun-03 12:50
Cambalindo27-Jun-03 12:50 
QuestionMFC going by wayside? Pin
DaveE9th27-Jun-03 9:03
DaveE9th27-Jun-03 9:03 
AnswerRe: MFC going by wayside? Pin
keegan27-Jun-03 9:16
keegan27-Jun-03 9:16 
GeneralRe: MFC going by wayside? Pin
basementman27-Jun-03 10:44
basementman27-Jun-03 10:44 
AnswerRe: MFC going by wayside? Pin
Matt Newman27-Jun-03 9:32
Matt Newman27-Jun-03 9:32 
AnswerRe: MFC going by wayside? Pin
Nemanja Trifunovic27-Jun-03 9:36
Nemanja Trifunovic27-Jun-03 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.