|
|
|
|
|
|
s********z 发帖数: 5411 | 1 我在把下面这段code改成qt,是不是需要删掉 “ifdef _MSC_VER”阿?
这里为什么要用”#ifdef _MSC_VER“ “#endif”阿? 只有是visual studio
compiler情
况下,这个code才能用?
多谢
xx.h
#ifdef _MSC_VER
int ReadString(CString& strMsg, char chStop);
int ReadString(CString& strMsg);
int WriteString(CString strCmd);
#endif
xx.cpp
#ifdef _MSC_VER
int CCamlinkSerial::ReadString(CString& strMsg, char chStop)
{
if (!m_bOpened) { return 0; }
char chCur = chStop + 1; // ensures that ucCur and ucStop are
different to begin with
strMsg = "";
int t = 0;
while ((chCur != chStop) && (t < m_nTimeout)) {
if (ReadCommChar(chCur)) {
if (chCur != chStop) { strMsg += chCur; }
} else {
break;
}
}
if (chCur != chStop) { return -1; }
return 1;
}
int CCamlinkSerial::ReadString(CString& strMsg)
{
if (!m_bOpened) { return 0; }
char chCur = '\0';
bool bValidRead = true;
strMsg = "";
int lTotal = 0;
while (bValidRead) {
if (ReadCommChar(chCur)) {
strMsg += chCur;
lTotal += 1;
} else {
bValidRead = false;
}
}
if (!bValidRead) { return -1; } // timeout
return lTotal;
}
int CCamlinkSerial::WriteString(CString strCmd)
{
int nLen = strCmd.GetLength();
int nBytes = WriteData((char*)(strCmd.GetBuffer(nLen)), nLen);
strCmd.ReleaseBuffer();
return nBytes;
}
#endif | d****p 发帖数: 685 | 2 CString is ATL stuff so it is only for MSVC platform.
If you want cross-platform code, change it to std::string
【在 s********z 的大作中提到】 : 我在把下面这段code改成qt,是不是需要删掉 “ifdef _MSC_VER”阿? : 这里为什么要用”#ifdef _MSC_VER“ “#endif”阿? 只有是visual studio : compiler情 : 况下,这个code才能用? : 多谢 : xx.h : #ifdef _MSC_VER : int ReadString(CString& strMsg, char chStop); : int ReadString(CString& strMsg); : int WriteString(CString strCmd);
| s********z 发帖数: 5411 | 3 i c.
thanks.
I will just change it to qstring, since I am using qt. thnaks.
【在 d****p 的大作中提到】 : CString is ATL stuff so it is only for MSVC platform. : If you want cross-platform code, change it to std::string
|
|
|
|
|
|
|