Je vous écris pour ouvrir un port en utilisant cette fonction:ERROR_DEV_NOT_EXIST lorsque :: CreateFile dans C++ MFC?
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);
}
Je ne peux pas ouvrir le code d'erreur port et le système que je reçois est 55: ERROR_DEV_NOT_EXIST 55 (0x37) de cette list
Que puis-je faire pour ouvrir le port? grâce
EDIT: Je Énumérer Ports comme ceci:
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);
}
}
J'ai aussi vérifié les formats suivants:
sPort1.Format (_T ("URT% d"), i);
sPort3.Format (_T ("\. \ COM% d"), i);
sPort4.Format (_T ("\\. \ COM% d"), i);
et sPort5.Format (_T ("\ COM% d"), i);
mais je ne pouvais pas trouver.
C'est un deux-points, pas un point-virgule ... –
Correction - merci. – Shaihi