Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
Hello All
I have a problem where I have to figure out the Magnetic Variation of a point.
Here's the background. I want to use the industry standard for figuring out Magnetic Variation. It's located at here. I've downloaded the file and within it has a program called WMM.exe. This program does exactly what I want. You put a Lat, Long and height and then you push calculate and then it figures out the declination.
So, within the zip file is also what I believe is the code to this exe but the problem is that it's in C++. Is there a way to use the code in a C# project? I want to pass at least 4 variables to it, Lat, Long, Height and Date. How do I do this?
There's two parts to this. The first is getting the declination and then the next is that I have a whole list of points within an Access table that looks like this - Lat, Lon, Height, Date, MagVar
Has anyone ever done something like this? Also, how do I add a C++ project with my C# project?
Posted 1-Feb-13 17:13pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Depends on what type of C++ it is: if it is CLR code, then you can just add it as a reference and call it's methods as if they were C# - the framework will sort it all out for you.
If it is native C++ code, then you may be able to use it, but you will have to read up on P/INVOKE and will have to find out what functions the C++ code exposes.
You can add a C++ CLR project to your solution very easily: Right click the solution and select "Add...Existing Project..." then follow the dialogs from there.
The other alternative is to use it as is: you can execute it as a process and it may be possible to provide it with command line arguments to make it work without it's GUI (which I assume it has from your "push calculate" comment.
There is another option: rewrite the C++ code which does the work in C# (and ignore the GUI if you don't need it).
Sorry, but we can't give a definitive answer based on that little info! Laugh | :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 8,488
1 OriginalGriff 6,516
2 Peter Leow 3,647
3 Zoltán Zörgő 3,416
4 Richard MacCutchan 2,397

Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 2 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100