Here's some sample code snippets of how to accomplish this task of
calling functions in the TomTom SDK 6 in a .NETCF application
In your native wrapper, lets say we want to wrap TTSDK function:
- GetApplicationVersion(TError * err, TVersion* ver)
- FlashMessage(TError * err, char * msg, int ms)
[C++ CODE]
#include "sdkconstants.h"
#include "TomTomAPI.h"
#include "TomTomGoFileLayer.h"
#include "TTN6SDK.h"
#define CLIENT_NAME "client"
CTomTomAPI::TError err;
int res = 0;
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) int TTN_GetApplicationVersion( int*
iError, LPTSTR szVersion, int *iBuildNumber )
{
MTomTomCommunicationLayerInterface *comms =
DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
CTomTomAPI api(*comms);
CTomTomAPI::TVersion version;
res = api.GetApplicationVersion(&err, &version);
*iError = err.iError;
TCHAR str[16];
_stprintf(str, TEXT("%S"), version.iVersion);
lstrcpy( szVersion, (LPTSTR)str );
*iBuildNumber = version.iBuildNumber;
delete comms;
return res;
}
extern "C" __declspec(dllexport) int TTN_FlashMessage( int* iError,
char* aMessage, int aMilliSeconds )
{
char message[256];
sprintf(message, "%S", aMessage);
MTomTomCommunicationLayerInterface *comms =
DEFAULT_TRANSPORTATION_LAYER(CLIENT_NAME,2005,TOMTOM_TCPIP_PORT);
CTomTomAPI api(*comms);
res = api.FlashMessage(&err, message, aMilliSeconds);
*iError = err.iError;
delete comms;
return res;
}
And now to access the native wrapper DLL from .NETCF
[C# CODE]
[DllImport("TTSDK6.dll", EntryPoint="TTN_GetApplicationVersion")]
static extern int TTN_GetApplicationVersion(ref int iError,
StringBuilder szVersion, ref int iBuildNumber);
[DllImport("TTSDK6.dll", EntryPoint="TTN_FlashMessage")]
static extern int TTN_FlashMessage(ref int iError, string aMessage,
int aMilliseconds);
public struct TVersion
{
public string iVersion;
public int iBuildNumber;
}
public static TVersion GetApplicationVersion()
{
TVersion version = new TVersion();
StringBuilder szVersion = new StringBuilder();
int iBuildNumber = 0;
if (0 != Native.TTN_GetApplicationVersion(ref iError, szVersion, ref
iBuildNumber))
throw new Exception("An Unexpected Error occured while trying to
retrieve Application Version information...");
else {
version.iVersion = szVersion.ToString();
version.iBuildNumber = iBuildNumber;
}
return version;
}
public static void FlashMessage(string aMessage, int aMilliseconds)
{
if (0 != Native.TTN_FlashMessage(ref iError, aMessage,
aMilliseconds)) {
throw new Exception("An Unexpected Error occurred while trying to
Flash a Message ('" + aMessage + "') on the Navigator screen...");
}
}
By the way, the version 6 of the TomTom SDK is very very very buggy!
TomTom has already released 2 versions of the SDK 6, but it still
doesn't work very well. This is actually very typical for the TomTom
SDK. I wish they would do something about these problems...
Regards,
Christian R. Helle