Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 926565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:42:16+00:00 2026-05-15T19:42:16+00:00

I have a callback function which has the parameter const unsigned char *pData .

  • 0

I have a callback function which has the parameter const unsigned char *pData. everytime I hit the callback function I need to store the pData value into my local unsigned char* variable. Is there any function to copy the data?


Edit: Here is a code sample:

void Callbackfun(int x, const unsigned char* pData, const UINT cbData) {
    switch(x) {
    case 0:
        // ptr is a global variable of structure containg name and number
        ptr.name = (unsigned char*)pData;
        break;
    case 1:
        ptr.number = (unsigned char*)pData;
        break;
    }
}

now every time this function is called i want to store the pData values in my local structure (as shown by ptr.name).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:42:17+00:00Added an answer on May 15, 2026 at 7:42 pm

    In your callback function, you will have to allocate local memory for your “data”. That way you can retain it when the calling function leaves scope. If you know the length of the data, and the length is consistent you have two options. Dynamic allocation, or allocate on the stack. Code example is untested.

    Here’s the dynamic allocation and copy.

     unsigned char* localData = new unsigned char[42];
     memcpy( localData, pData, 42 );
    

    Here’s the stack allocated version

     unsigned char localData[42];
     memcpy( &localData, pData, 42 );
    

    I’m assuming you’re not passing string data since you’re using unsigned char. Since you’re only dealing with a pointer you’ll have to know the size of the buffer for either allocation.

    If you do not have a constant data length, then you’ll need to pass that as a second parameter to your callback function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a js function which has, until now, always been the callback for
I have a lua animation variable which has a callback function used in an
I have Java application which sends pointer to function (callback) to some native dll
I have the following code, in which Boost.Local uses a function callback to load
I have a callback function which is bound to a boost::asio::deadline_timer . Now the
DatePicker has an internal function, _adjustDate() , which I'd like to add a callback
I have a callback function that checks my login details are correct - If
I want to have one callback function after actions are done, I'm trying something
I have this static callback function in MyClass, and I try to call another
I have a jQuery plugin I am trying to add a callback function for.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.