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 8465711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:07:43+00:00 2026-06-10T15:07:43+00:00

I have a WiFi Listener registered as a callback (pointer function) with a fixed

  • 0

I have a WiFi Listener registered as a callback (pointer function) with a fixed 3rd party interface. I used a static member of my function to register the callback function and then that static function calls a nonstatic member through a static cast. The main problem is that I cannot touch the resulting char * buff with any members of my class nor can I even change an int flag that is also a member of my class. All result in runtime access violations. What can I do? Please see some of my code below. Other problems are described after the code.

void *pt2Object;

TextWiFiCommunication::TextWiFiCommunication()
{
    networkDeviceListen.rawCallback = ReceiveMessage_thunkB;
    /* some other initializing */
}

int TextWiFiCommunication::ReceiveMessage_thunkB(int eventType, NETWORK_DEVICE    *networkDevice)
{
     if (eventType == TCP_CLIENT_DATA_READY)
            static_cast<TextWiFiCommunication *>(pt2Object)->ReceiveMessageB(eventType,networkDevice);
     return 1;
}
int TextWiFiCommunication::ReceiveMessageB(int eventType, NETWORK_DEVICE *networkDevice)
{
     unsigned char outputBuffer[8];
// function from an API that reads the WiFi socket for incoming data
     TCP_readData(networkDevice, (char *)outputBuffer, 0, 8);
     std::string tempString((char *)outputBuffer);
     tempString.erase(tempString.size()-8,8);  //funny thing happens the outputBuffer is double in size and have no idea why
     if (tempString.compare("facereco") == 0)
         cmdflag = 1;
     return 1;
 }

So I can’t change the variable cmdflag without an access violation during runtime. I can’t declare outputBuffer as a class member because nothing gets written to it so I have to do it within the function. I can’t copy the outputBuffer to a string type member of my class. The debugger shows me strlen.asm code. No idea why. How can I get around this? I seem to be imprisoned in this function ReceiveMessageB.

Thanks in advance!

Some other bizzare issues include: Even though I call a buffer size of 8. When I take outputBuffer and initialize a string with it, the string has a size of 16.

  • 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-06-10T15:07:44+00:00Added an answer on June 10, 2026 at 3:07 pm

    You are likely getting an access violation because p2tObject does not point to a valid object but to garbage. When is p2tObject initialized? To what does it point?

    For this to work, your code should look something like this:

    ...
    TextWifiCommunication twc;
    p2tObject = reinterpret_cast<void*>(&twc);
    ...
    

    Regarding the string error, TCP_readData is not likely to null-terminate the character array you give it. A C-string ends at the first ‘\0’ (null) character. When you convert the C-string to a std::string, the std::string copies bytes from the C-string pointer until it finds the null terminator. In your case, it happens to find it after 16 characters.

    To read up to 8 character from a TCP byte stream, the buffer should be 9 characters long and all the bytes of the buffer should be initialized to ‘\0’:

    ...
    unsigned char outputBuffer[9] = { 0 };
    // function from an API that reads the WiFi socket for incoming data
    TCP_readData(networkDevice, (char *)outputBuffer, 0, 8);
    std::string tempString((char *)outputBuffer);
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple network interface(Like WIFI,LAN,LTE dougle).I am sending http request using apache httpclient
I have no WIFI, I have no cable connection available. Is there hope for
I have a Wifi iPad and this compass actually knows the direction of north.
I have an open wifi hotspot and a web server and I'm trying to
I have to open an NSStream to a wifi access point that has only
I have an iPhone application that send datas via wifi on my mac. I
I have an old T-Mobile MDA. It has WiFi, Windows Mobile and a camera.
I'd like to have a settings bundle behavior similar to the iPhone WiFi settings.
Let's say I have 3 or more peers connected to the same WiFi Access
Hi: Is it generally possible to have Wifi Tethering turned on (creating a Hotspot)

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.