Sdílet prostřednictvím


Getting status information when establishing an async connection

There was an interesting post over in the microsoft.public.smartphone.developer newsgroup today that seemed worth blogging the answer to. The question was:

“[...] can my application receive messages or have a callback called when the status of my asynchronous connection attempt changes?”

The answer is yes. To do this you need to use a couple of members in the CONNMGR_CONNECTIOINFO passed to ConnMgrEstablishConnection(). To get window messages as connection status changes set the hWnd member to the window handle that should receive the messages. Then set the uMsg member to the window message you'd like to have sent (I usually use WM_USER + some offset). Optionally you can set the lParam method to a value you want to have sent along for the ride with the window message.

As connection status changes you'll receive messages to the window you specified, with the wParam set to the status. A list of the supported states can be found in the ConnMgrConnectionStatus() documentation.

[Author: Neil Enns]

Comments

  • Anonymous
    June 24, 2004
    .. but you only receive events from ConnMgr when you are connected (STATUS_CONNECTED) and the connection is lost (STATUS_CONNECTIONCANCELLED).

    Is there any way to detect a connection has become available again. It seems like once you get a lost connection you need to poll the connection manager with EstablishConnection() continuously to try and re-establish. (Polling for status always still says CONNECTIONCANCELLED until you use EstablishConnection() again).

    Very frustrating. Ideally an app that wants to stay online all the time should register with ConnMgr and just get status events posted all the time.
  • Anonymous
    June 24, 2004
    When you get told the connection is dropped simply call ConnMgrEstablishConnection() immediately again. Then go back to waiting for an event from connmgr. As soon as connection manager is able to satisfy the request you'll get pinged with a STATUS_CONNECTED method. I've used this in the past to simulate an always-on GPRS connection.

    Other status events come through as well, such as connecting is in progress.

    Neil
  • Anonymous
    June 24, 2004
    I don't seem to be able to get that behaviour on my WM2003 device!

    When I get the CONNMGR_STATUS_CONNECTIONCANCELED sent to my window, I do call ConnMgrEstablishConnection() again, and it returns SUCEEDED, and sends my window CONNMGR_STATUS_NOPATHTODESTINATION. After that it never sends any other status events (although I see the Conn Mgr icons on the system toolbar change from offline to online).

    I have tried both releasing my current connmgr handle, and keeping my handle between ConnMgrEstablishConnection() calls... When the ConnMgr icon shows it being online, I can call ConMgrEstablishConnection() again and I will get CONNMGR_STATUS_WAITCONNECTION immeadiately followed by CONNMGR_STATUS_CONNECTED.

    BTW, by test is using an intermec I700 with a cradle. I put it in the cradle and the ConnMgr detects the LAN after about 10 seconds and shows the online icon. Any idea what's missing?
  • Anonymous
    June 24, 2004
    The comment has been removed
  • Anonymous
    January 12, 2006
    Connection Manager posts the status change messages only if i give a window handle.
    In my application i want the htatus change messages come to a thread which doesnt have a window handle of its own..
    How do i do this.
    I have tried giving the thread handle to the hwnd parameter..but that doesnt work..My thread doesnt receive any status messages.
    How do i do this?

  • Anonymous
    March 28, 2009
    Hi, try setting CONNMGR_CONNECTIONINFO.dwParams. I have set it to CONNMGR_PARAM_GUIDDESTNET.