Page 1 of 1

First tSim Class

Posted: Wed Jul 29, 2009 8:02 pm
by jlcapel
Hi all,

I am very happy to release very first tSim class to manage smartphone Sim cards.

This class just read/write/delete phone book entries from smartphone sim.

I do not have time to make a complete demo... But here are some guidelines...

* You need to include "#include sim.ch" at beginning of your prg.

* You have to initialize sim before using any method of this class. So code should be something like this:

Code: Select all

    LOCAL o
    o := tSim():New()
    o:lInitialize()
       // your code here
       o:End()  // Make an implicit Deinitialize
 
* You need to familiarize with sim locations. There are several locations into sim card (exactly 5). Normally we use SIM_PBSTORAGE_SIM but also there are SIM_PBSTORAGE_EMERGENCY, SIM_PBSTORAGE_LASTDIALING, etc... which implies to allways tell which storage to use. For example, to know how many entries we have in SIM_PBSTORAGE_EMERGENCY:

Code: Select all

    LOCAL o, nTotal, nUsed
    o := tSim():New()
    o:lInitialize()
        IF !o:lNumberOfPhoneBookEntries(SIM_PBSTORAGE_SIM, @nTotal, @nUsed)
            MsgInfo("Error accessing SIM ("+STR(o:nLastError)+")","Error")
            RETURN NIL
        ENDIF

        MsgInfo("There are "+Str(nTotal)+" entries and "+STR(nUsed)+" are used.".)
        o:End()
 
Well, this piece of code shows how all methods works (except two or three). Normally method returns .T. or .F. depending on success. Data 'nLastError' contains err-code of last operarion (even if it was successfull). In sim.ch there is the list of errors. As you can see, ntotal and nused are passed by reference. Many of these methodos have this type of imput.

* The phonebook entry are four fields plus 1. Methods which read entries always return it in a multidimensional array. For example, for reading entry number 5 you do the following.

Code: Select all

    LOCAL o, a
    o := tSim():New()
    o:lInitialize()
    IF !o:lGetSimPhoneEntry( 110, SIM_PBSTORAGE_SIM, @a )
       MsgInfo("Pos 110  error ("+STR(o:nLastError))
    ELSE
       Aeval(a, {| n, m | MsgInfo("Phone: "+n[1]+CRLF+"Name: "+n[2]+CRLF+"Adr. Type: "+STR( n[3])+CRLF+"Plan Type: "+STR( n[4]),"pos 110") })
    ENDIF
        o:End()
 
In this code 'a' is passed by reference and it returns a multidimensional array as follows:

{ { _PHONE_NUMBER_, _TEXT_, _ADR_TYPE_, _PLAN_TYPE_}, {...}, ... }

First Element is (normally) number, the seconds is the name. Third and four element should be investigated by you ;-)


There are 2 files. First is 'TestTapi.prg' which contain tSim class. Second file is sim.ch.
In bat file you have to include these two libs.

echo %vcdir%\lib\arm\sms.lib >> msvc.tmp
echo %vcdir%\lib\arm\cellcore.lib >> msvc.tmp

Well, here is testtapi.prg (It has Harbour Licence)

Code: Select all

/*
 * Harbour Project source code:
 * Quick Clipper Browse()
 *
 * Copyright 2009 José Luis Capel <jlcapel@hotmail.com>
 * www - http://www.harbour-project.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour.  If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */


#include "sim.ch"

//----------------------------------------------------------------------------//

/*
function Main()


    LOCAL o
    LOCAL l
    LOCAL nTotal, nUsed
    LOCAL a

    o := tSim():New()

    l := o:lInitialize()

    IF l
       MsgInfo("Api Sim initialized!!"+STR( o:nLastError))
    Else
       MsgInfo("Api Sim NOT initialized!!.  Error "+STR(o:nLastError))
    ENDIF


    IF !o:lGetSimPhoneEntry( 1, SIM_PBSTORAGE_SIM, @a )
       MsgInfo("Pos 1 error")
    ELSE
       MsgInfo("VALTYPE-> "+VALTYPE(a)+" LEN -> "+STR(LEN(a)),a[1][1])
       Aeval(a, {| n, m | MsgInfo("Phone: "+n[1]+CRLF+"Name: "+n[2]+CRLF+"Adr. Type: "+STR( n[3])+CRLF+"Plan Type: "+STR( n[4]),"pos 1") })
    ENDIF

    IF !o:lGetSimPhoneEntry( 110, SIM_PBSTORAGE_SIM, @a )
       MsgInfo("Pos 123 error")
    ELSE
       Aeval(a, {| n, m | MsgInfo("Phone: "+n[1]+CRLF+"Name: "+n[2]+CRLF+"Adr. Type: "+STR( n[3])+CRLF+"Plan Type: "+STR( n[4]),"pos 110") })
    ENDIF


        IF !o:lSetSimPhoneEntry( 80, SIM_PBSTORAGE_SIM, "660099696", "pepeluis", SIM_NUMPLAN_UNKNOWN, SIM_ADDRTYPE_NATIONAL )
           MsgInfo("Error writing pos 80 Errpr=>"+STR(o:nLastError))
        ENDIF
        IF !o:lDelSimPhoneEntry(80,SIM_PBSTORAGE_SIM)
           MsgInfo("Error deletein pos 80 Errpr=>"+STR(o:nLastError))
        ENDIF

    l := o:lDeInitialize()
    IF !l
       MsgInfo("Not De-Initialized SIM api.  Error :"+STR(o:nLastError))
    ELSE
       MsgInfo("Api Sim Deinitialized!!!")
    ENDIF



    o:End()

return nil
*/





CLASS tsim FROM xSim
ENDCLASS

CLASS xSim

        DATA lInitialized
        DATA hSim
        DATA nLastError


    METHOD New() CONSTRUCTOR
    METHOD End()

    METHOD lInitialize()  // Must be initialized before any other method
    METHOD lDeInitialize() // Must be deinitialized....

    METHOD lNumberOfPhoneBookEntries( nType, nTotal , nUsed ) // nTotal nUsed both by reference
    METHOD aGetAllPhoneBookEntries( nType ) // --> array with PhoneBookEntries of nType storage
    METHOD lGetSimPhoneEntry( nPos, nType, aEntry ) // --> aEntry by refence contais phonebookentry
    METHOD lSetSimPhoneEntry( nPos, nType, cNumber, cName, nPlan, nAddrType ) // .T. / .F. if phonebookentry written
    METHOD lDelSimPhoneEntry( nPos, nType ) //// .T. / .F. if phonebookentry deleted


ENDCLASS

METHOD New() CLASS xSim
    ::lInitialized := .F.
    ::hSim := 0
RETURN Self


METHOD lInitialize() CLASS xSim

       LOCAL nResult

       nResult        := Sim_Initialize( @::hSim )  // hSim by reference!!

       ::lInitialized := nResult == SIM_E_OK
       ::nLastError   := nResult

RETURN ::lInitialized


METHOD lDeInitialize() CLASS xSim

       LOCAL nResult


       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       nResult        := Sim_DeInitialize( ::hSim )

       ::lInitialized := !( nResult == SIM_E_OK)
       ::nLastError   := nResult

RETURN nResult == SIM_E_OK


METHOD lNumberOfPhoneBookEntries( nType, nTotal , nUsed ) CLASS xSim // nTotal and nUsed by reference

       LOCAL nResult

       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       DEFAULT nType := SIM_PBSTORAGE_SIM

       nResult       := Sim_PhoneBookEntries(::hSim, nType, @nTotal, @nUsed )
       ::nLastError  := nResult

RETURN nResult == SIM_E_OK


METHOD aGetAllPhoneBookEntries( nType ) CLASS xSim

       LOCAL nResult
       LOCAL nTotal
       LOCAL nUsed
       LOCAL aEntry
       LOCAL aEntries
       LOCAL nPos

       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       DEFAULT nType    := SIM_PBSTORAGE_SIM
       DEFAULT aEntries := {}

       IF !::lNumberOfPhoneBookEntries( nType, @nTotal, @nUsed )
          RETURN {}
       ENDIF

       FOR nPos := 1 TO nUsed
           aEntry := {}
           nResult := Sim_ReadPhoneBookEntry(::hSim, nType, nPos, @aEntry)
           IF nResult != SIM_E_OK
              ::nLastError := nResult
              EXIT
           ELSE
              AADD(aEntries, aEntry)
           ENDIF
       NEXT
       ::nLastError   := nResult

RETURN aEntries

METHOD lGetSimPhoneEntry( nPos, nType, aEntry ) CLASS xSim

       LOCAL nResult
       LOCAL a

       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       DEFAULT nType    := SIM_PBSTORAGE_SIM

       nResult := Sim_ReadPhoneBookEntry(::hSim, nType, nPos, @a)

       aEntry  := {}
       AADD(aEntry,a)
       ::nLastError   := nResult

RETURN nResult == SIM_E_OK

METHOD lSetSimPhoneEntry( nPos, nType, cNumber, cName, nPlan, nAddrType ) CLASS xSim
       LOCAL nResult

       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       DEFAULT nPos     := SIM_PBINDEX_FIRSTAVAILABLE
       DEFAULT nType    := SIM_PBSTORAGE_SIM

       nResult := Sim_WritePhoneBookEntry(::hSim, nType, nPos, cNumber, cName, nPlan, nAddrType)
       ::nLastError   := nResult

RETURN nResult == SIM_E_OK


METHOD lDelSimPhoneEntry( nPos, nType ) CLASS xSim
       LOCAL nResult

       IF !::lInitialized
          ::nLastError := SIM_E_NOTINITIALIZED
          RETURN .F.
       ENDIF

       DEFAULT nType    := SIM_PBSTORAGE_SIM

       nResult := Sim_DeletePhoneBookEntry(::hSim, nType, nPos)
       ::nLastError   := nResult

RETURN nResult == SIM_E_OK



METHOD End() CLASS xSim

       IF ::lInitialized
          ::lDeInitialize()
       ENDIF

RETURN NIL





#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <sms.h>


HB_FUNC( SEND_SMS )    // cMessage, cNumber
{
    SMS_HANDLE smshHandle;
    SMS_ADDRESS smsaDestination;
    TEXT_PROVIDER_SPECIFIC_DATA tpsd;
    SMS_MESSAGE_ID smsmidMessageID = 0;


    wchar_t  * sztMessage     = HB_TCHAR_CONVTO( hb_parc(1) );
    wchar_t  * sztPhoneNumber = HB_TCHAR_CONVTO( hb_parc(2) );
    BOOL bInternational       = *sztPhoneNumber == '+' ? TRUE : FALSE  ;



    // try to open an SMS Handle
    HRESULT hr = SmsOpen(SMS_MSGTYPE_TEXT, SMS_MODE_SEND, &smshHandle, NULL);
    if (hr != ERROR_SUCCESS) {
        HB_TCHAR_FREE(sztMessage);
        HB_TCHAR_FREE(sztPhoneNumber);
            hb_retc("ERROR - Can't open Sms system");
        return ;
    }


    // Create the destination address
    memset (&smsaDestination, 0, sizeof (smsaDestination) );
    smsaDestination.smsatAddressType = bInternational ? SMSAT_INTERNATIONAL : SMSAT_NATIONAL;
    lstrcpy(smsaDestination.ptsAddress, sztPhoneNumber);


    // Set up provider specific data
    tpsd.dwMessageOptions = PS_MESSAGE_OPTION_NONE;
    tpsd.psMessageClass = PS_MESSAGE_CLASS0;
    tpsd.psReplaceOption = PSRO_NONE;



    // Send the message, indicating success or failure
    hr = SmsSendMessage (smshHandle, NULL, &smsaDestination, NULL,
    (PBYTE) sztMessage, _tcslen(sztMessage) * sizeof(wchar_t),
    (PBYTE) &tpsd,12, SMSDE_OPTIMAL,
    SMS_OPTION_DELIVERY_NONE, &smsmidMessageID);

    switch( hr )
    {
        case S_OK :
             hb_retc("OK");
             break;
        case E_FAIL :
             hb_retc("ERROR - E_FAIL");
             break;
        case E_INVALIDARG :
             hb_retc("ERROR - E_INVALIDARG");
             break;
        case E_OUTOFMEMORY :
             hb_retc("ERROR - E_OUTOFMEMORY");
             break;
        case E_UNEXPECTED :
             hb_retc("ERROR - E_UNEXPECTED");
             break;
        case SMS_E_TOOMUCHDATA :
             hb_retc("ERROR - SMS_E_TOOMUCHDATA");
             break;
        case SMS_E_INVALIDDATA :
             hb_retc("ERROR - SMS_E_INVALIDDATA");
             break;
        case SMS_E_BUFFERTOOSMALL :
             hb_retc("ERROR - SMS_E_BUFFERTOOSMALL");
             break;
        case SMS_E_PROVIDERSPECIFICBUFFERWRONGSIZE :
             hb_retc("ERROR - SMS_E_PROVIDERSPECIFICBUFFERWRONGSIZE");
             break;
        case SMS_E_TIMEUNAVAILABLE :
             hb_retc("ERROR - SMS_E_TIMEUNAVAILABLE");
             break;
        case SMS_E_UNKNOWNSCADDRESS :
             hb_retc("ERROR - SMS_E_UNKNOWNSCADDRESS");
             break;
        case SMS_E_RECEIVEHANDLEALREADYOPEN :
             hb_retc("ERROR - SMS_E_RECEIVEHANDLEALREADYOPEN");
             break;
        case SMS_E_DESTINATIONOUTOFSVC :
             hb_retc("ERROR - SMS_E_DESTINATIONOUTOFSVC");
             break;
        case SMS_E_INVALIDADDRESS :
             hb_retc("ERROR - SMS_E_INVALIDADDRESS");
             break;
        case SMS_E_MSGBARREDBYOPERATOR :
             hb_retc("ERROR - SMS_E_MSGBARREDBYOPERATOR");
             break;
        case SMS_E_MSGCALLBARRED :
             hb_retc("ERROR - SMS_E_MSGCALLBARRED");
             break;
        case SMS_E_NOSCSUBSCRIPTION :
             hb_retc("ERROR - SMS_E_NOSCSUBSCRIPTION");
             break;
        case SMS_E_SCBUSY :
             hb_retc("ERROR - SMS_E_SCBUSY");
             break;
        case SMS_E_SVCNOTSUBSCRIBED :
             hb_retc("ERROR - SMS_E_SVCNOTSUBSCRIBED");
             break;
        case SMS_E_UNASSIGNEDNUMBER :
             hb_retc("ERROR - SMS_E_UNASSIGNEDNUMBER");
             break;
        case SMS_E_UNIDENTIFIEDSUBCRIBER :
             hb_retc("ERROR - SMS_E_UNIDENTIFIEDSUBCRIBER");
             break;
        default :
             hb_retc("ERROR - NO ERROR CODE");
             break;

        }

    SmsClose (smshHandle);
    HB_TCHAR_FREE(sztMessage);
    HB_TCHAR_FREE(sztPhoneNumber);

    return;

}


#pragma ENDDUMP




#pragma BEGINDUMP
#include <hbapi.h>
#include <windows.h>
#include <simmgr.h>
#include <hbapiitm.h>

LONG Sim_ErrCode( HRESULT hResult);


HB_FUNC( SIM_INITIALIZE )    // lNotifications, hSim by reference
{

    HSIM hSim = 0;
    /////////////BOOL bNotifications = HB_IS_NIL(1) ? FALSE : hb_parl(1);  This gpf's!!!
    HRESULT hResult;

    hResult = SimInitialize(0 , NULL, 0 , &hSim);
        hb_stornl( hResult == S_OK ? (LONG) hSim : 0, 1 );  // Passing hSim to first param by ref
        hb_retnl(Sim_ErrCode( hResult ) );

    return;
}


HB_FUNC( SIM_DEINITIALIZE )    // hSim
{

    HSIM hSim = (HSIM) hb_parnl(1)   ;
    HRESULT hResult;

    hResult = SimDeinitialize(hSim) ;

    hb_retnl(Sim_ErrCode(hResult));  // Check SIM Manager Error Constants  S_OK --> Success , any other error
    return;
}

HB_FUNC( SIM_PHONEBOOKENTRIES ) // hSim, nLocation, @nTotal, @nUsed
{

    HSIM hSim = (HSIM) hb_parnl(1);
    DWORD dwLocation = (DWORD) hb_parni(2);
    DWORD dwUsed = 0, dwTotal = 0;
    HRESULT hResult ;

        hResult = SimGetPhonebookStatus ( hSim, dwLocation, &dwUsed, &dwTotal);

        hb_stornl( hResult == S_OK ? (LONG) dwTotal : 0, 3 ) ;
        hb_stornl( hResult == S_OK ? (LONG) dwUsed : 0, 4 ) ;

    hb_retnl(Sim_ErrCode(hResult));  // Check SIM Manager Error Constants  S_OK --> Success , any other error
    return;

}

HB_FUNC( SIM_READPHONEBOOKENTRY ) // hSim, nLocation, nPos, @aEntry
{

    HSIM hSim = (HSIM) hb_parnl(1);
    DWORD dwLocation = (DWORD) hb_parni(2);
    DWORD dwIndex = (DWORD) hb_parni(3);
    HRESULT hResult ;
    SIMPHONEBOOKENTRY PhoneEntry;
    PHB_ITEM pArray = hb_itemNew( NULL );
    char * lpszAddress;
    char * lpszText;



    PhoneEntry.cbSize = sizeof(SIMPHONEBOOKENTRY);
    hResult = SimReadPhonebookEntry ( hSim, dwLocation ,dwIndex, &PhoneEntry);

        lpszAddress = HB_TCHAR_CONVFROM(PhoneEntry.lpszAddress);
        lpszText = HB_TCHAR_CONVFROM(PhoneEntry.lpszText);

    hb_arrayNew( pArray, 5 ); // 5 elements

    hb_arraySetC( pArray, 1, lpszAddress ); // a string
    hb_arraySetC( pArray, 2, lpszText ); // a string
    hb_arraySetNL( pArray, 3, PhoneEntry.dwAddressType );    // a number
    hb_arraySetNL( pArray, 4, PhoneEntry.dwNumPlan );    // a number
    hb_arraySetNI( pArray, 5, dwIndex );    // index

    hb_itemCopy( hb_param( 4, HB_IT_ANY ), pArray );
    hb_itemRelease( pArray );

    HB_TCHAR_FREE( lpszAddress );
    HB_TCHAR_FREE( lpszText );

    hb_retnl(Sim_ErrCode(hResult));  // Check SIM Manager Error Constants  S_OK --> Success , any other error
    return;

}

HB_FUNC( SIM_WRITEPHONEBOOKENTRY ) // hSim, nLocation, nPos, cNumber, cName, nPlan, nAddrType
{

        HRESULT hResult ;
        SIMPHONEBOOKENTRY PhoneEntry;
        wchar_t * lpwszAddress;
        wchar_t * lpwszText;

        lpwszAddress = HB_TCHAR_CONVTO( hb_parc(4) );
        lpwszText    = HB_TCHAR_CONVTO( hb_parc(5) );

        PhoneEntry.cbSize        = sizeof(SIMPHONEBOOKENTRY);
        PhoneEntry.dwParams      = SIM_PARAM_PBE_ALL;
        wcsncpy(PhoneEntry.lpszAddress,   lpwszAddress, MAX_LENGTH_ADDRESS);
        wcsncpy(PhoneEntry.lpszText,      lpwszText, MAX_LENGTH_PHONEBOOKENTRYTEXT);
        PhoneEntry.dwAddressType = (DWORD) hb_parnl(7);
        PhoneEntry.dwNumPlan     = (DWORD) hb_parnl(6);


        hResult = SimWritePhonebookEntry ( (HSIM) hb_parnl(1), (DWORD) hb_parni(2) ,(DWORD) hb_parni(3), &PhoneEntry);

        HB_TCHAR_FREE( lpwszAddress );
        HB_TCHAR_FREE( lpwszText );

        hb_retnl(Sim_ErrCode(hResult));  // Check SIM Manager Error Constants  S_OK --> Success , any other error
        return;

}

HB_FUNC( SIM_DELETEPHONEBOOKENTRY ) // hSim, nLocation, nPos
{
    HRESULT hResult ;

    hResult = SimDeletePhonebookEntry ( (HSIM) hb_parnl(1), (DWORD) hb_parni(2) ,(DWORD) hb_parni(3) );
        hb_retnl(Sim_ErrCode(hResult));  // Check SIM Manager Error Constants  S_OK --> Success , any other error
        return;

}

LONG Sim_ErrCode( HRESULT hResult )
{

    switch( hResult)
    {
        case S_OK :
                return(0);
        case SIM_E_SIMFAILURE :
                return(-100);
        case SIM_E_SIMBUSY :
                return(-200);
        case SIM_E_SIMWRONG :
                return(-300);
        case SIM_E_NOSIMMSGSTORAGE :
                return(-400);
        case SIM_E_SIMTOOLKITBUSY :
                return(-500);
        case SIM_E_SIMDOWNLOADERROR :
                return(-600);
        case SIM_E_SIMNOTINSERTED :
                return(-700);
        case SIM_E_PHSIMPINREQUIRED :
                return(-800);
        case SIM_E_PHFSIMPINREQUIRED :
                return(-900);
        case SIM_E_PHFSIMPUKREQUIRED :
                return(-1000);
        case SIM_E_SIMPINREQUIRED :
                return(-1100);
        case SIM_E_SIMPUKREQUIRED :
                return(-1200);
        case SIM_E_INCORRECTPASSWORD :
                return(-1300);
        case SIM_E_SIMPIN2REQUIRED :
                return(-1400);
        case SIM_E_SIMPUK2REQUIRED :
                return(-1500);
        case SIM_E_NETWKPINREQUIRED :
                return(-1600);
        case SIM_E_NETWKPUKREQUIRED :
                return(-1700);
        case SIM_E_SUBSETPINREQUIRED :
                return(-1800);
        case SIM_E_SUBSETPUKREQUIRED :
                return(-1900);
        case SIM_E_SVCPINREQUIRED :
                return(-2000);
        case SIM_E_SVCPUKREQUIRED :
                return(-2100);
        case SIM_E_CORPPINREQUIRED :
                return(-2200);
        case SIM_E_CORPPUKREQUIRED :
                return(-2300);
        case SIM_E_MEMORYFULL :
                return(-2400);
        case SIM_E_INVALIDINDEX :
                return(-2500);
        case SIM_E_NOTFOUND :
                return(-2600);
        case SIM_E_MEMORYFAILURE :
                return(-2700);
        case SIM_E_SIMMSGSTORAGEFULL :
                return(-2800);
        case SIM_E_EMPTYINDEX :
                return(-2900);
        case SIM_E_NOTREADY :
                return(-3000);
        case SIM_E_SECURITYFAILURE :
                return(-3100);
        case SIM_E_BUFFERTOOSMALL :
                return(-3200);
        case SIM_E_NOTTEXTMESSAGE :
                return(-3300);
        case SIM_E_NOSIM :
                return(-3400);
        case SIM_E_NETWORKERROR :
                return(-3500);
        case SIM_E_MOBILEERROR :
                return(-3600);
        case SIM_E_UNSUPPORTED :
                return(-3700);
        case SIM_E_BADPARAM :
                return(-3800);
        case SIM_E_UNDETERMINED :
                return(-3900);
        case SIM_E_RADIONOTPRESENT :
                return(-4000);
        case SIM_E_RADIOOFF :
                return(-4100);
    }
    return (-9999) ;


}


#pragma ENDDUMP

 

And here sim.ch

Code: Select all

/*
 * Harbour Project source code:
 * Quick Clipper Browse()
 *
 * Copyright 2009 José Luis Capel <jlcapel@hotmail.com>
 * Some parts Copyright MicroSoft Corp.
 * www - http://www.harbour-project.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/).
 *
 * As a special exception, the Harbour Project gives permission for
 * additional uses of the text contained in its release of Harbour.
 *
 * The exception is that, if you link the Harbour libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Harbour library code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public License.
 *
 * This exception applies only to the code released by the Harbour
 * Project under the name Harbour.  If you copy code from other
 * Harbour Project or Free Software Foundation releases into a copy of
 * Harbour, as the General Public License permits, the exception does
 * not apply to the code that you add in this way.  To avoid misleading
 * anyone as to the status of such modified files, you must delete
 * this exception notice from them.
 *
 * If you write modifications of your own for Harbour, it is your choice
 * whether to permit this exception to apply to your modifications.
 * If you do not wish that, delete this exception notice.
 *
 */

// Error Codes for SIM api
#define SIM_E_OK                       0     // This is non standard...
#define SIM_E_NOTINITIALIZED           -10   // This is non standard (class tsim not initialized sim)
#define SIM_E_UNESPECTEDERROR          -9999 // This error means that an error catched but not in list bellow...
#define SIM_E_SIMFAILURE               -100 // @constdefine SIM failure was detected
#define SIM_E_SIMBUSY                  -200 // @constdefine SIM is busy
#define SIM_E_SIMWRONG                 -300 // @constdefine Inorrect SIM was inserted
#define SIM_E_NOSIMMSGSTORAGE          -400 // @constdefine SIM isn't capable of storing messages
#define SIM_E_SIMTOOLKITBUSY           -500 // @constdefine SIM Application Toolkit is busy
#define SIM_E_SIMDOWNLOADERROR         -600 // @constdefine SIM data download error
#define SIM_E_SIMNOTINSERTED           -700 // @constdefine SIM isn't inserted into the phone
#define SIM_E_PHSIMPINREQUIRED         -800// @constdefine PH-SIM PIN is required to perform this operation
#define SIM_E_PHFSIMPINREQUIRED        -900 // @constdefine PH-FSIM PIN is required to perform this operation
#define SIM_E_PHFSIMPUKREQUIRED        -1000 // @constdefine PH-FSIM PUK is required to perform this operation
#define SIM_E_SIMPINREQUIRED           -1100 // @constdefine SIM PIN is required to perform this operation
#define SIM_E_SIMPUKREQUIRED           -1200 // @constdefine SIM PUK is required to perform this operation
#define SIM_E_INCORRECTPASSWORD        -1300 // @constdefine Incorrect password was supplied
#define SIM_E_SIMPIN2REQUIRED          -1400 // @constdefine SIM PIN2 is required to perform this operation
#define SIM_E_SIMPUK2REQUIRED          -1500 // @constdefine SIM PUK2 is required to perform this operation
#define SIM_E_NETWKPINREQUIRED         -1600 // @constdefine Network Personalization PIN is required to perform this operation
#define SIM_E_NETWKPUKREQUIRED         -1700 // @constdefine Network Personalization PUK is required to perform this operation
#define SIM_E_SUBSETPINREQUIRED        -1800 // @constdefine Network Subset Personalization PIN is required to perform this operation
#define SIM_E_SUBSETPUKREQUIRED        -1900 // @constdefine Network Subset Personalization PUK is required to perform this operation
#define SIM_E_SVCPINREQUIRED           -2000 // @constdefine Service Provider Personalization PIN is required to perform this operation
#define SIM_E_SVCPUKREQUIRED           -2100 // @constdefine Service Provider Personalization PUK is required to perform this operation
#define SIM_E_CORPPINREQUIRED          -2200 // @constdefine Corporate Personalization PIN is required to perform this operation
#define SIM_E_CORPPUKREQUIRED          -2300 // @constdefine Corporate Personalization PUK is required to perform this operation
#define SIM_E_MEMORYFULL               -2400 // @constdefine Storage memory is full
#define SIM_E_INVALIDINDEX             -2500 // @constdefine Invalid storage index was supplied
#define SIM_E_NOTFOUND                 -2600 // @constdefine A requested storage entry was not found
#define SIM_E_MEMORYFAILURE            -2700 // @constdefine Storage memory failure
#define SIM_E_SIMMSGSTORAGEFULL        -2800 // @constdefine Message storage on the SIM is full
#define SIM_E_EMPTYINDEX               -2900 // @constdefine Storage location is empty
#define SIM_E_NOTREADY                 -3100 // @constdefine SIM isn't yet ready to perform the requested operation
#define SIM_E_SECURITYFAILURE          -3200 // @constdefine SIM isn't yet ready to perform the requested operation
#define SIM_E_BUFFERTOOSMALL           -3300 // @constdefine Buffer too small
#define SIM_E_NOTTEXTMESSAGE           -3400 // @constdefine Requested SMS message is not a text message
#define SIM_E_NOSIM                    -3500 // @constdefine Device doesn't have a SIM
#define SIM_E_NETWORKERROR             -3600 // @constdefine There was a network error
#define SIM_E_MOBILEERROR              -3700 // @constdefine Mobile error
#define SIM_E_UNSUPPORTED              -3800 // @constdefine The command is unsupported
#define SIM_E_BADPARAM                 -3900 // @constdefine Bad parameter
#define SIM_E_UNDETERMINED             -4000 // @constdefine Undetermined error
#define SIM_E_RADIONOTPRESENT          -4100 // @constdefine The Radio is not present
#define SIM_E_RADIOOFF                 -4200 // @constdefine The Radio is off

// Phone book storage locations
#define SIM_PBSTORAGE_EMERGENCY         (0x00000001)      // @constdefine Emergency dial list
#define SIM_PBSTORAGE_FIXEDDIALING      (0x00000002)      // @constdefine SIM fixed dialing list
#define SIM_PBSTORAGE_LASTDIALING       (0x00000004)      // @constdefine SIM last dialing list
#define SIM_PBSTORAGE_OWNNUMBERS        (0x00000008)      // @constdefine SIM ownnumbers lists
#define SIM_PBSTORAGE_SIM               (0x00000010)      // @constdefine General SIM Storage
#define SIM_NUMPBSTORAGES               5                 // @constdefine Number of phonebook storages

// -----------------------------------------------------------------------------


// -----------------------------------------------------------------------------
//
// @doc EXTERNAL
//
// @constants Phonebook Misc | Special phonebook constants
//
// @comm None
//
// -----------------------------------------------------------------------------
#define SIM_PBINDEX_FIRSTAVAILABLE      (0xffffffff)      // @constdefine Use first phonebook storage entry available


// -----------------------------------------------------------------------------
//
// @doc EXTERNAL
//
// @constants Numbering Plan | Defines different numbering plans for SIM_ADDRTYPE_UNKNOWN,
//            SIM_ADDRTYPE_INTERNATIONAL, and SIM_ADDRTYPE_NATIONAL
//
// @comm None
//
// -----------------------------------------------------------------------------
#define SIM_NUMPLAN_UNKNOWN             (0x00000000)      // @constdefine Unknown
#define SIM_NUMPLAN_TELEPHONE           (0x00000001)      // @constdefine ISDN/telephone numbering plan (E.164/E.163)
#define SIM_NUMPLAN_DATA                (0x00000002)      // @constdefine Data numbering plan (X.121)
#define SIM_NUMPLAN_TELEX               (0x00000003)      // @constdefine Telex numbering plan
#define SIM_NUMPLAN_NATIONAL            (0x00000004)      // @constdefine National numbering plan
#define SIM_NUMPLAN_PRIVATE             (0x00000005)      // @constdefine Private numbering plan
#define SIM_NUMPLAN_ERMES               (0x00000006)      // @constdefine ERMES numbering plan (ETSI DE/PS 3 01-3)


// -----------------------------------------------------------------------------
//
// @doc EXTERNAL
//
// @constants Address Type | Defines different address types
//
// @comm None
//
// -----------------------------------------------------------------------------
#define SIM_ADDRTYPE_UNKNOWN            (0x00000000)      // @constdefine Unknown
#define SIM_ADDRTYPE_INTERNATIONAL      (0x00000001)      // @constdefine International number
#define SIM_ADDRTYPE_NATIONAL           (0x00000002)      // @constdefine National number
#define SIM_ADDRTYPE_NETWKSPECIFIC      (0x00000003)      // @constdefine Network specific number
#define SIM_ADDRTYPE_SUBSCRIBER         (0x00000004)      // @constdefine Subscriber number (protocol-specific)
#define SIM_ADDRTYPE_ALPHANUM           (0x00000005)      // @constdefine Alphanumeric address
#define SIM_ADDRTYPE_ABBREV             (0x00000006)      // @constdefine Abbreviated number


#xcommand DEFAULT <uVar1> := <uVal1> ;
               [, <uVarN> := <uValN> ] => ;
                  <uVar1> := If( <uVar1> == nil, <uVal1>, <uVar1> ) ;;
                [ <uVarN> := If( <uVarN> == nil, <uValN>, <uVarN> ); ]

 

Re: First tSim Class

Posted: Sat Aug 01, 2009 8:19 am
by Antonio Linares
Jose Luis,

gracias! :-)

Tendrás que modificar los títulos que has usado para los ficheros de Harbour :-)
* Harbour Project source code:
* Quick Clipper Browse()

Re: First tSim Class

Posted: Sat Aug 01, 2009 4:02 pm
by jlcapel
Antonio,

You're right!

It is already changed in harbour svn sources.