描述:
我写了一个active,在add method
假设我现在要返回一个BYTE形的,
(0x01 0x02 0x88 0x99 ...)
怎么样返回这样的一个16进制
我想可以作为一串字符串,但我在add method时,
在return type 中不知道 返回哪一个
要怎么做呢,
谢谢了
解决方案1:
呵呵,UP!
解决方案2: CString ReadStr = "12345";
CString mstr;
CString out = "";
int x = ReadStr.GetLength();
for( int i = 0; i < x; ++i )
{
mstr.Format(" 0X%02X ",ReadStr.GetAt(i));
out += mstr;
}
结果是 输出 out 为 0x31 0x32 0x33 0x34 0x35
帮你顶!
解决方案4: 其实没有必要这样
别人在做二次开发时,只是拿你的值和0xAA比较,
在机器中它们是相等170的呀
你只返回170就可以了
我想是这样的
up
CString::operator [ ]
TCHAR operator []( int nIndex ) const;
Parameters
nIndex
Zero-based index of a character in the string.
Remarks
You can think of a CString object as an array of characters. The overloaded subscript ([]) operator returns a single character specified by the zero-based index in nIndex. This operator is a convenient substitute for the GetAt member function.
Important You can use the subscript ([]) operator to get the value of a character in a CString, but you cannot use it to change the value of a character in a CString.
Example
The following example demonstrates the use of CString::operator [ ].
// example for CString::operator [ ]
CString s( "abc" );
ASSERT( s[1] == 'b' );
CString Overview | Class Members | Hierarchy Chart
See Also CString::GetAt, CString::SetAt
CString::GetAt
TCHAR GetAt( int nIndex ) const;
Return Value
A TCHAR containing the character at the specified position in the string.
Parameters
nIndex
Zero-based index of the character in the CString object. The nIndex parameter must be greater than or equal to 0 and less than the value returned by GetLength. The Debug version of the Microsoft Foundation Class Library validates the bounds of nIndex; the Release version does not.
Remarks
You can think of a CString object as an array of characters. The GetAt member function returns a single character specified by an index number. The overloaded subscript ([]) operator is a convenient alias for GetAt.
Example
The following example demonstrates the use of CString::GetAt.
// example for CString::GetAt
CString s( "abcdef" );
ASSERT( s.GetAt(2) == 'c' );
CString Overview | Class Members | Hierarchy Chart
See Also CString::GetAt, CString::GetLength, CString::operator []
好象CString有一个Format方法,可以将数字以指定形式输出,记不大清了
到MSDN中找Format吧
up
BYTE * CTsView::GetStr()
{
CString ReadStr=_T("ajsdfasjoerewjrekw");
BYTE *pbStr;
//ReadStr = SerialPort.Read();
//SerialPort.PortClose();
UINT nLen=ReadStr.GetLength();
pbStr=new BYTE[nLen-7];
memcpy((void *)pbStr,(void *)(LPCTSTR)ReadStr.Mid(7),nLen-7);
return pbStr;
}
不知道这样行不行!
char * GetStr()
{
CString ReadStr;
ReadStr = SerialPort.Read();
SerialPort.PortClose();
return ReadStr.Mid(7);//或者为6,8
}
返回值是DWORD的(HRESULT)。
要取值只能传参数进去。
通过参数取出来。
看你的客户对象而定:变体形、安全数组、BYTE* 都行