I am trying to communicate with a windows application using the antiquated DDE interface, I know this interface has been overtaken by ActiveX but the application i am talking to (ZEMAX – optical modelling software) doesn't implement it.
I have managed to post requests to the application and receive responses, all successfully. However one of the functions that I need to implement requires passing a pointer to a data structure to the application, I have the c code equivalent but no idea how to implement it. I have been using the supplied dde.llb but can find no documentation for it.
This is the 'c' equivalent of the code i need to implement, can anyone help me with this???:
int PostArrayTraceMessage(char *szBuffer, DDERAYDATA *RD)
{
ATOM aItem;
HGLOBAL hPokeData;
DDEPOKE * lpPokeData;
long numbytes;
int numrays;
if (RD[0].opd > 4)
{
/* NSC Rays */
numrays = (int)RD[0].opd - 5;
}
else
{
/* sequential rays */
numrays = RD[0].error;
}
/* point to where the data is */
rdpGRD = RD;
ngNumRays = numrays;
numbytes = (1+numrays)*sizeof(DDERAYDATA);
hPokeData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, (LONG) sizeof(DDEPOKE) + numbytes);
lpPokeData = (DDEPOKE *) GlobalLock(hPokeData);
lpPokeData->fRelease = TRUE;
lpPokeData->cfFormat = CF_TEXT;
memcpy(lpPokeData->Value, RD, numbytes);
/* clear the buffers */
szGlobalBuffer[0] = '\0';
szBuffer[0] = '\0';
aItem = GlobalAddAtom("RayArrayData");
GlobalUnlock(hPokeData);
if (!PostMessage(hwndServer, WM_DDE_POKE, (WPARAM) hwndClient, PackDDElParam(WM_DDE_POKE, (UINT) hPokeData, aItem)))
{
MessageBox (hwndClient, "Cannot communicate with ZEMAX!", "Hello?", MB_ICONEXCLAMATION | MB_OK);
GlobalDeleteAtom(aItem);
GlobalFree(hPokeData);
return -1;
}
GlobalDeleteAtom(aItem);
WaitForData(hwndClient);
strcpy(szBuffer, szGlobalBuffer);
/* clear the pointer */
rdpGRD = NULL;
if (GotData) return 0;
else return -1;
}
Thanks for your help.
Regards,
Tom