Inicializar GPRS

Post Reply
lsmarco
Posts: 13
Joined: Fri Jan 08, 2010 10:51 am

Inicializar GPRS

Post by lsmarco »

Olá,

Gostaria de saber como faço para inicializar o GPRS (linha internet) do aparelho antes de ativar os comandos FTP.

obrigado,

Luciano.
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Inicializar GPRS

Post by anserkk »

Please refer this topic
http://forums.fivetechsupport.com/viewt ... =4&t=14874

You have to link vce CellCore.lib

Code: Select all

// FTP sample developed by Enrico Maria Giordano

#include "Fwce.ch"

#define FILE_ATTRIBUTE_READONLY 1
#define FILE_ATTRIBUTE_HIDDEN 2
#define FILE_ATTRIBUTE_SYSTEM 4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE 32
#define FILE_ATTRIBUTE_NORMAL 128
#define FILE_ATTRIBUTE_TEMPORARY 256



//
// access types for InternetOpen()
//

#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net
#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS


//
// manifests
//

#define INTERNET_INVALID_PORT_NUMBER 0 // use the protocol-specific default

#define INTERNET_DEFAULT_FTP_PORT 21 // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT 70 // " " gopher "
#define INTERNET_DEFAULT_HTTP_PORT 80 // " " HTTP "
#define INTERNET_DEFAULT_HTTPS_PORT 443 // " " HTTPS "
#define INTERNET_DEFAULT_SOCKS_PORT 1080 // default for SOCKS firewall servers.


//
// service types for InternetConnect()
//

#define INTERNET_SERVICE_FTP 1
#define INTERNET_SERVICE_GOPHER 2
#define INTERNET_SERVICE_HTTP 3


//
// flags for FTP
//

#define INTERNET_FLAG_TRANSFER_ASCII 1
#define INTERNET_FLAG_TRANSFER_BINARY 2



FUNCTION MAIN()
LOCAL hInternet, hCon

    MsgInfo("Conectando...")
    hInternet := InternetOpen( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    IF hINTERNET = 0
       MSGINFO("Erro na conexão com a internet!")
       RETURN NIL
    ENDIF

    hCon = INTERNETCONNECT( hInternet, "ip_do_Site_ftp",0, "Usuário","senha", INTERNET_SERVICE_FTP, 0,0 )
    IF HCON = 0
       MSGSTOP("Erro na conexão FTP !")
       RETURN NIL
    ENDIF

    FTPPUTFILE( hCon, CurDir()+"\param.dbf", "/public_html/sav/param.dbf", 0, 0 )

    INTERNETCLOSEHANDLE( hCon )
    INTERNETCLOSEHANDLE( hInternet )

    MsgInfo("Arquivo enviado com sucesso !")

RETURN NIL


#pragma BEGINDUMP

#include "windows.h"
#include "wininet.h"
#include "hbapi.h"
#include "initguid.h"
#include "connmgr.h"


LPWSTR AnsiToWide( LPSTR );

HB_FUNC( INTERNETOPEN )
{
    LPWSTR cAgent = AnsiToWide( hb_parc( 1 ) );
    LPWSTR cProxyName = AnsiToWide( hb_parc( 3 ) );
    LPWSTR cProxyBypass = AnsiToWide( hb_parc( 4 ) );

    HINTERNET hInternet = InternetOpen( cAgent, hb_parnl( 2 ), cProxyName, cProxyBypass, hb_parnl( 5 ) );

    hb_xfree( cAgent );
    hb_xfree( cProxyName );
    hb_xfree( cProxyBypass );

    hb_retnl( ( LONG ) hInternet );
}

HB_FUNC( INTERNETCLOSEHANDLE )
{
    hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}

HB_FUNC( INTERNETCONNECT )
{
    LPWSTR cServerName = AnsiToWide( hb_parc( 2 ) );
    LPWSTR cUserName = AnsiToWide( hb_parc( 4 ) );
    LPWSTR cPassword = AnsiToWide( hb_parc( 5 ) );

    HINTERNET hInternet = InternetConnect( ( HINTERNET ) hb_parnl( 1 ), cServerName, ( INTERNET_PORT ) hb_parnl( 3 ), cUserName, cPassword, hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) );

    hb_xfree( cServerName );
    hb_xfree( cUserName );
    hb_xfree( cPassword );

    hb_retnl( ( LONG ) hInternet );
}

HB_FUNC( FTPGETFILE )
{
    LPWSTR cRemoteFile = AnsiToWide( hb_parc( 2 ) );
    LPWSTR cNewFile = AnsiToWide( hb_parc( 3 ) );

    hb_retl( FtpGetFile( ( HINTERNET ) hb_parnl( 1 ), cRemoteFile, cNewFile, hb_parl( 4 ), hb_parnl( 5 ), hb_parnl( 6 ), hb_parnl( 7 ) ) );

    hb_xfree( cRemoteFile );
    hb_xfree( cNewFile );
}

HB_FUNC( FTPPUTFILE )
{
    LPWSTR cLocalFile = AnsiToWide( hb_parc( 2 ) );
    LPWSTR cNewRemoteFile = AnsiToWide( hb_parc( 3 ) );

    hb_retl( FtpPutFile( ( HINTERNET ) hb_parnl( 1 ), cLocalFile, cNewRemoteFile, hb_parnl( 4 ), hb_parnl( 5 ) ) );

    hb_xfree( cLocalFile );
    hb_xfree( cNewRemoteFile );
}

HB_FUNC (GPRSCONNECTION)
{
   HANDLE phWebConnection = NULL;
   DWORD pdwStatus = 0;

   ConnMgrConnectionStatus (phWebConnection, &pdwStatus);
   if (pdwStatus == CONNMGR_STATUS_CONNECTED)
   {
      hb_retl (TRUE);
   }
   else
   {
      CONNMGR_CONNECTIONINFO sConInfo;
      memset (&sConInfo,0, sizeof (CONNMGR_CONNECTIONINFO));
      sConInfo.cbSize = sizeof (CONNMGR_CONNECTIONINFO);
      sConInfo.dwParams = CONNMGR_PARAM_GUIDDESTNET;
      sConInfo.dwPriority = CONNMGR_PRIORITY_USERINTERACTIVE;
      sConInfo.dwFlags = CONNMGR_FLAG_PROXY_HTTP;
      sConInfo.bExclusive = FALSE;
      sConInfo.bDisabled = FALSE;
      sConInfo.guidDestNet = IID_DestNetInternet;


      if (ConnMgrEstablishConnection (&sConInfo, &phWebConnection) == S_OK)
      {
         unsigned int k;
         
         for( k = 0; k < 8; k ++)
         {
            ConnMgrConnectionStatus(phWebConnection,&pdwStatus);
            if (pdwStatus == CONNMGR_STATUS_CONNECTED)
            {
               hb_retl (TRUE);
            }
            else
            {
               if (pdwStatus == CONNMGR_STATUS_CONNECTIONCANCELED || pdwStatus == CONNMGR_STATUS_WAITINGCONNECTIONABORT)
               {
                  hb_retl (FALSE);
               }
               Sleep (2500);
               ConnMgrConnectionStatus (phWebConnection, &pdwStatus);
               if (pdwStatus == CONNMGR_STATUS_WAITINGCONNECTION)
               {}
               if (pdwStatus == CONNMGR_STATUS_CONNECTIONCANCELED || pdwStatus == CONNMGR_STATUS_WAITINGCONNECTIONABORT)
               {
                  hb_retl (FALSE);
               }
            }
         }
         hb_retl (FALSE);
      }
      else
      {
         hb_retl (FALSE);
      }
   }
}

#pragma ENDDUMP
Regards
Anser
Post Reply