开发者

DDEConnect failing on Unicode

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 = DdeCreateStringH开发者_C百科andle(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;
    }


Did you DDEInitialize in Unicode mode? the DDEInitialize and DDEConnect modes have to match. So if you haven't defined UNICODE, you'd have to explicitly call DDEInitializeW before specifying a DDEConnect in CP_WINUNICODE mode. That's how I read the docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜