2014-04-25 65 views
0

我複製代碼時遇到兩個問題。我複製的代碼如下所示。我在Windows XP上使用Code :: Blocks。C將命令發送到DDE服務器的示例

問題1:

在下面的代碼,我得到它說一個錯誤「‘MyDDECallBACK’未申報(在一次使用此功能,」如果我有一個0替換它,或註釋掉該行,該代碼運行沒有錯誤(只要我也註釋問題2)。我不確定在哪裏聲明這個,因爲這個例子沒有聲明它,或者我不確定這是什麼,它似乎也不喜歡的ERR =真除非我利用真

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; 
} 
+0

請縮進您的代碼。 –

回答

0
  1. 回調是,你得到通知從服務了。刪除這個,你不會得到你可能需要的通知。
  2. 的..是的示例代碼的方式來告訴你把你自己的邏輯在這裏作者 - 它在C或C++沒有意義了(但是3點...確實有函數聲明一個意思)
+0

謝謝!但是我該如何聲明這個函數呢? –

+0

您需要找到'MyDDECallBack'的定義,然後用該簽名聲明一個函數。 – Soren