Quantcast
Channel: LabWindows/CVI topics
Viewing all articles
Browse latest Browse all 5339

Passing an object to a callback

$
0
0

I would like to have access to a C++ object from within my timer callback function without making the object global.  Example below:

 

in 'MyClass.h'

 

class MyClass

{

public:

     MyClass();

     ~MyClass();

 

     void MyClassFunction();

 

}

 

in 'MyClass.cpp'

 

MyClass::MyClass()

{

    //do some constructor stuff here

}

MyClass::~MyClass()

{

    //Some destructor stuff here

}

 

void MyClassFunction()

{

    //some function stuff here

}

 

in 'Display.cpp'

 

 

//This is called periodically at a fixed time interval

int CVICALLBACK displayTick (int panel, int control, int my_event,
                         void *callbackData, int eventData1, int eventData2)
{

    //I want access to an instantiation of MyClass here, without making the instantiation global....

    MyClass_object.MyClassFunction(); //do some stuff using my object here

}

 

There's probably a simple solution to this, but I've never done it.

 


Viewing all articles
Browse latest Browse all 5339

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>