Home · All Commands · First Steps · Tutorials · Demos · FAQ
 

Remote Interface Documentation

GeoCoding Example

Introduction

This Example will show you how to get a coordinate from an address string. This time, we do not only send a message, we also have to pass data (the address string) to the navigator and we will read the result. Every command that can read or write data has it's own functions to do this and a struct in which the data is stored.
In case of the SearchAddress-Command they are called:

First, we create and fill the struct with the search string:

    RI_CSearchAddress data;
    wcscpy(data.m_address, L"D,76131,Karlsruhe,Stumpfstrasse,1");

Then, we write the data into the shared memory:

    LPARAM id = GetUniqueID();
    LRESULT sharing_ret = RI_SearchAddress_WriteData( id, data );

No we can send the message to search the address. The id for reading and writing the data the will be also used for RI_MESSAGE:

    if ( RI_MESSAGE( RI_MESSAGE_SEARCHADDRESS, GetSafeHwnd(), id ) == RI_NOERROR )
    {
    }

After sending the request, we wait in windowproc for the returned answer.
The wParam-value will indicate the error code.

    if ( message == RI_MESSAGE_SEARCHADDRESS )
    {
        if ( (LRESULT)wParam == RI_NOERROR )
        {
            RI_CSearchAddress data;
            LRESULT read_suc = RI_SearchAddress_ReadData( lParam, data );
        }
    }

If the message is the one we sent, we read the data with RI_SearchAddress_ReadData().
The lParam value is the id we sent before, the struct will be filled with the result.

The complete sequence:

#define USE_LOADLIBRARY
#include "TNSRemoteInterfaceDll.h"

LPARAM GetUniqueID()
{
    //generate unique ID
    static LPARAM id = 0;
    if (++id == 0) ++id; // do not use 0 !!!!!
    return id;
}

inline LRESULT RI_MESSAGE( const UINT request, HWND h_client, LPARAM id )
{
    //check if RI handle is valid
    if ( !IsWindow( RI_GetTNS() ) ) 
        return RI_NAVIGATIONNOTACTIVE;
    //send the request
    PostMessage( RI_GetTNS(), request, WPARAM(h_client), id );
    return RI_NOERROR;
}

LRESULT CDlgMFC_GeoCoding::WindowProc ( UINT  message , WPARAM  wParam , LPARAM  lParam )
{
    //check messages for answer from RI
    if ( message == RI_MESSAGE_SEARCHADDRESS )
    {
        if ( (LRESULT)wParam == RI_NOERROR )
        {
            //SearchAddress succeeded. errorcode (0)
            //get the data from the shared memory
            RI_CSearchAddress data;
            LRESULT read_suc = RI_SearchAddress_ReadData( lParam, data );
            if ( read_suc != RI_NOERROR )
                //...data was overwritten. errorcode (-2)<BR>
            else
            {
                TRACE(TEXT("X-Koordinate: %i\n"), data.m_mercator_x);
                TRACE(TEXT("Y-Koordinate: %i\n"), data.m_mercator_y);
                TRACE(TEXT("Result Address: %s\n"), data.m_result_address);
            }
        }
        else if ( (LRESULT)wParam == RI_NOTAV )
        {
            //SearchAddress has no street found. errorcode (19)
            //get the data from the shared memory
            RI_CSearchAddress data;
            LRESULT read_suc = RI_SearchAddress_ReadData( lParam, data );
            if ( read_suc != RI_NOERROR )<BR>
                //...data was overwritten. errorcode (-2)
            else
            {
                TRACE(TEXT("X-Koordinate: %i\n"), data.m_mercator_x);
                TRACE(TEXT("Y-Koordinate: %i\n"), data.m_mercator_y);
                TRACE(TEXT("Result Address: %s\n"), data.m_result_address);
            }
        }
        else
            //SearchAddress not succeeded. errorcode (-1)
    }
    return CDialog::WindowProc( message, wParam, lParam );
}

void CDlgMFC_GeoCoding::foo()
{
    //*** copy data ***
    RI_CSearchAddress data;
    wcscpy(data.m_address, L"D,76131,Karlsruhe,Stumpfstrasse,1");

    //*** write data in shared memory ***
    LPARAM id = GetUniqueID();
    LRESULT sharing_ret = RI_SearchAddress_WriteData( id, data );
    if ( sharing_ret != RI_NOERROR )
        return;
    if ( RI_MESSAGE( RI_MESSAGE_SEARCHADDRESS, GetSafeHwnd(), id ) == RI_NOERROR )
        //message sending succeeded
    else
        //navigation software not running
}

© PTV AG 2011 Generated on Fri Oct 14 2011 10:17:32 for RI by doxygen 1.7.1