Developer Reference Dongling for Command Line Applications

Most command line applications do not have a windows message loop, ENCX uses windows messages to pass dongle security change notifications between threads. It is important to wait for the security system to be initialised before trying to open, install or update a chart.

Early in a command line app you should wait for the dongle to become active and fail if this does not happen. Of course, if during the running of the application the dongle is removed then an error will occur and that has to be handled. Generally though, if the dongle is OK at the start it will stay OK.

One might declare a function:

namespace
{
    bool FindDongle(encx::ILibraryPtr pEncx)
    {
        for(int n = 0;n < 60;++n)
        {
            ::Sleep(500);
            if(pEncx->Dongle->State == encx::DS_Active)
            return true;
        }
        return false;
    }
}

And then call it from early on, perhaps in main(..)

encx::ILibraryPtr m_pEncx;
...
if(!FindDongle(m_pEncx))
{
    cout << "Could not find a dongle." << endl;
    return 0;
}

See also Dongle Object and Dongle Free Security.