我写了一个active,在add method
假设我现在要返回一个BYTE形的,
(0x01 0x02 0x88 0x99 ...)
怎么样返回这样的一个16进制
我想可以作为一串字符串,但我在add method时,
在return type 中不知道 返回哪一个
要怎么做呢,
谢谢了

解决方案 »

  1.   

    看你的客户对象而定:变体形、安全数组、BYTE* 都行
      

  2.   

    返回值是DWORD的(HRESULT)。要取值只能传参数进去。
    通过参数取出来。
      

  3.   

    写错了一点CString ReadStr;
    ReadStr = SerialPort.Read();
    SerialPort.PortClose();

    if((ReadStr.GetLength() > 7) && (ReadStr[6] == 0x08))return  .......;
    else
    return  .......;
    这我要读出ReadStr[7]以后的值,我知道ReadStr[7]的值是0x88,以及ReadStr[8]以后和
      

  4.   

    但我在add method时,
    在return type 中,只有那几种类型
    我要用哪一个
      

  5.   

    char * GetStr()
    {
    CString ReadStr;
    ReadStr = SerialPort.Read();
    SerialPort.PortClose();return  ReadStr.Mid(7);//或者为6,8
    }
      

  6.   

    这样不行呀
    在但我在add method时,
    在return type 中,没有char*
     (还是我不知道 :( )
    还有
    error C2109: subscript requires array or pointer type我是菜鸟呵
      

  7.   

    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;
    }
    不知道这样行不行!
      

  8.   

    先谢谢大家 不是BYTE *pbStr;就是一个 CString  ReadStr
    它里面 的东西 是:0x88 0x99 0x2C 0x1C 0xAA
     我要怎么把它读出,而在active中add method,没有什么*呀 :)
    在调试active时返回值,要么是10进制的,要么就是乱码
    我不知道,还请大家指教
      

  9.   

    好象CString有一个Format方法,可以将数字以指定形式输出,记不大清了
    到MSDN中找Format吧
      

  10.   

    CString::GetAt
    TCHAR GetAt( int nIndex ) const;Return ValueA TCHAR containing the character at the specified position in the string.ParametersnIndexZero-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.ResYou 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.ExampleThe 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 ChartSee Also   CString::GetAt, CString::GetLength, CString::operator []
      

  11.   

    CString::operator [ ] 
    TCHAR operator []( int nIndex ) const;ParametersnIndexZero-based index of a character in the string.ResYou 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.ExampleThe following example demonstrates the use of CString::operator [ ].// example for CString::operator [ ]
    CString s( "abc" );
    ASSERT( s[1] == 'b' );CString Overview |  Class Members |  Hierarchy ChartSee Also   CString::GetAt, CString::SetAt
      

  12.   

    现在我的CString ReadStr是这样的:0x00 0x25 0x89 0x2C 0xAA 0x1C我只能得到25什么数字的,我要得到这个数组:00 25 89 2C AA 1C
    我要怎么做,这是给别人做二次开发用的
    如果我的这个函数没有返回值,我可以设置一个成员变量去得到它们吗?
    二次开发直接调用这个成员变量就可以了吗?请大家说说一说呵
    谢谢了
      

  13.   

    其实没有必要这样
    别人在做二次开发时,只是拿你的值和0xAA比较,
    在机器中它们是相等170的呀
    你只返回170就可以了我想是这样的
      

  14.   

    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