vc error C2664: “CreateFileA”: 不能将参数 1 从“WCHAR [260]”转换为“LPCSTR”
BOOLCSerial::OpenCommPort(DWORDdwPort){if(m_hCom!=INVALID_HANDLE_VALUE){returnFALSE;}...
BOOL CSerial::OpenCommPort(DWORD dwPort){ if(m_hCom != INVALID_HANDLE_VALUE) { return FALSE; }
strcpy(m_szComm, "\\\\.\\COM"); char sz[5]; ltoa(dwPort, sz, 10);
strcat(m_szComm, sz);//
WCHAR wstr[MAX_PATH]; memset(wstr, 0, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, m_szComm, strlen(m_szComm), wstr, sizeof(m_szComm));
m_hCom = ::CreateFile(wstr, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(m_hCom == INVALID_HANDLE_VALUE) { return FALSE; }
DWORD dwId; m_bExit = FALSE; m_hThread = ::CreateThread(NULL, 0, SerialThreadProc, this, 0, &dwId); if(m_hThread == NULL) { ::CloseHandle(m_hCom); m_hCom = INVALID_HANDLE_VALUE; // return FALSE; }
// here to return TRUE;} 展开
strcpy(m_szComm, "\\\\.\\COM"); char sz[5]; ltoa(dwPort, sz, 10);
strcat(m_szComm, sz);//
WCHAR wstr[MAX_PATH]; memset(wstr, 0, MAX_PATH); MultiByteToWideChar(CP_ACP, 0, m_szComm, strlen(m_szComm), wstr, sizeof(m_szComm));
m_hCom = ::CreateFile(wstr, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(m_hCom == INVALID_HANDLE_VALUE) { return FALSE; }
DWORD dwId; m_bExit = FALSE; m_hThread = ::CreateThread(NULL, 0, SerialThreadProc, this, 0, &dwId); if(m_hThread == NULL) { ::CloseHandle(m_hCom); m_hCom = INVALID_HANDLE_VALUE; // return FALSE; }
// here to return TRUE;} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询