06-05-2021 09:03 AM - edited 06-05-2021 09:04 AM
Hello,
I need to write a simple DDE code in CVI to communicate as a server with another executable. I can't find any examples in the samples directory, there used to be the dde directory under samples but not anymore in CVI 2019. Can anyone point me to the CVI dde server samples?
Particularly I do not understand how to declare the DDE server callback function. In one place the the documentation states that the prototype is
int CallbackFunction (int handle, char *topicName, char *itemName, int xType, int dataFmt, int dataSize, void *dataPtr, void *callbackData);
https://zone.ni.com/reference/en-XX/help/370051AG-01/cvi/libref/cvidde_callback_function/#1708059e
But in another place it says
int (*ddeFuncPtr) (unsigned handle, char *topicName, char *itemName, int xType, int dataFmt, int dataSize, void *dataPtr, void *callbackData);
https://zone.ni.com/reference/en-XX/help/370051AG-01/cvi/libref/cviregisterddeserver/
So when I try to register the DDE server with a reference to the callback function the compiler gives an error "incompatible pointer types" pointing to the code line
int ret = RegisterDDEServer (szApp, CallbackDde, 0);
int CallbackDde (int handle, char *topicName, char *itemName, int xType, int dataFmt, int dataSize, void *dataPtr, void *callbackData)
{
// handle the callback here
return 1;
}
int DdeInit()
{
int ret = RegisterDDEServer (szApp, CallbackDde, 0);
return ret; // zero represents successful execution.
}
Any help will be apprecaited
06-08-2021 09:25 AM - edited 06-08-2021 09:27 AM
The only difference between the two is the int datatype for the handle in one description and the unsigned datatype in the second. "unsigned" really means "unsigned int" while int is synonymous for "signed int".
It's quite possible that this difference was not important in old versions of CVI when it used it's own C compiler, since the most important aspect is the size of the variable which in both cases is a 32-bit int. But with the introduction of the clang backend as C compiler in LabWindows 2013 things might have changed. This compiler backend could have easily added more stringent compatibility checks for function pointers that also flag signed/unsigned parameter mismatches as an error. With DDE being basically an Ultra-legacy technology from Windows 3.x days, it's not surprising that such simple mistakes never have been discovered in recent years. Nobody is using DDE nowadays anymore and that is true since more than 10 years already.