Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ calling a non static function from a static function
    primarykey
    data
    text
    <p>I'm experiencing an access violation error when I try to call non static function.</p> <p>my <code>.h</code> file looks like this.</p> <pre><code>class World { public: World(); virtual ~World(); static void CALLBACK DispatchCallback( SIMCONNECT_RECV *pData, DWORD cbData, void *pContext ); void Process(SIMCONNECT_RECV *pData, DWORD cbData); virtual void frameEvent(); virtual void init(); }; </code></pre> <p>Now in my .cpp file the init() function I call a function that return data to my callback function.</p> <pre><code>SimConnect_CallDispatch(hSimConnect, DispatchCallback, NULL); </code></pre> <p>Which sends data to the <code>DisPatchCallback</code> function.</p> <p>In this function the following code resides:</p> <pre><code>void CALLBACK World::DispatchCallback( SIMCONNECT_RECV *pData, DWORD cbData, void *pContext) { World *pThis = reinterpret_cast&lt;World*&gt;(pContext); pThis-&gt;Process(pData, cbData); } </code></pre> <p>this function is a static function which creates a World object to call the Process function.</p> <p>This works but it break on the line where it wants to access the frameEvent function.</p> <pre><code>void World::Process(SIMCONNECT_RECV *pData, DWORD cbData) { HRESULT hr; switch(pData-&gt;dwID) { case SIMCONNECT_RECV_ID_EVENT_FRAME: frameEvent(); //it breaks here frameEvent is a non static function break; } } </code></pre> <blockquote> <p>Access violation reading location 0x00000000.</p> </blockquote> <p>Can someone point me to the right direction as to solve this issue.?</p> <p>If you wonder I'm writing a plugin for Microsoft Flight Simulator X.</p> <p>I'm trying to implement <code>simconnect.h</code> in a oo way. Msdn shows an example that I'm trying to implement.</p> <pre><code>class CName { void Dispatch(); static void DispatchCallback( SIMCONNECT_RECV *pData, DWORD cbData, void *pContext ); void Process(SIMCONNECT_RECV *pData, DWORD cbData); HANDLE hSimConnect; // use SimConnect_Open to set this value. }; void CName::Dispatch() { ::SimConnect_Dispatch(hSimConnect, &amp;CName;::DispatchCallback, this); } // static function void CName::DispatchCallback( SIMCONNECT_RECV *pData, DWORD cbData, void *pContext) { CName *pThis = reinterpret_cast&lt;CName*&gt;(pContext); pThis-&gt;Process(pData, cbData); } void CName::Process(SIMCONNECT_RECV *pData, DWORD cbData) { // do processing of SimConnect data } </code></pre> <p>I hope I gave enough information.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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