Sample of a C# interface C# is a programming language optimized special for the WINDOWS NET Framework |
/************************************************************************/ /* Sample of a C# interface */ /* for some functions of the Dynamic Link Library GeoDLL */ /* The interface must be extended for other functions if necessary. */ /* The interface can be included in the C# source code directly */ /* or can be used as a header file. */ /* */ /* Author: Killet GeoSoftware Ing.-GbR */ /* and Dr. M. Reichert, ARCADIS Consult Freiberg */ /* */ /* In the calling directory of GeoDLL the files geodll32.dll */ /* and geodllbn.bin must be present. */ /* */ /* A lot of changes were accomplished. Unfortunately we did not have */ /* the possibility to compile the interface. If there are contained any */ /* syntax bugs in the source code, the author asks for report! */ /************************************************************************/
######################################################################### ########### Class class_cootrans for encapsulation of GeoDLL ############ #########################################################################
using System; using System.Runtime.InteropServices;
namespace examplesproject {
public class class_cootrans { public class_cootrans() {
}
// Example of the binding of GeoDLL to a .NET project with the // use of the programming language C# // Programming by Dr. M. Reichert, ARCADIS Consult Freiberg // (www.fg.arcadis.de) // August 2003 // Coordinate Transformations with the use of geodll32.dll produced by // Killet GeoSoftware Ing.-GbR, Kempen, Germany (www.killetsoft.de)
// The presence of the files geodll32.dll and geodllbn.bin is // presupposed in a directory, on which in of the $PPATH environment // variable is referred, in the simplest case thus is the system // directory.
// Import of GeoDLL with Platform Invoke. Thus this DLL becomes // totally encapsulated with the class class_cootrans. // Each used DLL function must be imported separately. // To get code identity with the GeoDLL, CharSet=CharSet.Ansi // must be adjusted!
[DllImport("geodll32.dll", EntryPoint="setunlockcode", ExactSpelling=false, CharSet=CharSet.Ansi, SetLastError=true)] private static extern bool setunlockcode(string pszUnlockcode, string pszLicensee);
[DllImport("geodll32.dll", EntryPoint="setcoordarea", ExactSpelling=false, CharSet=CharSet.Ansi, SetLastError=true)] private static extern bool setcoordarea(int nSwitch);
[DllImport("geodll32.dll", EntryPoint="coordtrans", ExactSpelling=false, CharSet=CharSet.Ansi, SetLastError=true)] private static extern bool coordtrans(double nCoordXQ, double nCoordYQ, string pszCoordQ, int nCoordSysQ, int nRefSysQ, out double nCoordXZ, out double nCoordYZ, out string pszCoordZ, int nCoordSysZ, int nRefSysZ, int nStripZ);
internal string unlock() { // Outside interface to the function setunlockcode if(setunlockcode("108154987-123456789","Winzigweich GmbH") && setunlockcode("123454321-471147122","Winzigweich GmbH")) return "ok"; else return "not unlocked"; } // This unlock parameters do not work! // The originals must be acquired from Killet GeoSoftware Ing.-GbR! // Full version: Unlock parameters must be correct at the first input! // Test version: Function may not be called! // The test version without unlocking works per program run a short // time only!
internal string gaussKrueger3DegToGeographic(double easting, double northing, out double longitude, out double latitude) { // Outside interface to the function coordtrans for parameter // configurations coordinated on the respective purpose.
// Transforms the passed easting and northing values of the // Coordinate System 3° Gauss-Krueger, Reference System DHDN // to geographic coordinates with the notation dddmm (degrees, // minutes), Reference System WGS84.
string result; string outstring; // Dimension of the out parameters. They are not existing in the // function calls, because they are here actually not used.
longitude=latitude=0; // Init out values, if it does not come to a computation because // of data input errors.
// Own coordinates range check. if(easting>9999999 || easting<0) { return result="Error on easting input"; } if(northing>9999999 || northing<-9999999) { return result="Error on northing input"; }
setcoordarea(1); // Switch on coordinate range check of the DLL.
if(coordtrans(easting,northing,"",2,0,out longitude, out latitude, out outstring,32,0,0)) result="ok"; else result="Error while calculation";
return result; }
internal string geographicToGaussKrueger3Deg(double longitude, double latitude, int meridianStrip, out double easting, out double northing) { // Outside interface to the function coordtrans for parameter // configurations coordinated on the respective purpose.
// Transforms the passed longitude and latitude values of the // geographic coordinates with the notation dddmm (degrees, minutes), // Reference System WGS84 to the Coordinate System 3° Gauss-Krueger, // Reference System DHDN.
// The parameter meridianStrip determines the strip, for which the // target coordinates are to be calculated.
string result; string outstring; // Dimension of the out parameters. They are not existing in the // function calls, because they are here actually not used.
easting=northing=0; // Init out values, if it does not come to a computation because // of data input errors.
// Own coordinates range check. if(longitude>18000 || longitude<-18000 || ((longitude/100)-Math.Floor(longitude/100))*100>59.99999) { return result="Error on longitude input"; } if(latitude>9000 || latitude<-9000 || ((latitude/100)-Math.Floor(latitude/100))*100>59.99999) { return result=" Error on latitude input"; } if(meridianStrip<0 || meridianStrip>120) { return result="Error on meridian strip input"; }
setcoordarea(1); // Switch on coordinate range check of the DLL.
if(coordtrans(longitude,latitude,"",32,0,out easting, out northing, out outstring,2,0,meridianStrip)) result="ok"; else result=" Error while calculation";
return result; } } } #########################################################################
######################################################################### ########### Calling of functions of the class class_cootrans ########### #########################################################################
private void button3_Click(object sender, System.EventArgs e) { class_cootrans coordinatetransformation = new class_cootrans(); // Instanz of the own class class_cootrans, which encapsulates the // GeoDLL.
double longitude, latitude, easting, northing; // Dimension of the return variables. string result;
// Unlocking the DLL. result=coordinatetransformation.unlock(); MessageBox.Show(result);
// Function call of the own class: Transformation of GK coordinates to // geographic coordinates. result=coordinatetransformation.gaussKrueger3DegToGeographic( 4492252.29,6011118.28,out longitude, out latitude); MessageBox.Show("Result: " + result + " Lat: " + latitude.ToString() + " Lon: " + longitude.ToString() );
// Function call of the own class: Transformation of geographic // coordinates to GK coordinates, projection on the 3rd meridians strip. result=coordinatetransformation.geographicToGaussKrueger3Deg( 1152.87,5413.91,3,out easting, out northing); MessageBox.Show("Result: " + result + " Strip: 3 East: " + easting + " North: " + northing);
// Function call of the own class: Transformation of geographic // coordinates to GK coordinates, projection on the 4th meridian strip. result=coordinatetransformation.geographicToGaussKrueger3Deg( 1152.87,5413.91,4,out easting, out northing); MessageBox.Show("Result: " + result + " Strip: 4 East: " + easting + " North: " + northing);
// Function call of the own class: Transformation of geographic // coordinates to GK coordinates, projection on the 5th meridian strip. result=coordinatetransformation.geographicToGaussKrueger3Deg( 1152.87,5413.91,5,out easting, out northing); MessageBox.Show("Result: " + result + " Strip: 5 East: " + easting + " North: " + northing); } #########################################################################
|