王朝百科
分享
 
 
 

Dynamic Data Exchange

王朝百科·作者佚名  2010-05-08  
宽屏版  字体: |||超大  

概念Microsoft® Windows®提供了应用程序间数据传输的若干种方法。其中一种就是使用动态数据交换(DDE)协议。DDE协议是一套消息和指示的集合。通过发送消息以及共享内存实现应用程序的数据共享和交换。应用程序可以使用DDE协议实现一次性数据传输以及持续的数据交换(当新数据可用时,应用程序发送更新通知给另一个应用程序)。

Microsoft® Windows® provides several methods for transferring data between applications. One method is to use the dynamic data exchange (DDE) protocol. The DDE protocol is a set of messages and guidelines. It sends messages between applications that share data and uses shared memory to exchange data between applications. Applications can use the DDE protocol for one-time data transfers and for continuous exchanges in which applications send updates to one another as new data becomes available.

示例The following example illustrates how the client initiates a conversation, where both the application and topic are specified.

static BOOL fInInitiate = FALSE;

char *szApplication;

char *szTopic;

atomApplication = *szApplication == 0 ?

NULL : GlobalAddAtom((LPSTR) szApplication);

atomTopic = *szTopic == 0 ?

NULL : GlobalAddAtom((LPSTR) szTopic);

fInInitiate = TRUE;

SendMessage((HWND) HWND_BROADCAST, // broadcasts message

WM_DDE_INITIATE, // initiates conversation

(WPARAM) hwndClientDDE, // handle to client DDE window

MAKELONG(atomApplication, // application-name atom

atomTopic)); // topic-name atom

fInInitiate = FALSE;

if (atomApplication != NULL)

GlobalDeleteAtom(atomApplication);

if (atomTopic != NULL)

GlobalDeleteAtom(atomTopic);

To retrieve an item from the server, the client sends the server a WM_DDE_REQUEST message specifying the item and format to retrieve, as shown in the following example.

if ((atomItem = GlobalAddAtom(szItemName)) != 0)

{

if (!PostMessage(hwndServerDDE,

WM_DDE_REQUEST,

(WPARAM) hwndClientDDE,

PackDDElParam(WM_DDE_REQUEST, CF_TEXT, atomItem)))

{

GlobalDeleteAtom(atomItem);

}

}

if (atomItem == 0)

{

// Handle errors.

}

In this example, the client specifies the clipboard format CF_TEXT as the preferred format for the requested data item.

The receiver (server) of the WM_DDE_REQUEST message typically must delete the item atom, but if the PostMessage call fails, the client must delete the atom.

If the server has access to the requested item and can render it in the requested format, the server copies the item value as a shared memory object and sends the client a WM_DDE_DATA message, as illustrated in the following example.

// Allocate the size of the DDE data header, plus the data: a

// string,<CR><LF><NULL>. The byte for the string's terminating

// null character is counted by DDEDATA.Value[1].

if (!(hData = GlobalAlloc(GMEM_MOVEABLE,

(LONG) sizeof(DDEDATA) + lstrlen(szItemValue) + 2)))

{

return;

}

if (!(lpData = (DDEDATA FAR*) GlobalLock(hData)))

{

GlobalFree(hData);

return;

}

lpData->cfFormat = CF_TEXT;

lstrcpy((LPSTR) lpData->Value, (LPSTR) szItemValue);

// Each line of CF_TEXT data is terminated by CR/LF.

lstrcat((LPSTR) lpData->Value, (LPSTR) "

");

GlobalUnlock(hData);

if ((atomItem = GlobalAddAtom((LPSTR) szItemName)) != 0)

{

lParam = PackDDElParam(WM_DDE_ACK, (UINT) hData, atomItem);

if (!PostMessage(hwndClientDDE,

WM_DDE_DATA,

(WPARAM) hwndServerDDE,

lParam))

{

GlobalFree(hData);

GlobalDeleteAtom(atomItem);

FreeDDElParam(WM_DDE_ACK, lParam);

}

}

if (atomItem == 0)

{

// Handle errors.

}

In this example, the server application allocates a memory object to contain the data item. The data object is initialized as a DDEDATA structure.

The server application then sets the cfFormat member of the structure to CF_TEXT to inform the client application that the data is in text format. The client responds by copying the value of the requested data into the Value member of the DDEDATA structure. After the server has filled the data object, the server unlocks the data and creates a global atom containing the name of the data item.

Finally, the server issues the WM_DDE_DATA message by calling PostMessage. The handle to the data object and the atom containing the item name are packed into the lParam parameter of the message by the PackDDElParam function.

If PostMessage fails, the server must use the FreeDDElParam function to free the packed lParam parameter. The server must also free the packed lParam parameter for the WM_DDE_REQUEST message it received.

If the server cannot satisfy the request, it sends a negative WM_DDE_ACK message to the client, as shown in the following example.

// Negative acknowledgment.

PostMessage(hwndClientDDE,

WM_DDE_ACK,

(WPARAM) hwndServerDDE,

PackDDElParam(WM_DDE_ACK, 0, atomItem));

Upon receiving a WM_DDE_DATA message, the client processes the data-item value as appropriate. Then, if the fAckReq member pointed to in the WM_DDE_DATA message is 1, the client must send the server a positive WM_DDE_ACK message, as shown in the following example.

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);

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
如何用java替换看不见的字符比如零宽空格&#8203;十六进制U+200B
 干货   2023-09-10
网页字号不能单数吗,网页字体大小为什么一般都是偶数
 干货   2023-09-06
java.lang.ArrayIndexOutOfBoundsException: 4096
 干货   2023-09-06
Noto Sans CJK SC字体下载地址
 干货   2023-08-30
window.navigator和navigator的区别是什么?
 干货   2023-08-23
js获取referer、useragent、浏览器语言
 干货   2023-08-23
oscache遇到404时会不会缓存?
 干货   2023-08-23
linux下用rm -rf *删除大量文件太慢怎么解决?
 干货   2023-08-08
刀郎新歌破世界纪录!
 娱乐   2023-08-01
js实现放大缩小页面
 干货   2023-07-31
生成式人工智能服务管理暂行办法
 百态   2023-07-31
英语学习:过去完成时The Past Perfect Tense举例说明
 干货   2023-07-31
Mysql常用sql命令语句整理
 干货   2023-07-30
科学家复活了46000年前的虫子
 探索   2023-07-29
英语学习:过去进行时The Past Continuous Tense举例说明
 干货   2023-07-28
meta name="applicable-device"告知页面适合哪种终端设备:PC端、移动端还是自适应
 干货   2023-07-28
只用css如何实现打字机特效?
 百态   2023-07-15
css怎么实现上下滚动
 干货   2023-06-28
canvas怎么画一个三角形?
 干货   2023-06-28
canvas怎么画一个椭圆形?
 干货   2023-06-28
canvas怎么画一个圆形?
 干货   2023-06-28
canvas怎么画一个正方形?
 干货   2023-06-28
中国河南省郑州市金水区蜘蛛爬虫ip大全
 干货   2023-06-22
javascript简易动态时间代码
 干货   2023-06-20
感谢员工的付出和激励的话怎么说?
 干货   2023-06-18
 
>>返回首页<<
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有