Question and Answer Database FAQ1193D.txt Setting comm port configuration programmatically under Win95 Category :Miscellaneous Platform :All Product :All 32 bit Question: How can I set the comm ports configuration programmatically under Windows 95? Answer: The following example demonstrates setting the comm port under Windows95. Example: procedure TForm1.Button1Click(Sender: TObject); var CommPort : string; hCommFile : THandle; Buffer : PCommConfig; size : DWORD; begin CommPort := 'COM1'; {Open the comm port} hCommFile := CreateFile(PChar(CommPort), GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if hCommFile=INVALID_HANDLE_VALUE then begin ShowMessage('Unable to open '+ CommPort); exit; end; {Allocate a temporary buffer} GetMem(Buffer, sizeof(TCommConfig)); {Get the size of the CommConfig structure} {as it may be different than documented} size := 0; GetCommConfig(hCommFile, Buffer^, size); {Free the temporary buffer} FreeMem(Buffer, sizeof(TCommConfig)); {Allocate the CommConfig structure} GetMem(Buffer, size); GetCommConfig(hCommFile, Buffer^, size); {Change the baud rate} Buffer^.dcb.BaudRate := 1200; {Set the comm port to the new configuration} SetCommConfig(hCommFile, Buffer^, size); {Free the buffer} FreeMem(Buffer, size); {Close the comm port} CloseHandle(hCommFile); end; 7/16/98 4:31:28 PM
Last Modified: 01-SEP-99