Answered WinCE 6.0, work with GPRS/WiFi (C#)

  • terça-feira, 6 de março de 2012 13:00
     
     
    Hello. I'm working on a project, which should connect to servers through wifi/gprs. Project is an application for Windows CE 6.0 device, I'm writing in Visual Studio 2008 on C#.

    I have two severs to work with. To first I have to connect via wifi, second - via gprs. So I need to know, how can I change the method of connecting between wifi and gprs.

    I found and tried this way: I turn on both wifi and gprs on my device. So I work via wifi because it has a higher priority. When I need to work via gprs, I turn off wifi (SetDevicePower function). But when I turn wifi on, it doesn't connect to my Preferred Network back.

    Also I heard about the way to change priority between gprs/wifi in OS priority table programmatically, but i didn't found any information about how to do this.

    I hope you can help me.
    • Movido CoolDadTxMVP terça-feira, 6 de março de 2012 14:53 Mobile related (From:Visual C# General)
    •  

Todas as Respostas

  • quarta-feira, 7 de março de 2012 16:02
     
     Respondido Contém Código

    I think the ConnectionManager API can do what you want. It allows you to select from the available interfaces and establish a network connection using whichever one you want to use.

    // Get the interface you want to connect with. This can
    // be a programmatic choice or a user selection.
    const CONNMGR_CONNECTION_DETAILED_STATUS* status = GetDesiredInterface();
    
    CONNMGR_CONNECTIONINFO info = { 0 };
    info.cbSize = sizeof( CONNMGR_CONNECTIONINFO );
    info.dwParams = CONNMGR_PARAM_GUIDDESTNET;
    info.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
    
    // allow connection manager to use any proxy it needs to make the connection
    info.dwFlags = CONNMGR_FLAG_PROXY_HTTP | 
                   CONNMGR_FLAG_PROXY_SOCKS4 | 
                   CONNMGR_FLAG_PROXY_SOCKS5 | 
                   CONNMGR_FLAG_PROXY_WAP;
    
    // Get the destination meta-network GUID for the adapter with the given name. If the
    // adapter doesn't have a name, the description usually works. If the adapter is a proxy,
    // be sure to set the correct reference type.
    if( S_OK == ::ConnMgrMapConRef( 
        ( CM_CONNTYPE_PROXY == status->dwType ) ? ConRefType_PROXY : ConRefType_NAP, 
        ( NULL != status->szAdapterName ) ? status->szAdapterName : status->szDescription, 
        &info.guidDestNet ) )
    {
        DWORD status = 0;
        HANDLE connection = NULL;
        
        // Establish the connection. hr will either be E_FAIL or S_OK. Extended error 
        // information is stored in the status variable.
        HRESULT hr = ::ConnMgrEstablishConnectionSync( &info, 
                                                       &connection, 
                                                       30000, 
                                                       &status );
        if( S_OK == hr )
        {
            // use the connection wisely, then release it when you are finished
            ::ConnMgrReleaseConnection( connection, 1 );
        }
    }
    
    

    see: http://www.codeproject.com/Articles/98020/Using-the-Connection-Manager

    -PaulH