[Shapelib] I have the dll compiled but know I have to make it
works in the emulator.
mateusz at loskot.net
Mon Aug 28 14:57:17 EDT 2006
Daniel de la Cuesta wrote:
> Don´t worry about my previous question because It´s solved. I have been
> trying and I got the solution.
> I had to change somethings in the C code:
> 1.- I had to define DLL export:
> #define DLL_EXPORT __declspec(dllexport)
But there is already such definition in shapefil.h:
#define SHPAPI_CALL __declspec(dllexport)
> 2.- Declare each method that is accesed from outside lik
> DLL_EXPORT void Method ()
All functions in shpopen.c are qualified with SHPAPI_CALL.
I'm not sure I understand where is the problem.
> Now when i do: dumpbin shapelib.dll /EXTERNS I got the extern methods.
Another option is to export functions using DEF file:
> I am trying a test app that uses shapelib.dll and I have a problem. I
> want to create a new DBF. So I use the DBFCreate function. Then i add
> some fields. I do something like that:
> IntPtr hDbf = ShapeLib.DBFCreate(FILENAME);
> int iRet = ShapeLib.DBFAddField(hDbf, "id",
> ShapeLib.DBFFieldType.FTInteger, 5, 0);
> iRet = ShapeLib.DBFAddField(hDbf, "texto",
> ShapeLib.DBFFieldType.FTString, 10, 0);
> iRet = ShapeLib.DBFAddField(hDbf, "double",
> ShapeLib.DBFFieldType.FTDouble, 11, 0);
> iRet = ShapeLib.DBFAddField(hDbf, "boolean",
> ShapeLib.DBFFieldType.FTLogical, 5, 0);
> Everything is Ok, I get a dbf archive with the fields I want. Well,
> almost everything because I only get the first letter of each field and
> the first letter of the file.
> For example: I get a "t.dbf" file (instead of "test.dbf").
> I want a field called "stringField" but I only get a field called "s"
> I want a field called "doubleField" but I only get a field called "d"
> What´s happening? Anyone know something about that?
Have you specified appropriate marshaling for strings?
Shapelib offers C API. C API takes strings as pointers character array.
The array is passed by pointer to the first character in the array.
So, you have to tell .NET framework how it should "convert" string
parameter of .NET string type to C/C++ type of char*.
Also note, .NET works with Unicode string (wide-char sring),
char* points to single-byte string, so you need to marshal data
when passing across managed and unmanaged Worlds boundaries.
Read references I listed in my previous post.
Search in MSDN for attribute MarshalAs
More information about the Shapelib