如何重新连接到DDE服务器

时间:2015-12-08 11:14:47

标签: c++ windows winapi dde

如何重新连接到DDE服务器?

以下代码不断给出0x4006错误,该错误与documentation相符,表示DMLERR_INVALIDPARAMETER

HCONV g_conv;

void dde_server_reconnect(HCONV hconv)
{
  while (true)
  {
    if (g_conv = DdeReconnect(hconv))
    {
      std::cout << "Reconnect success!" << std::endl;
      return;
    }
    else
    {
      std::cerr << "Unable to reconnect. Error: " << DdeGetLastError(g_id_inst) << std::endl;
    }

    boost::this_thread::sleep_for(boost::chrono::seconds(1));
  }
}

HDDEDATA CALLBACK dde_callback(
  UINT uType,
  UINT uFmt,
  HCONV hconv,
  HSZ hsz1,
  HSZ hsz2,
  HDDEDATA hdata,
  DWORD dwData1,
  DWORD dwData2)
{
  switch (uType)
  {
  case XTYP_ADVDATA:
  {
    process_data(hdata);
    return (HDDEDATA)DDE_FACK;
  }

  case XTYP_DISCONNECT:
  {
    auto reconnect_th = boost::thread(dde_server_reconnect, hconv);
    reconnect_th.detach();
  }
  }

  return NULL;
}

我做错了什么?我该如何解决?

0 个答案:

没有答案