如何在DdeCallback函数中实现返回代码
How to implement return codes in DdeCallback function
编写DdeCallback
函数的正确方法是什么?更确切地说,我说的是返回代码。
来自官方文件:
返回值取决于事务类。了解更多信息有关返回值的信息,请参阅个别交易类型
例如,我的应用程序需要自己处理XTYP_ADVDATA
消息,而忽略其他消息。
因此,根据XTYP_ADVDATA
的文档,如果我处理了以下消息,我需要返回DDE_FACK
:
如果DDE回调函数处理此问题,则应返回DDE_FACK事务DDE_FBUSY(如果太忙而无法处理该事务),或DDE_FNOTPROCESSED(如果拒绝此事务)
但其他信息呢?在其他情况下,我应该返回什么?
//初始化
DWORD id_inst = 0;
UINT res = DdeInitializeA(
&id_inst,
(PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY,
0 // Reserved; must be set to zero
);
// XTYP_ADVSTART
HDDEDATA data = DdeClientTransaction(
NULL, // The beginning of the data the client must pass to the server. This parameter is required only if the wType parameter is XTYP_EXECUTE or XTYP_POKE. Otherwise, this parameter should be NULL
0, // The length, in bytes, of the data pointed to by the pData parameter
conv,
item,
CF_TEXT,
XTYP_ADVSTART,
30000, // The maximum amount of time, in milliseconds, that the client will wait for a response from the server application in a synchronous transaction
NULL // A pointer to a variable that receives the result of the transaction. An application that does not check the result can use NULL for this value
);
HDDEDATA CALLBACK DdeCallback(
UINT uType, // The transaction type
UINT uFmt, // The format atom of the data sent from the server
HCONV hconv, // A handle to the conversation
HSZ hsz1, // A handle to the topic name
HSZ hsz2, // A handle to the item name
HDDEDATA hdata, // A handle to the data associated with the topic name and item name pair
DWORD dwData1, // Not used
DWORD dwData2) // Not used
{
switch (uType)
{
case XTYP_ADVDATA:
DWORD data_size = DdeGetData(hdata, NULL, 0, 0);
std::unique_ptr<char[]> buf(new char[data_size]);
DdeGetData(
hdata,
(BYTE *)buf.get(),
data_size,
0 // An offset within the DDE object. Data is copied from the object beginning at this offset
);
std::cout << "Data received: " << buf.get() << std::endl;
return (HDDEDATA)DDE_FACK;
}
return /* ??? */;
}
在调用DdeInitialize()
时,您只会收到您注册的消息类型(或者更准确地说,您不会过滤掉)。如果您只注册接收(或不忽略)XTYP_ADVDATA
消息,那么您将只收到这些消息,并且不必担心处理其他消息类型。任何未过滤掉的消息类型都必须根据每个消息类型的规则在回调中正确处理。
阅读DdeInitialize()
的文档,注意其afCmd
参数的说明。另请阅读有关DDE基本概念的文档,特别是描述初始化和回调函数的部分。
相关文章:
- 为什么我们要为avl树实现返回一个指向节点的指针,而不是void函数
- 如何实现 Front() 方法以返回模板化双向链表C++的第一个元素?
- 使用 std::forward_list 返回错误的队列实现
- 如何实现返回受保护结构的私有函数
- 私有在函数定义/实现的返回值范围内是什么意思 (c++)?
- 当我在网格/面中实现索引时,为什么它会返回OpenGl错误
- PfCreateInterface返回错误120(未实现)
- 实现一个函数,该函数将字符串作为输入并返回一个新字符串,辅音字母不替换为 "!"
- 如何检查 CNG Windows API 是否返回符合 FIPS 的算法实现
- 使 c++11 Dijkstra 实现返回最短路径
- 如何在没有参数的情况下实现返回双向链表大小的函数?int size() const.
- 返回原始值的QuickSort实现
- C++ 线程函数指针实现返回错误无效使用非静态成员函数
- C++ 中的 MD5 实现返回不正确的摘要
- WString 实现 - 返回以 null 结尾,我走的路是否正确
- C++跳过列表实现-返回的值已损坏,内存泄漏
- 为什么我的合并排序实现返回奇怪的数字
- 如何实现返回二进制数据的简单C函数的单元测试
- 如何正确实现返回ref的运算符重载,以便轻松删除它们的工件
- 如何在DdeCallback函数中实现返回代码