Click here to Skip to main content
15,913,685 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCan anyone help me understand this code better? Pin
BrockVnm18-May-04 9:57
BrockVnm18-May-04 9:57 
AnswerRe: Can anyone help me understand this code better? Pin
Christian Graus18-May-04 11:29
protectorChristian Graus18-May-04 11:29 
GeneralRe: Can anyone help me understand this code better? Pin
Ryan Binns18-May-04 18:39
Ryan Binns18-May-04 18:39 
Generali need to get the chat text of msm messanger Pin
Member 96792618-May-04 9:28
Member 96792618-May-04 9:28 
GeneralRe: i need to get the chat text of msm messanger Pin
Member 42102519-May-04 10:35
Member 42102519-May-04 10:35 
GeneralSerial Port Communication in WinXP (or NT/2000) Pin
AnotherProgrammer18-May-04 8:52
AnotherProgrammer18-May-04 8:52 
GeneralRe: Serial Port Communication in WinXP (or NT/2000) Pin
Antti Keskinen18-May-04 9:07
Antti Keskinen18-May-04 9:07 
GeneralRe: Serial Port Communication in WinXP (or NT/2000) Pin
AnotherProgrammer18-May-04 9:56
AnotherProgrammer18-May-04 9:56 
Thanks for the reply.

So I have to basically rewrite a portion of my code to comply with using CreateFile and whatnot. This is where it gets confusing for me.

From the link you provided:

----
/* A sample program to illustrate setting up a serial port. */

#include <windows.h>

int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM2";

hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);

if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}

// Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.

fSuccess = GetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}

// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.

dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit

fSuccess = SetCommState(hCom, &dcb);

if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}

printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
return (0);
}
-----

This sample program confuses me a great deal. Why does the main program need parameters (I was under the impression that it was called by the OS and executing began there -- thus, there are no inputs... and to further complicate things, neither of those parameters are used in the program!). Also, what are these data types that are declared - DCB, HANDLE, and BOOL (capital bool? C++ is case-sensitive, no?)?

I guess I'm just overall sketchy on how to use CreateFile and those data types (HANDLE seems to be the port's data type, I guess), since I thought using a class that already did these things was the way to go and so didn't take the time to familiarize myself with them. Could you clarify some of these questions for me? I really appreciate the help.

Thank you.
GeneralRe: Serial Port Communication in WinXP (or NT/2000) Pin
Antti Keskinen18-May-04 20:40
Antti Keskinen18-May-04 20:40 
GeneralRe: Serial Port Communication in WinXP (or NT/2000) Pin
closecall18-May-04 15:07
closecall18-May-04 15:07 
GeneralRe: Serial Port Communication in WinXP (or NT/2000) Pin
valikac18-May-04 16:51
valikac18-May-04 16:51 
GeneralHelp needed urgent! Pin
ben218-May-04 7:13
ben218-May-04 7:13 
GeneralRe: Help needed urgent! Pin
David Crow18-May-04 7:17
David Crow18-May-04 7:17 
GeneralRe: Help needed urgent! Pin
ben218-May-04 7:32
ben218-May-04 7:32 
GeneralRe: Help needed urgent! Pin
David Crow18-May-04 7:45
David Crow18-May-04 7:45 
Questionhow to change window icon Pin
vividtang18-May-04 7:01
vividtang18-May-04 7:01 
AnswerRe: how to change window icon Pin
David Crow18-May-04 7:15
David Crow18-May-04 7:15 
GeneralRe: how to change window icon Pin
vividtang18-May-04 7:19
vividtang18-May-04 7:19 
GeneralRe: how to change window icon Pin
David Crow18-May-04 7:21
David Crow18-May-04 7:21 
AnswerRe: how to change window icon Pin
sps-itsec4618-May-04 8:20
sps-itsec4618-May-04 8:20 
GeneralRe: how to change window icon Pin
vividtang18-May-04 8:27
vividtang18-May-04 8:27 
Generalabout path Pin
vividtang18-May-04 6:56
vividtang18-May-04 6:56 
GeneralRe: about path Pin
David Crow18-May-04 7:09
David Crow18-May-04 7:09 
GeneralRe: about path Pin
Maximilien18-May-04 7:15
Maximilien18-May-04 7:15 
Generalabout SetWindowText() and change window default style Pin
vividtang18-May-04 6:44
vividtang18-May-04 6:44 

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.