Microsoft KB Archive/45701

From BetaArchive Wiki

Using Shared Memory Between Applications

PSS ID Number: Q45701 Article last modified on 11-05-1993

2.03 2.10 3.00 MS-DOS

The information in this article applies to:
- Microsoft Windows Software Development Kit for Windows version 3.0


When using DDE to transfer data between two applications, you must always remember that all shared memory objects in DDE are to be treated as read only by the recipients. This is stated on Page 118 of the “Microsoft Windows Software Development Kit Windows Extensions” manual, in the DDE section. These guidelines were created to ensure that your application will work correctly when using expanded memory, since the global memory objects of the application will be bank switched out when the application is no longer the current task. The following steps should be applied to transferring data between applications where Application A and Application B are two applications communicating via DDE.


Application A

hGlobalA = GlobalAlloc(..,GMEM_DDESHARE,….) hPointerA = GlobalLock(hGlobalA) Write information to Memory specified by hPointerA GlobalUnlock(hGlobalA) PostMessage(…,hGlobalA,…)

Application B

hGlobalB = GlobalAlloc(..,GMEM_DDESHARE,…) hPointerB = GlobalLock(hGlobalB) hPointerA = GlobalLock(hGlobalA) Copy memory in Global Area for application A into Global memory are for application B. Modify item in memory area specified by hPointerB. GlobalUnlock(hGlobalB) GlobalUnlock(hGlobalA) GlobalFree(hGlobalA) PostMessage(…,hGlobalA,…)

The main point of this example is to illustrate the necessity for copying the data in the Global Area created by A into a Global Area created by B, then modifying the information in Global Area B and passing the handle to B’s Global Memory area back to A (rather than assuming that the handle to A’s global memory will reflect the changes made by Application B, which is not the case). You cannot pass a Global Memory handle to Application B, modify the memory using that Global Handle, and then have A use the same handle to retrieve the updated information. The global object created by Application A and copied to B’s banks is not copied back to A’s banks. A still has the original object (not modified) residing in its banks.

Additional reference words: 3.00 KBCategory: KBSubcategory: UsrDdeMemmgt Copyright Microsoft Corporation 1993.