Hi,
I am writing to open a port using this function:
HANDLE hFile = ::CreateFile(pszComName, GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0,0);
// Check if we could open the device
if (hFile == INVALID_HANDLE_VALUE)
{
DWORD hh= ::GetLastError();
error.Format(_T("test - [%d]"),hh);
AfxMessageBox(error,MB_ICONSTOP);
}
I cannot open the port and system error code I receive is 55: ERROR_DEV_NOT_EXIST 55 (0x37) from this list
what can i do to open the port? thanks
EDIT: I Enumerate Ports like this:
for (UINT i=1; i<256; i++)
{
CString sPort;
sPort.Format(_T("COM%d"), i);
HANDLE hPort = ::CreateFile(sPort, GENERIC_READ | GENERIC_WRITE, 0, 0,OPEN_EXISTING,0, 0);
if (hPort == INVALID_HANDLE_VALUE)
{
DWORD dwError = GetLastError();
}
else
{
AfxMessageBox(_T("1 open"));
CloseHandle(hPort);
}
}
I also checked these formats:
sPort1.Format(_T("URT%d"), i);
sPort3.Format(_T("\.\COM%d"), i);
sPort4.Format(_T("\\.\COM%d"), i);
and sPort5.Format(_T("\COM%d"), i);
but I couldnt find any.