Jump to content

WinDdePostMsg: Difference between revisions

From EDM2
Created page with "This function is issued by an application to post a message to another application with which it is carrying out a dynamic data exchange conversation with a national language ..."
 
Line 136: Line 136:


==Related Functions==
==Related Functions==
* [[WinDdeInitiate]]]
* [[WinDdeInitiate]]
* [[WinDdeRespond]]
* [[WinDdeRespond]]



Revision as of 17:47, 15 May 2023

This function is issued by an application to post a message to another application with which it is carrying out a dynamic data exchange conversation with a national language conversation context.

Syntax

WinDdePostMsg(hwndTo, hwndFrom, usMsgId, pData, ulOptions)

Parameters

hwndTo (HWND) - input
Window handle of target.
hwndFrom (HWND) - input
Window handle of originator.
usMsgId (ULONG) - input
Message identifier.
Identifies the message to be posted.
The following messages are valid:
       WM_DDE_ACK WM_DDE_ADVISE
       WM_DDE_DATA
       WM_DDE_EXECUTE
       WM_DDE_POKE
       WM_DDE_REQUEST
       WM_DDE_TERMINATE
       WM_DDE_UNADVISE. 
pData (PDDESTRUCT) - input
Pointer to the DDE control structure being passed.
ulOptions (ULONG) - input
Options.
It must be one of the following values:
DDEPM_RETRY
This controls what happens if the message cannot be posted because the destination queue is full.
If this option is set, then message posting is retried at 1-second intervals, until the message is posted successfully. In this case, this function dispatches any messages in the queue of the application issuing this function, by calling the WinPeekMsg and WinDispatchMsg functions in a loop, so that messages sent by other applications can be received. This means that the application can continue to receive DDE messages (or other kinds of messages), while attempting to post DDE messages, thereby preventing deadlock between two applications whose queues are full and who are both attempting to post a message to each other with this option set.
Applications which rely on inspecting messages prior to issuing the WinPeekMsg function can either, use the WinSetHook function and detect the above situation in the invoked hook procedure by testing the MSGF_DDEPOSTMSG value of the msgf parameter, or not use this option, in order to avoid the deadlock situation.
If this option is not set, then this function returns FALSE without retrying.
Note: If the message posting fails for any other reason (for example, an invalid window handle is specified), this function returns FALSE even if this option has been selected.
DDEPM_NOFREE
This option prevents the WinDdePostMsg call from freeing the shared memory block passed in on the pData parameter. If this option is used, the caller is responsible for freeing the memory block at some subsequent time (for example, the same memory block could be used in multiple calls to WinDdePostMsg and then freed once at the end of those calls.
If this option is not specified, the DDE structure will be freed.

Returns

rc (BOOL) - returns
Success indicator.
TRUE
Successful completion
FALSE
Error occurred.

Remarks

To support DDE conversations between applications running in different memory models (16-bit and 32-bit) it is necessary to process all DDE messages in the application window procedure. The use of the WinDispatchMsg function ensures that conversion is performed on memory or segment addresses.

Example Code

This example uses WinDdePostMsg to request a security item from the server once it has received an acknowledgement (via WM_DDEINITIATEACK) to the WinDdeInitiate call. Note the use of the shared memory segment to pass and receive necessary information.

#define INCL_WINDDE             /* Window DDE Functions         */
#define INCL_DOSMEMMGR          /* Memory Manager values        */
#include <os2.h>

BOOL  fSuccess;         /* success indicator                    */
HWND  hwndClient;       /* client window                        */
HWND  hwndServer;       /* server window                        */
CHAR  pszAppName[15]="";/* server application                   */
CHAR  pszTopicName[15]="";/* topic                              */
HWND  hwndTo;           /* target window                        */
HWND  hwndFrom;         /* source window                        */
USHORT  usMsgId;        /* message id                           */
BOOL  fRetry;           /* retry indicator                      */
CONVCONTEXT Context;
PDDESTRUCT  pddeData;   /* DDE structure                        */
MRESULT  mresReply;     /* message return data                  */

case WM_CREATE:
     fSuccess = WinDdeInitiate(hwndClient, pszAppName,
                               pszTopicName, &Context);
     DosAllocSharedMem((PVOID)pddeData,"DDESHAREMEM",
                       sizeof(DDESTRUCT) + 50,
                       PAG_READ | PAG_WRITE | PAG_COMMIT |
                       OBJ_GIVEABLE | OBJ_GETTABLE);

case WM_DDE_INITIATEACK:
     /* issue a request message to DDE partner */
     usMsgId = WM_DDE_REQUEST;

     /* initialize DDE conversation structure */
     pddeData->cbData = sizeof(DDESTRUCT);      /* Total length  */
     pddeData->fsStatus = DDE_FACK;    /* Status - positive ack  */
     pddeData->usFormat = DDEFMT_TEXT;           /* Data format  */
     pddeData->offszItemName = sizeof(DDESTRUCT);/* Offset to item  */

     /* set name of item to 'Security', copying the information to
        the shared memory at the end of pddeData */
     strcpy((BYTE *)pddeData + pddeData->offszItem,
            SZDDESYS_ITEM_SECURITY);

     /* Offset to beginning of data (notice additional offset due
        to item information) */

     pddeData->offabData = sizeof(DDESTRUCT) +
                          strlen(SZDDESYS_ITEM_SECURITY);

     /* set name of item to 'Security', copying the information to
        the shared memory at the end of pddeData */
     strcpy((BYTE *)pddeData + pddeData->offszItem,
            SZDDESYS_ITEM_SECURITY);

     fSuccess = WinDdePostMsg(hwndTo, hwndFrom, usMsgId, pddeData,
                              fRetry);

Definition

#define INCL_WINDDE /* Or use INCL_WIN, INCL_PM, */
#include <os2.h>

HWND          hwndTo;     /*  Window handle of target. */
HWND          hwndFrom;   /*  Window handle of originator. */
ULONG         usMsgId;    /*  Message identifier. */
PDDESTRUCT    pData;      /*  Pointer to the DDE control structure being passed. */
ULONG         ulOptions;  /*  Options. */
BOOL          rc;         /*  Success indicator. */

rc = WinDdePostMsg(hwndTo, hwndFrom, usMsgId, pData, ulOptions);

Related Functions

Related Messages

  • WM_DDE_ACK
  • WM_DDE_ADVISE
  • WM_DDE_DATA
  • WM_DDE_EXECUTE
  • WM_DDE_POKE
  • WM_DDE_REQUEST
  • WM_DDE_TERMINATE
  • WM_DDE_UNADVISE