DdeInitialize(&m_inst, exitFunction, MF_CALLBACKS|MF_CONV|MF_ERRORS|
MF_HSZ_INFO|MF_LINKS|MF_POSTMSGS|MF_SENDMSGS,0);
with the same m_inst as the Program1. So some conflict occures and DDE
data halts for the both programs. Even if I execute Program2 while
running Program1 with no Application1&Application2 running (hence no
DDE data coming at all). Program2 halts when executing
DdeCreateStringHandle(m_inst,"EXDDE",CP_WINANSI);
Both Program1 and Program2 use the same piece of code for getting DDE
data except for
m_Sservice = DdeCreateStringHandle(m_inst,"EXDDE",CP_WINANSI)
changed for
m_Sservice = DdeCreateStringHandle(m_inst,"EXDDE2",CP_WINANSI)
dde.h:
#define MAXSIZE 64000
#pragma once
#include <stdio.h>
#include "windows.h"
#include "stdio.h"
#include "ddeml.h"
#pragma warning(disable : 4996)
class CExDDE
{
HSZ m_Sservice;
public:
static DWORD m_inst;
static char m_ItemData1[256];
static char m_ItemData2[256];
static void getVal(void * val, unsigned char ** pos, int size);
public:
CExDDE();
~CExDDE();
};
----------------------------------------------------------------
dde.cpp :
#include "stdafx.h"
#include "dde.h"
HDDEDATA CALLBACK exitFunction(UINT uType,UINT uFmt, HCONV hconv,HSZ
hsz1,HSZ hsz2,HDDEDATA hdata,DWORD dwData1,DWORD dwData2);
extern HWND g_hWndMain;
CExDDE::CExDDE()
{
m_inst = 0;
DdeInitialize(&m_inst, exitFunction,MF_CALLBACKS|MF_CONV|MF_ERRORS|
MF_HSZ_INFO|MF_LINKS|MF_POSTMSGS|MF_SENDMSGS,0);
m_Sservice = DdeCreateStringHandle(m_inst,"EXDDE",CP_WINANSI);
DdeNameService(m_inst,m_Sservice,0,DNS_REGISTER);
//printf("reg=%d\n",DdeGetLastError(m_inst));
}
CExDDE::~CExDDE()
{
DdeNameService(m_inst,m_Sservice,0,DNS_UNREGISTER);
DdeFreeStringHandle(m_inst,m_Sservice);
DdeUninitialize(m_inst);
}
DWORD CExDDE::m_inst = 0;
char CExDDE::m_ItemData1[256];
char CExDDE::m_ItemData2[256];
void CExDDE::getVal(void * val, unsigned char ** pos, int size)
{
memcpy(val, (*pos), size);
(*pos) += size;
}
struct SDdeQueItem
{
unsigned char data[MAXSIZE];
int size;
char sTopic[256];
char sCells[256];
} ;
HDDEDATA CALLBACK exitFunction(UINT uType,UINT uFmt, HCONV
hconv,HSZ hsz1,HSZ hsz2,HDDEDATA hdata,DWORD dwData1,DWORD dwData2)
// .
{char forTopic[256] = "", forItem[256] = "", forData[256] = "",
forWho[256] = "";
switch (uType & XCLASS_MASK)
{case XCLASS_BOOL : // .
switch (uType)
......................................................................
......................................................................
------------------------------------------------------------------------------------------------
main.cpp :
#include "dde.h"
..................
CExDDE * pDde;
..................
pDde = new CExDDE();
What should I change so that both Program1 and Program2 could ran
simultaneously?
Thank you for your help!