Here's what I use to get IMEI (using phone library) and it works for
me on Treo 600. status_t is a typedef to Err and if you're not using
C++ standard library then you have to replace String with char * and
remove the assert().

phnLibCDMAName and others are defined in HsPhoneTypes.h in SDK.

// get IMEI number, should be unique but apparently the phone
// needs to be connected to network in order to return this
// see http://www.mail-archive.com/[EMAIL PROTECTED]/msg76403.html
static status_t getIMEI(String& out)
{
    bool     libLoaded=false;
    UInt16   refNum=sysInvalidRefNum ;

    status_t error=SysLibFind(phnLibCDMAName, &refNum);
    if (error)
        error=SysLibFind(phnLibGSMName, &refNum);
    if (error)
    {
        error=SysLibLoad(phnLibDbType, phnLibCDMADbCreator, &refNum);
        if (error)
            error=SysLibLoad(phnLibDbType, phnLibGSMDbCreator, &refNum);
        if (!error)
            libLoaded=true;
    }

    if (error)
        return error;

    assert(sysInvalidRefNum!=refNum);

    char *emei=NULL;

    if (PhnLibCardInfo(refNum,0,0,NULL,&emei))
    {
        // "00000000" is an invalid IMEI which can happen, according to
        // http://www.mail-archive.com/[EMAIL PROTECTED]/msg76416.html
        // (it's also what simulator returns)
        if (emei && *emei && (0!=StrCompare(emei,"00000000")))
        {
            out.append(emei);
            MemPtrFree (emei);
        }
        else
            error = sysErrParamErr;
    }
    else
        error = sysErrParamErr;

    if (libLoaded)
        SysLibRemove(refNum);

    return error;
}


Krzysztof Kowalczyk | http://blog.kowalczyk.info

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to