Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
1.67/5 (5 votes)
See more:
How to listen port event..?
In which language it is feasible..?(c/c++/java)

OP Update to Ques:
How to generate list of current active ports on the system..?
In which programming language it is feasible..? (c/c++/java).
Posted
Updated 24-Dec-10 19:25pm
v2
Comments
Dave Kreskowiak 24-Dec-10 1:18am    
What are you talking about? "Port event"?? Are you talking about how you listen on a TCP/IP port and communicate with it?
fjdiewornncalwe 24-Dec-10 12:19pm    
The answer to your question as it is written would be : "Yes"... But that isn't very helpful to you because it isn't complete, which is also the state of your question. Please expand your question with more information as to what you are trying to do so that we can help you along your way. Cheers.

1 solution

Best approach to get active ports from hardware oriented language like c, c++. in c we can make code snippet like

Try QueryDosDevice, e.g.

TCHAR szDevices[65535];
unsigned long dwChars = QueryDosDevice(NULL, szDevices, 65535);
TCHAR *ptr = szDevices;

while (dwChars)
{
int port;
if (sscanf(ptr, "COM%d", &port) == 1)
{
// Add to list of com ports
}
TCHAR *temp_ptr = strchr(ptr, 0);
dwChars -= (DWORD)((temp_ptr - ptr) / sizeof(TCHAR) + 1);
ptr = temp_ptr + 1;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900