function pointers and callback functions ?
I don't normally use function pointers or callback functions, but I have
a function that uses a function pointer to read the value of a sensor
attached to a board that reads analog inputs of the sensor. Now, I have
attempted to convert it to MFC, but I have not yet been successful.
Now, I was reading on the Internet that using callbacks in MFC is not
recommended, but I was wondering what would I use if not a callback.
What I want to do is to capture the input anytime the control is moved
and to display numerical values in a text box or maybe even use a
progress bar. But the program could be doing something else at the same
time and I was wondering how to capture it so that it is displayed at
the time the control is moved. The code I have below is what I have so
far even though I am fairly sure it won't work as I have it at the
moment. It is a conversion of a console program and the only thing that
does not work is the sensor input function. Any help would be appreciated.
Z.K.
void CInterfaceKitTestDlg::OnTest()
{
// TODO: Add your control notification handler code here
long sernum, version;
char *deviceptr;
int result = 0;
int numOutputs = 0;
CPhidgetInterfaceKitHandle IFK = 0;
CString property;
CPhidgetInterfaceKit_create(&IFK);
result = CPhidget_open(IFK, -1);
if (result)
{
MessageBox("No InterfaceKit found...");
return;
}
CPhidget_getDeviceType(IFK, &deviceptr);
CPhidget_getSerialNumber(IFK, &sernum);
CPhidget_getDeviceVersion(IFK, &version);
property.Format("Device Type: %s\nVersion: %15d\n SerialNumber:
%7d",deviceptr,version, sernum);
MessageBox(property);
CPhidgetInterfaceKit_getNumOutputs(IFK,&numOutputs);
property.Format("Number of Outputs: %d",numOutputs);
MessageBox(property);
//CPhidgetInterfaceKit_setOutputState(IFK, 7, true);
CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK ,
IFK_InputChangeHandler, NULL);
for(int i=0;i<10;i++)
{
CPhidgetInterfaceKit_setOutputState(IFK, 7, true);
Sleep(500);
CPhidgetInterfaceKit_setOutputState(IFK, 7, false);
Sleep(500);
}
CPhidgetInterfaceKit_set_OnSensorChange_Handler(IFK ,
IFK_InputChangeHandler, NULL);
//if((MessageBox("LED is on")) != 0)
// CPhidgetInterfaceKit_setOutputState(IFK, 7, false);
return;
}
int CALLBACK IFK_SensorChangeHandler(CPhidgetInterfaceKitHandle IFK,
void *userptr, int Index, int Value)
{
CString temp;
temp.Format("Input %d is %d\n", Index, Value);
AfxMessageBox(temp);
return 0;
}