Jump to content

WinDdePostMsg: Difference between revisions

From EDM2
Ak120 (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
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.  
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==
==Syntax==
Line 5: Line 5:


==Parameters==
==Parameters==
;hwndTo (HWND) - input
;hwndTo (HWND) - input:Window handle of target.
:Window handle of target.  
;hwndFrom (HWND) - input:Window handle of originator.
 
;usMsgId (ULONG) - input:Message identifier.
;hwndFrom (HWND) - input
:Window handle of originator.  
 
;usMsgId (ULONG) - input
:Message identifier.
 
:Identifies the message to be posted.
:Identifies the message to be posted.
:The following messages are valid:
:The following messages are valid:
 
::WM_DDE_ACK WM_DDE_ADVISE
        WM_DDE_ACK WM_DDE_ADVISE
::WM_DDE_DATA
        WM_DDE_DATA
::WM_DDE_EXECUTE
        WM_DDE_EXECUTE
::WM_DDE_POKE
        WM_DDE_POKE
::WM_DDE_REQUEST
        WM_DDE_REQUEST
::WM_DDE_TERMINATE
        WM_DDE_TERMINATE
::WM_DDE_UNADVISE.
        WM_DDE_UNADVISE.  
;pData (PDDESTRUCT) - input:Pointer to the DDE control structure being passed.
 
;ulOptions (ULONG) - input:Options.
;pData (PDDESTRUCT) - input
:It must be one of the following values:
:Pointer to the DDE control structure being passed.  
:;DDEPM_RETRY:This controls what happens if the message cannot be posted because the destination queue is full.
 
;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.
::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.
::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.
::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.  
::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.
:;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.
::If this option is not specified, the DDE structure will be freed.


==Returns==
==Returns==
; rc (BOOL) - returns
;rc (BOOL) - returns:Success indicator.
 
:;TRUE:Successful completion  
:Success indicator.
:;FALSE:Error occurred.
;TRUE
:Successful completion  
;FALSE
:Error occurred.


==Remarks==
==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.  
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==
==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.  
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.
<pre>
<pre>
#define INCL_WINDDE            /* Window DDE Functions        */
#define INCL_WINDDE            /* Window DDE Functions        */
Line 147: Line 121:
* WM_DDE_REQUEST
* WM_DDE_REQUEST
* WM_DDE_TERMINATE
* WM_DDE_TERMINATE
* WM_DDE_UNADVISE  
* WM_DDE_UNADVISE


[[Category:Win]]
[[Category:Win]]

Latest revision as of 14:50, 16 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