Can someone help me with this com port enumarator
-
ok, im using this com port enumarator: http://www.codeproject.com/system/listports.asp and im haveing trouble using it to list the ports in a list box using MFC. Can someone send me a simple example doing that with this, using VC++ 6 preferably? thank you, This stupid thing is frustrating me beyond belief lol --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
-
ok, im using this com port enumarator: http://www.codeproject.com/system/listports.asp and im haveing trouble using it to list the ports in a list box using MFC. Can someone send me a simple example doing that with this, using VC++ 6 preferably? thank you, This stupid thing is frustrating me beyond belief lol --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
In stdafx.h put: #include #include In EnumerSer.h put: #ifndef __AFXTEMPL_H__ #pragma message("EnumerateSerialPorts function requires afxtempl.h in your PCH") #endif void EnumerateSerialPorts(CUIntArray& ports); ... Demo.cpp: #include "stdafx.h" #include #include "EnumerSer.h" void main() { CUIntArray ports; EnumerateSerialPorts(ports); _tprintf(_T("The following serial ports are installed on this machine\n")); for (int i=0; i
-
In stdafx.h put: #include #include In EnumerSer.h put: #ifndef __AFXTEMPL_H__ #pragma message("EnumerateSerialPorts function requires afxtempl.h in your PCH") #endif void EnumerateSerialPorts(CUIntArray& ports); ... Demo.cpp: #include "stdafx.h" #include #include "EnumerSer.h" void main() { CUIntArray ports; EnumerateSerialPorts(ports); _tprintf(_T("The following serial ports are installed on this machine\n")); for (int i=0; i
Sorry I forget: ///////////////////////////// Implementation ////////////////////////////////// void EnumerateSerialPorts(CUIntArray& ports) { //Make sure we clear out any elements which may already be in the array ports.RemoveAll(); //Determine what OS we are running on OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); BOOL bGetVer = GetVersionEx(&osvi); //On NT use the QueryDosDevice API if (bGetVer && (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)) { //Use QueryDosDevice to look for all devices of the form COMx. This is a better //solution as it means that no ports have to be opened at all. TCHAR szDevices[65535]; DWORD dwChars = QueryDosDevice(NULL, szDevices, 65535); if (dwChars) { int i=0; for (;;) { //Get the current device name TCHAR* pszCurrentDevice = &szDevices[i]; //If it looks like "COMX" then //add it to the array which will be returned int nLen = _tcslen(pszCurrentDevice); if (nLen > 3 && _tcsnicmp(pszCurrentDevice, _T("COM"), 3) == 0) { //Work out the port number int nPort = _ttoi(&pszCurrentDevice[3]); ports.Add(nPort); } // Go to next NULL character while(szDevices[i] != _T('\0')) i++; // Bump pointer to the next string i++; // The list is double-NULL terminated, so if the character is // now NULL, we're at the end if (szDevices[i] == _T('\0')) break; } } else TRACE(_T("Failed in call to QueryDosDevice, GetLastError:%d\n"), GetLastError()); } else { //On 95/98 open up each port to determine their existence //Up to 255 COM ports are supported so we iterate through all of them seeing //if we can open them or if we fail to open them, get an access denied or general error error. //Both of these cases indicate that there is a COM port at that number. for (UINT i=1; i<256; i++) { //Form the Raw device name CString sPort; sPort.Format(_T("\\\\.\\COM%d"), i); //Try to open the port BOOL bSuccess = FALSE; HANDLE hPort = ::CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); if (hPort == INVALID_HANDLE_VALUE) { DWORD dwError = GetLastError(); //Check to see if the error was because some other app had the port open or a general failure
-
In stdafx.h put: #include #include In EnumerSer.h put: #ifndef __AFXTEMPL_H__ #pragma message("EnumerateSerialPorts function requires afxtempl.h in your PCH") #endif void EnumerateSerialPorts(CUIntArray& ports); ... Demo.cpp: #include "stdafx.h" #include #include "EnumerSer.h" void main() { CUIntArray ports; EnumerateSerialPorts(ports); _tprintf(_T("The following serial ports are installed on this machine\n")); for (int i=0; i
umm u have a few includes there with nothing after them, what do i include? ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
-
umm u have a few includes there with nothing after them, what do i include? ty --------------------- And Like The Wind Our Hero Vanishes Off Into The Distance...
-
Sorry I did not check "Do not treat <'s as HTML tags." In Stdafx.h should be: #include #include In Demo.cpp missed #include
im about to shove a stick of dynomite into my comps serial port, lol i get this error: cannot convert parameter 1 from 'unsigned int' to 'const char *' for this line of code: m_port.AddString(ports.ElementAt(i)); how do i fix that? thank you
-
im about to shove a stick of dynomite into my comps serial port, lol i get this error: cannot convert parameter 1 from 'unsigned int' to 'const char *' for this line of code: m_port.AddString(ports.ElementAt(i)); how do i fix that? thank you
-
You have to convert this integer into string such as: char str[7]; sprintf(str, "COM%d", ports.ElementAt(i)); m_port.AddString(str);
o ok thank you