我把图片读入到char*指针内,但想把char*指针内容读到CString,普通文本数据的办法不可行!请问应该怎么读? 

解决方案 »

  1.   

    "char内容不是文本" 是什么意思?
      

  2.   

    CString就是用来储存文本的,不是文本不要用它。
      

  3.   

    不是文字信息,例如“CSDN论坛”之类的,而是图片信息,图片信息本身很多符号搞到不能把char数组直接拷到
    CSTRING上,不知道这个问题怎么解决。
      

  4.   

    循环把char *数据插入CString, 当然我只是想当然!
      

  5.   

    因为我是一个报文信息,一块内存读了图片信息之后,我在这块内存之前还要写入一些其他信息。除了CString
    用得方便外,其他的还不怎么好用。
      

  6.   


    根据 lz 的描述,这个是不错的方法不知 lz 到底看上了 CString 哪点说说看,给个示例
      

  7.   

    呵呵,主要是使用起来方便,如果Find等操作,我可以确认到要内存里面要查的东西在哪里,但是如果只是指针
    ,或者数组的话就比较麻烦。
      

  8.   

    但是如果只是指针 
    ,或者数组的话就比较麻烦//for循环而已
      

  9.   

    CString只能用于管理字符串,不是文本不要用它;至于查找,用指针更方便啊。
      

  10.   

    难道LZ认为CString里的查找不是用遍历的?
      

  11.   

    CString处理文本确实方便,但不要迷信。CString都有源码的,看看就知道它如何实现的了……
      

  12.   

    也是遍历吧  只不过CString效率应该更好一些,我现在用指针内存实现了,看来只有这个办法。
      

  13.   

    先把数据做一个base64编码吧。然后再存储到CString中
    LONG CEncoder::encodeBase64A(const BYTE *in_buf, int in_len, LPCSTR sep, char* out_buf, DWORD *out_len)
    {
        int div, i;
        const BYTE *d = in_buf;
        int bytes = (in_len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 0;
        DWORD needed;
        LPSTR ptr;    TRACE("bytes is %d, pad bytes is %d\n", bytes, pad_bytes);
        needed = bytes + pad_bytes + 1;
        needed += (needed / 64 + 1) * strlen(sep);    if (needed > *out_len)
        {
            *out_len = needed;
            return ERROR_INSUFFICIENT_BUFFER;
        }
        else
            *out_len = needed;    /* Three bytes of input give 4 chars of output */
        div = in_len / 3;    ptr = out_buf;
        i = 0;
        while (div > 0)
        {
            if (i && i % 64 == 0)
            {
                strcpy(ptr, sep);
                ptr += strlen(sep);
            }
            /* first char is the first 6 bits of the first byte*/
            *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
            /* second char is the last 2 bits of the first byte and the first 4
             * bits of the second byte */
            *ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
            /* third char is the last 4 bits of the second byte and the first 2
             * bits of the third byte */
            *ptr++ = b64[ ((d[1] << 2) & 0x3c) | (d[2] >> 6 & 0x03)];
            /* fourth char is the remaining 6 bits of the third byte */
            *ptr++ = b64[   d[2]       & 0x3f];
            i += 4;
            d += 3;
            div--;
        }    switch(pad_bytes)
        {
            case 1:
                /* first char is the first 6 bits of the first byte*/
                *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
                /* second char is the last 2 bits of the first byte and the first 4
                 * bits of the second byte */
                *ptr++ = b64[ ((d[0] << 4) & 0x30) | (d[1] >> 4 & 0x0f)];
                /* third char is the last 4 bits of the second byte padded with
                 * two zeroes */
                *ptr++ = b64[ ((d[1] << 2) & 0x3c) ];
                /* fourth char is a = to indicate one byte of padding */
                *ptr++ = '=';
                break;
            case 2:
                /* first char is the first 6 bits of the first byte*/
                *ptr++ = b64[ ( d[0] >> 2) & 0x3f ];
                /* second char is the last 2 bits of the first byte padded with
                 * four zeroes*/
                *ptr++ = b64[ ((d[0] << 4) & 0x30)];
                /* third char is = to indicate padding */
                *ptr++ = '=';
                /* fourth char is = to indicate padding */
                *ptr++ = '=';
                break;
        }
        strcpy(ptr, sep);    return ERROR_SUCCESS;
    }LONG CEncoder::decodeBase64Block(const char *in_buf, int in_len, const char **nextBlock, PBYTE out_buf, DWORD *out_len)
     {
         int len = in_len, i;
         const char *d = in_buf;
         int  ip0, ip1, ip2, ip3;
     
         if (len < 4)
             return ERROR_INVALID_DATA;
     
         i = 0;
         if (d[2] == '=')
         {
             if ((ip0 = decodeBase64Byte(d[0])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip1 = decodeBase64Byte(d[1])) > 63)
                 return ERROR_INVALID_DATA;
     
             if (out_buf)
                 out_buf[i] = (ip0 << 2) | (ip1 >> 4);
             i++;
         }
         else if (d[3] == '=')
         {
             if ((ip0 = decodeBase64Byte(d[0])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip1 = decodeBase64Byte(d[1])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip2 = decodeBase64Byte(d[2])) > 63)
                 return ERROR_INVALID_DATA;
     
             if (out_buf)
             {
                 out_buf[i + 0] = (ip0 << 2) | (ip1 >> 4);
                 out_buf[i + 1] = (ip1 << 4) | (ip2 >> 2);
             }
             i += 2;
         }
         else
         {
             if ((ip0 = decodeBase64Byte(d[0])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip1 = decodeBase64Byte(d[1])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip2 = decodeBase64Byte(d[2])) > 63)
                 return ERROR_INVALID_DATA;
             if ((ip3 = decodeBase64Byte(d[3])) > 63)
                 return ERROR_INVALID_DATA;
     
             if (out_buf)
             {
                 out_buf[i + 0] = (ip0 << 2) | (ip1 >> 4);
                 out_buf[i + 1] = (ip1 << 4) | (ip2 >> 2);
                 out_buf[i + 2] = (ip2 << 6) |  ip3;
             }
             i += 3;
         }
         if (len >= 6 && d[4] == '\r' && d[5] == '\n')
             *nextBlock = d + 6;
         else if (len >= 5 && d[4] == '\n')
             *nextBlock = d + 5;
         else if (len >= 4 && d[4])
             *nextBlock = d + 4;
         else
             *nextBlock = NULL;
         *out_len = i;
         return ERROR_SUCCESS;
     }BYTE inline CEncoder::decodeBase64Byte(char c)
    {
    BYTE ret;

    if (c >= 'A' && c <= 'Z')
    ret = c - 'A';
    else if (c >= 'a' && c <= 'z')
    ret = c - 'a' + 26;
    else if (c >= '0' && c <= '9')
    ret = c - '0' + 52;
    else if (c == '+')
    ret = 62;
    else if (c == '/')
    ret = 63;
    else
    ret = 64;
    return ret;
    }