Hi,
I’m attempting to use the a C library from C# code. The method that I would like to use has the following prototype:
long Convert_Geodetic_To_MGRS (double Latitude,
double
Longitude,
long Precision,
char* MGRS);
My C# code for importing the library is as follows:
[DllImport("geotrans2.dll",
EntryPoint="#168", CallingConvention=CallingConvention.Cdecl)]
private static extern long Convert_Geodetic_To_MGRS
(double Latitude,double
Longitude,long
Precision,StringBuilder
MGRS);
And here is my C# code where I call the method:
double Latitude = 1;
double Longitude = 2;
int Precision = 5;
StringBuilder str = new StringBuilder(256);
long ret = Convert_Geodetic_To_MGRS (Latitude, Longitude,
Precision,str);
Besides StringBuilder for the type of the MGRS parameter
I have also tried:
1) ref StringBuilder
2) out StringBuilder
3) string
4) ref string
5) out string
6) char[]
7) ref char[]
8) out char[]
9) byte[]
10) ref byte[]
11) out byte[]
Nothing seems to work, the MGRS parameter is always NULL upon entry to the DLL function.
According to the .NET help files, StringBuilder should be marshaled as a [in,out] char*...no clue why it is NULL upon entry to the DLL function.
Any help would be greatly appreciated.
Thanks,
Russ