gpt4 book ai didi

C 向 DDE 服务器发送命令的示例

转载 作者:行者123 更新时间:2023-11-30 17:34:32 24 4
gpt4 key购买 nike

复制代码时遇到两个问题。我复制的代码如下所示。我在 Windows XP 上使用 Code::Blocks。

问题 1:

在下面的代码中,我收到一个错误,显示“'MyDDECallBACK' 未声明(在此函数中首次使用)。”如果我将其替换为 0,或注释掉该行,则代码运行时不会出现错误(只要我还注释掉了问题 2)。我不确定在哪里声明它,因为示例没有声明它,或者我不确定这是什么。除非我大写 true,否则它似乎也不喜欢 err=true ?

if(DMLERR_NO_ERROR != DdeInitialize(&idInst, MyDDECallBack, APPCMD_CLIENTONLY, 0))
err = true;

问题2:

代码末尾的“..”有何用途?另外,如果我将其注释掉(与问题 1 一起),代码就会运行。

再次感谢您的帮助!

// The following code fragment uses Windows DDEML APIs
// to send a move command to the Nucleus DDE Server
// and receives a status string.
//
// Variables and initial values.
HCONV hConv = NULL;

DWORD idInst = 0;
HSZ hszService = NULL;
HSZ hszTopic = NULL;
HSZ hszCmd = NULL;
BOOL err = FALSE;
HDDEDATA transResult = NULL;
DWORD dwResult = 0;
char result[300];
// Need long timeout value to allow the station to move and
// respond.
const long TIMEOUT = 60000;
// Initialize the DDEML environment. Create an Instance
// that is used in many other calls to DDE.
if(DMLERR_NO_ERROR != DdeInitialize(&idInst, MyDDECallBack,
APPCMD_CLIENTONLY, 0))
err = true;
// Create String handles for the server name, topic and item.
if(!err)
{
hszService = DdeCreateStringHandle(idInst, "EDMAIN",
CP_WINANSI);
hszTopic = DdeCreateStringHandle(idInst, "CMI Commands",
CP_WINANSI);
hszCmd = DdeCreateStringHandle(idInst,
":MOVE:REL 2 100 100 NONE",
CP_WINANSI);
err = (hszService == NULL || hszTopic == NULL || hszCmd == NULL);
}
// Connect to the Nucleus DDE Server. (Open a conversation).
// Captain Picard would say, "Open a channel Mr. Wharf".
if(!err)
{
hConv = DdeConnect(idInst, hszService, hszTopic, NULL);
err = hConv == NULL;
if(err)
MessageBox(NULL, "Unable to make DDE connection.\n"
"Make sure Nucleus is running.",
"DDE CLIENT ERROR", MB_ICONSTOP);
}
// Send the command string to the server.
if (!err)
{
transResult = DdeClientTransaction(NULL, 0, hConv, hszCmd,
CF_TEXT, XTYP_REQUEST, TIMEOUT, NULL);
// Read the result string. TransResult will be a
// valid data handle if the client transaction above
// was successful, and NULL if it was not. This must be
// checked since calls to DdeGetData with a NULL handle
// cause GPF’s.

if(transResult)
DdeGetData(transResult, (LPBYTE)result, sizeof(result), 0);
// Display the result string.
MessageBox(NULL, result, "RESULT", MB_ICONINFORMATION);
}
// Close the conversation.
if (hConv != NULL)
DdeDisconnect( hConv );
// Delete the string handles.
if ((hszService != NULL) & (idInst != NULL))
DdeFreeStringHandle( idInst, hszService );
if ((hszTopic != NULL) & (idInst != NULL))
DdeFreeStringHandle( idInst, hszTopic );
if ((hszCmd != NULL) & (idInst != NULL))
DdeFreeStringHandle( idInst, hszCmd );
// Clear out the DDEML environment.
if (idInst != NULL)
DdeUninitialize(idInst);
..
// Since we are only doing requests from Nucleus, we don’t
// expect to get callbacks to this routine. Nevertheless,
// it is necessary to create a routine with no action.
HDDEDATA CALLBACK MyDDECallBack( UINT wType,
UINT wFmt, HCONV HConv,
HSZ dataHandle1, HSZ dataHandle2,
HDDEDATA data, DWORD myword1,
DWORD myword2)
{
return NULL;
}

最佳答案

  1. 回调用于让您从服务获取通知。删除它,您将不会收到您可能需要的通知。
  2. .. 是示例代码的作者,旨在告诉您将自己的逻辑放在这里 - 它在 C 或 C++ 中没有任何意义(但是 3 个点 ... 在函数声明中确实有意义)

关于C 向 DDE 服务器发送命令的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23300307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com