Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing the member of a class that is part of a WiFi listener callback member function
    text
    copied!<p>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.</p> <pre><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&lt;TextWiFiCommunication *&gt;(pt2Object)-&gt;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; } </code></pre> <p>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. </p> <p>Thanks in advance!</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload