locked
Read data from unsigned charater * in c++ RRS feed

  • Question

  • Hello Guys

    How Can I read data from memory buffer ??

    Example

    unsigned char* totalResponse = NULL;

    unsigned long totalResponseSize = 0;

    const unsigned long RECVRESPONSE_TEMPBUFFERSIZE = 10 * 1024;
            unsigned long readBufferSize = RECVRESPONSE_TEMPBUFFERSIZE;
            // Temporary buffer that stores response comes from the printer
            unsigned char readBuffer[RECVRESPONSE_TEMPBUFFERSIZE] = { 0 };

    do {

                // sleep to get the printer ready to respond
               // Receive reponse from the printer
                readBufferSize = RECVRESPONSE_TEMPBUFFERSIZE;
                readResult = pu3Read(hSDK, readBuffer, &readBufferSize, &needContinue);
                l = readResult;
                if (CNMPU3_ERR_SUCCESS == readResult) {
                    unsigned char* tmp = NULL;
                    tmp = totalResponse;
                    totalResponse = (unsigned char*)malloc(sizeof(char) * (readBufferSize + totalResponseSize));

                    if (NULL == totalResponse)
                        break;
                    if (NULL != tmp)
                    {
                        memcpy_s(totalResponse, readBufferSize + totalResponseSize, tmp, totalResponseSize);
                        free(tmp);
                    }
                    // Store
                    memcpy_s(totalResponse + totalResponseSize, readBufferSize, readBuffer, readBufferSize);
                    totalResponseSize += readBufferSize;
                }
                else if (CNMPU3_ERR_NOCONTENT == readResult) {
                    Sleep(1000); // sleep to get the printer ready to respond
                    continue;
                }
                else {
                    break;
                }

            } while (needContinue == CNMPU3_TRUE);

    so How to get a value from *totalresponse ??

    Pls Sugest me

    Thanks for Help !!!

     

    • Moved by CoolDadTx Wednesday, October 14, 2020 2:32 PM C++ related
    Wednesday, October 14, 2020 2:00 PM

All replies

  • This is the C# forum. We do not answer C++ questions here. Please post your question in the new Microsoft Q&A forums.

    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, October 14, 2020 2:32 PM