Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get list of COM Ports in Win32 Pin
pandit8411-Oct-11 0:57
pandit8411-Oct-11 0:57 
AnswerRe: How to get list of COM Ports in Win32 Pin
App_11-Oct-11 1:03
App_11-Oct-11 1:03 
AnswerRe: How to get list of COM Ports in Win32 Pin
Madhu Nair11-Oct-11 1:15
Madhu Nair11-Oct-11 1:15 
GeneralRe: How to get list of COM Ports in Win32 Pin
Albert Holguin11-Oct-11 4:23
professionalAlbert Holguin11-Oct-11 4:23 
GeneralRe: How to get list of COM Ports in Win32 Pin
Madhu Nair11-Oct-11 6:44
Madhu Nair11-Oct-11 6:44 
GeneralRe: How to get list of COM Ports in Win32 Pin
Albert Holguin12-Oct-11 5:16
professionalAlbert Holguin12-Oct-11 5:16 
GeneralRe: How to get list of COM Ports in Win32 Pin
Jonathan Davies17-Oct-11 1:22
Jonathan Davies17-Oct-11 1:22 
AnswerRe: CreateFile function Pin
Software_Developer11-Oct-11 3:01
Software_Developer11-Oct-11 3:01 
The CreateFile function creates or opens a file or I/O device.

The following code lists COM Ports in Win32..
C#
#include <iostream>
#include <windows.h>

void main(){
   char port_name[16];
     for (int port_number = 1; port_number < 256; ++port_number)
     {
         port_number < 10 ?
             sprintf(port_name, "COM%d", port_number) :
             sprintf(port_name, "\\\\.\\COM%d", port_number);
         HANDLE hFile = ::CreateFile(port_name,
             GENERIC_READ | GENERIC_WRITE, 0, NULL,
             OPEN_EXISTING, 0, NULL);
         if(hFile != INVALID_HANDLE_VALUE)
             std::cout << port_name << std::endl;
         else
         {
             DWORD err = GetLastError();
             if (err == ERROR_ACCESS_DENIED ||
                 err == ERROR_SHARING_VIOLATION)
                 std::cout << port_name << std::endl;
         }
         CloseHandle(hFile);
     }

}

GeneralRe: CreateFile function Pin
Richard Andrew x6411-Oct-11 11:33
professionalRichard Andrew x6411-Oct-11 11:33 
GeneralRe: CreateFile function Pin
Peter_in_278011-Oct-11 12:06
professionalPeter_in_278011-Oct-11 12:06 
GeneralRe: CreateFile function Pin
Albert Holguin12-Oct-11 5:17
professionalAlbert Holguin12-Oct-11 5:17 
GeneralRe: CreateFile function Pin
Albert Holguin12-Oct-11 5:19
professionalAlbert Holguin12-Oct-11 5:19 
GeneralRe: CreateFile function Pin
Software_Developer12-Oct-11 9:28
Software_Developer12-Oct-11 9:28 
AnswerRe: How to get list of COM Ports in Win32 Pin
Randor 11-Oct-11 17:47
professional Randor 11-Oct-11 17:47 
GeneralRe: How to get list of COM Ports in Win32 Pin
pandit8411-Oct-11 20:18
pandit8411-Oct-11 20:18 
QuestionSaving File as JPEG - Encoding problems Pin
Naniw10-Oct-11 23:02
Naniw10-Oct-11 23:02 
AnswerRe: Saving File as JPEG - Encoding problems Pin
Richard MacCutchan11-Oct-11 0:10
mveRichard MacCutchan11-Oct-11 0:10 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Naniw11-Oct-11 1:08
Naniw11-Oct-11 1:08 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Richard MacCutchan11-Oct-11 5:21
mveRichard MacCutchan11-Oct-11 5:21 
AnswerRe: Saving File as JPEG - Encoding problems Pin
Luc Pattyn11-Oct-11 6:03
sitebuilderLuc Pattyn11-Oct-11 6:03 
GeneralMessage Removed Pin
11-Oct-11 16:29
Naniw11-Oct-11 16:29 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Luc Pattyn11-Oct-11 16:33
sitebuilderLuc Pattyn11-Oct-11 16:33 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Naniw11-Oct-11 16:38
Naniw11-Oct-11 16:38 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Luc Pattyn11-Oct-11 22:33
sitebuilderLuc Pattyn11-Oct-11 22:33 
GeneralRe: Saving File as JPEG - Encoding problems Pin
Naniw11-Oct-11 1:10
Naniw11-Oct-11 1:10 

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.