The best way to achieve that when programing in C is by using the NI-DAQ function named Config_DAQ_Event_Message. You can get a good idea about how that function works by going to NI-DAQ help and searching for that function.
Hope this helps.
Filipe Altoe
Application Engineer
National Instruments