Hello,
Why is it that DdeConnect is failing on Unicode but yet working on ANSI?
1) Open Excel and enter some dummy data
2) Create a sample code to read value from Excel via DDE
3) ANSI = Success, Unicode = FAIL
Sample code below. I am getting DDE Connection Failed everytime.
WCHAR szApp[] = L"Excel";
WCHAR szTopic[] = L"C:\\Test.xlsx";
char szItem1[] = "R1C1"; char szDesc1[] = "Current Value: ";
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
if (iReturn!=DMLERR_NO_ERROR)
{
printf("DDE Initialization Failed: 0x%04x\n", iReturn);
Sleep(1500);
return 0;
}
HSZ hszApp, hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandle(idInst, (LPCWSTR)szApp, 0);
hszTopic = DdeCreateStringHandle(idInst, (LPCWSTR)szTopic, 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
printf("DDE Connection Failed.\n");
Sleep(100); DdeUninitialize(idInst);
return 0;
}