Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the function int32 CVICALLBACK EveryNCallback

In the August  28, 2005 example file ContAcq-IntClk.c  there is the declaration:
 
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNSamplesEventType, uInt32 nSamples, void *callbackData);
 
1.  What is CVICALLBACK?
 
Thanks,
 
Kevin
 
0 Kudos
Message 1 of 9
(13,548 Views)

Hi Kevin,

CVICALLBACK is definend in C:\Program Files\National Instruments\CVI80\include\cvidef.h.  It's basically just __cdecl.

Here's the relevant part:

#define CVICDECL __cdecl

    /* CVICALLBACK is used for typdefs for ptrs to functions. For example:
     *  typedef void (CVICALLBACK * MenuDimmerCallbackPtr)(int menuBar,  int panel);
     */
    #define CVICALLBACK     CVICDECL

Hope this helps!
Megan B.
National Instruments

 

Message 2 of 9
(13,532 Views)
Hi Meagan,
 
I would like to add the following declaration to a simple dialog based Visual C++ program.
 
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNSamplesEventType, uInt32 nSamples, void *callbackData);
 
I have added it as a member function int 32 CprojectDlg::EveryNCallback(...) { ... }.
 
But when I call the function DAQmx RegisterEveryNSamplesEvent (taskHandle, DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback, NULL); in another member function, I get the error:
 
'DAQmx RegisterEveryNSamplesEvent' : cannot convert parameter 5 from 'int32 (TaskHandle,int32,uInt32,void *)' to 'DAQmx RegisterEveryNSamplesEventCallbackPtr'
None of the functions with this name in scope match the target type
 
Do you know what I am missing?
 
Thanks,
 
Kevin T.
 
0 Kudos
Message 3 of 9
(13,522 Views)

Hi Kevin,

The problem is arising because you've added the EveryNCallback as a member function.  It needs to be a static function to match the function signature.  The function signature changes if you make it a member of a class.  The callback registration function expects a C function pointer.  Making the function a static member function will make it match the C function signature.

Hope this helps,
Megan B.
Applications Engineer
National Instruments

Message 4 of 9
(13,505 Views)

Hi Kevin,

I have a problem the same as your asked years ago. I find your question but there are not enough message in your dialog. :manhappy:I wonder if you could provide me some further imformation. thank you so much. Smiley Happy

0 Kudos
Message 5 of 9
(10,747 Views)

Is there anyway to use these particular functions in classes?

0 Kudos
Message 6 of 9
(8,680 Views)

I would be interested in know how to include these function as a member to classes. Couldn't I just pass any correctly cast function as a callbackfunction arguements? This should be possible, correct? What would this look like?

 

Thanks in advance.

 

MK

0 Kudos
Message 7 of 9
(7,792 Views)

@mkellman wrote:

I would be interested in know how to include these function as a member to classes. Couldn't I just pass any correctly cast function as a callbackfunction arguements? This should be possible, correct? What would this look like?

 

Thanks in advance.

 

MK


No! A class member method always contains a hidden pointer to the current object instance as first parameter. (The implicit this-> pointer that the C++ compiler will normally take care of automatically whenever necessary) The callback function doesn't need or even want that, so your class method is not compatible to the callback function signature.

 

Making the function a static member of your class will solve that but you will not have an implicit reference to your object instance inside that. But you can work around that by passing the object reference as callbackData pointer when registering your static callback function, and then the callback function will receive this pointer as an explicit parameter in callbackData.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 9
(7,530 Views)

Thank u so much! I solved the problem because of your information.

0 Kudos
Message 9 of 9
(3,848 Views)