dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Need help with DDE

  1. #1
    Join Date
    Sep 2017
    Posts
    20

    Need help with DDE

    Hi, I'm an intermediate C++ programmer.

    I've been trying to write a small program that receives stock quotes from ThinkOrSwim's ThinkDesktop. ThinkDestop uses Microsoft's DDE to transfer stock quotes to other programs.


    I'm using the Microsoft tutorial called "Using Dynamic Data Exchange". So far I've gotten to the "Transfer Single Item" section, and my program receives the WM_DDE_DATA message. Now I believe I should be able to extract the stock quote, but I don't know how. I just don't think I understand Microsoft's example.

    Can someone explain or even write some code?


    Thanks
    Last edited by JohnBartle; August 13th, 2018 at 10:42 PM. Reason: Not actually fully resolved

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,482

    Re: Need help with DDE

    If you're got a WM_DDE_DATA message then you're at this code in the example

    Code:
    UnpackDDElParam(WM_DDE_DATA, lParam, (PUINT) &hData, 
        (PUINT) &atomItem); 
    
    if (!(lpDDEData = (DDEDATA FAR*) GlobalLock(hData)) 
            || (lpDDEData->cfFormat != CF_TEXT)) 
    { 
        PostMessage(hwndServerDDE, 
            WM_DDE_ACK, 
            (WPARAM) hwndClientDDE, 
            PackDDElParam(WM_DDE_ACK, 0, atomItem)); // Negative ACK. 
    } 
     
    // Copy data from lpDDEData here. 
     
    if (lpDDEData->fAckReq) 
    { 
        PostMessage(hwndServerDDE, 
            WM_DDE_ACK, 
            (WPARAM) hwndClientDDE, 
            PackDDElParam(WM_DDE_ACK, 0x8000, 
                atomItem)); // Positive ACK 
    } 
     
    bRelease = lpDDEData->fRelease; 
    GlobalUnlock(hData); 
    if (bRelease) 
        GlobalFree(hData);

    The comment // Copy data from lpDDEData here.

    shows where you need to extract the data.

    lpDDeData is a pointer to the data structure as shown at https://docs.microsoft.com/en-us/win...ns-dde-ddedata

    so lpDDeData->Value is the actual data you want as a BYTE array. So you can copy the data from there to where you want it in your program. Depending upon the format of the data etc etc will depend upon how many bytes you need to copy.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.8.9)

  3. #3
    Join Date
    Sep 2017
    Posts
    20

    Re: Need help with DDE

    Oh thanks man. It looks like I need to use the UnpackDDElParam() function. I was originally just trying to extract the DDEDATA and it's Value member directly through the main WindowProcedure's lParam.

    Thanks I'll check it out.

  4. #4
    Join Date
    Sep 2017
    Posts
    20

    Re: Need help with DDE

    Took your advice, and it works. Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)