TomTom Navigator & PInvoke

  • Thread starter Thread starter Morten
  • Start date Start date
M

Morten

Hello,

I'm trying to develop a C# application that communicates with TomTom
Navigator, but I'm having no luck. I've been trying to connect using PInvoke
like this:

----------------
using System.Runtime.InteropServices;
...
[DllImport("TTNCom.dll")]
extern static int GetNavigatorVersionInfoV01();
...
try
{
int GetVer;
GetVer = GetNavigatorVersionInfoV01();
}
catch (MissingMethodException)
{
MessageBox.Show ("Error - cannot call Method.");
}
 
You haven't told us what happened when you did that. Did you get the wrong
value back? A MissingMethodException? Give us a hint!

Paul T.
 
I'm sorry,

Yes I'm getting the MissingMethodException, but from what I've read this
could mean several things so I'm confused as what to do. I just want to hear
if anyone else have successfully tried to use PInvoke to connect to the
TomTom SDK?

Best Regards,
Morten

Paul G. Tobey said:
You haven't told us what happened when you did that. Did you get the wrong
value back? A MissingMethodException? Give us a hint!

Paul T.

Morten said:
Hello,

I'm trying to develop a C# application that communicates with TomTom
Navigator, but I'm having no luck. I've been trying to connect using PInvoke
like this:

----------------
using System.Runtime.InteropServices;
..
[DllImport("TTNCom.dll")]
extern static int GetNavigatorVersionInfoV01();
..
try
{
int GetVer;
GetVer = GetNavigatorVersionInfoV01();
}
catch (MissingMethodException)
{
MessageBox.Show ("Error - cannot call Method.");
}
 
Hi Morten,

For more information on the MissingMethodException see the .NET Compact
Framework FAQ. Examination of the function prototype that you are calling
suggests that the problem maybe with the location of the DLL (Windows or
executing assembly directory is required) or the function name may be
mangled. Of course the issue could be something else too, it's hard to say
without the Tom Tom Navigator software. Check out the MissingMethodException
FAQ item here:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx#6.15

The TomTom web site mentions that TomTom Navigator SDK 2 is not compatible
with the .NET Compact Framework; although it doesn't indicate why this is
the case:
http://www.tomtom.com/support/ce/navigator_sdkqa.php?Language=4

Apparently Pitsch & Pohler have created a wrapper though:
http://ttncf.pp-p.com/

Good luck.
j
--
Jonathan Wells
Product Manager
..NET Compact Framework
Check out the .NET Compact Framework FAQ at:
http://msdn.microsoft.com/mobility/prodtechinfo/devtools/netcf/FAQ/default.aspx

This posting is provided "AS IS" with no warranties, and confers no rights.

Morten said:
I'm sorry,

Yes I'm getting the MissingMethodException, but from what I've read this
could mean several things so I'm confused as what to do. I just want to hear
if anyone else have successfully tried to use PInvoke to connect to the
TomTom SDK?

Best Regards,
Morten

Paul G. Tobey said:
You haven't told us what happened when you did that. Did you get the wrong
value back? A MissingMethodException? Give us a hint!

Paul T.

Morten said:
Hello,

I'm trying to develop a C# application that communicates with TomTom
Navigator, but I'm having no luck. I've been trying to connect using PInvoke
like this:

----------------
using System.Runtime.InteropServices;
..
[DllImport("TTNCom.dll")]
extern static int GetNavigatorVersionInfoV01();
..
try
{
int GetVer;
GetVer = GetNavigatorVersionInfoV01();
}
catch (MissingMethodException)
{
MessageBox.Show ("Error - cannot call Method.");
}
 
Hi Morten!

I think we have a lot of experience with this.
We got it by building TTNCF (http://tttncf.pp-p.com) :-))

The bigest problem for you is name decoration!!!

So since the real definition is
static int GetNavigatorVersionInfoV01(TNavVersionInfoV01& aVersionInfo);

And this is a static member function of the class CTomTomNavigatorCom.

So have a look at the lib (or the dll - the lib is better to read) and find
out:
GetSdkVersionInfoV01@CTomTomNavigatorCom@@SAHAAUTNavVersionInfoV01@1@@Z

That is the signature of the function.
If you are not familiar with C++ Name decoration.....
The exported function name builds from
A.) the function name
B.) the class
C.) the parameters
D.) the returntype

Lets take a short look at
BringNavigatorToForeground@CTomTomNavigatorCom@@SAHXZ
or
SwitchToNavigatorView@CTomTomNavigatorCom@@SAHXZ

Both off them take no parameter - and return an int!

static INT AddPoi( LPCTSTR aFilename, long aLongitude, long aLatitude,
LPCTSTR aName, LPCTSTR anId );
looks like:
AddPoi@CTomTomNavigatorCom@@SAHPBGJJ00@Z

and
static INT DeleteClosestPoi( LPCTSTR aFilename, long aLongitude, long
aLatitude );
DeleteClosestPoi@CTomTomNavigatorCom@@SAHPBGJJ@Z

So from this simple examples you can see that JJ stands for the two longs in
the functions.

static INT MoveClosestPoi( LPCTSTR aFilename, long aLongitude, long
aLatitude, long aNewLongitude, long aNewLatitude );
looks like
MoveClosestPoi@CTomTomNavigatorCom@@SAHPBGJJJJ@Z

You see - four time J - there are 4 longs!!!!

So what you will have to do - use the decorated names in your PInvokes.
And alias them to get a "useable" name for the code!

Other problems are the things around GFFile (Registred window messages and
so on).

What we also found tricky is the GPSDriver support in the SDK!
This is documented in the full SDK (not in the downloadable documentation).
There are "LoadLibrary" "GetProcAdress" and other funny things to do!

In our TTNCF version 1.0 we do not support it, but we have a version 1.1
where we do.

A last tip: you can open the TTNCom.lib direct in VS (as a binary - hex
view); there you will find
the decorated names.

HTH

Manfred
 
Hi Jonathan!

I think our replies crossed!
You are right with "mangled names".
The problem in this case is the name decoration,
since it is a C++ dll!

By the way - we built TTNCF :-)
And we built it excatly because of the problems with interop and TTNCom!

Manfred
 
Hi,

I would like to thank you both for your kind and professional help, I really
appreciate it!
I will now have another go at it, and if it still fails I will know that I
have the TTNCF "safety net" to help me out!
Thank you again!

Best regards,
Morten
 
Hi Morten!

A last hint for you - there a rules for name mangeling.
So if you dont like to "read" binary views of C++ dlls,
you can find a schema behind this.

On the other hand - it just a couple of functions....
so the "read dll way" will work.
And by the way TTNCom does no "bad memory management things".
You (almost) alwasy reserve the memory for a structure - and hand that
struture
to the function.

Much easyer than com and the other things like this!

Only GPSDriver support is a little tricky!

Let us know if you are successfull - and how you managed it!

Manfred
 
OK,

I feel that I'm getting closer to solving this problem because of your great
help Manfred, but there still seems to be a problem with my code
("MissingMethodExeption" - error):

using System.Runtime.InteropServices;
...
try
{
int ShowTT = BringNavigatorToForeground();
}
catch (MissingMethodException)
{
MessageBox.Show ("Error - cannot call Method.");
}

[DllImport("TTNCom.dll", EntryPoint =
"BringNavigatorToForeground@CTomTomNavigatorCom@@SAHXZ")]
extern static int BringNavigatorToForeground();

Do you have any more tips for me, please? :)

Best regards,
Morten
 
Hi Morten!!

Since our approach to solve this things is very different from yours.....I
can only give you
some furthermore hints - not sure if this works!!!

These "functions" are static methods of a class CTomTomN..... in the dll.
The dll exports the class - and from that class you can call that function.
It's something like getting a "function pointer array" and calling a member
of that array!!

Maybe reading about C++ and "classes in DLLs" could help!!

Manfred
 
Hi Manfred,

I finally figured it out!
The entrypoint was set to:
BringNavigatorToForeground@CTomTomNavigatorCom@@SAHXZ
when it should be:
?BringNavigatorToForeground@CTomTomNavigatorCom@@SAHXZ

I figured it out after doing a dumpbin /exports on the TTNCom.dll

Thank you for all your help!!

Best regards,
Morten
 
Back
Top