[Shapelib] Shapelib.dll PInvoke error

Constanze Tschritter Conny3 at gmx.de
Thu Mar 1 04:56:10 PST 2007


Hi all,

Following some hints from a last years post to the shapelib list, I tried

dumpbin /exports shapelib.dll on the x86 version (from the .Net Wrapper) as well as on my ARM version with the result that the shapelib from the x86 version showed 43 functions while my Pocket PC version had appearently 0 functions. No wonder I got the MissingMethodException. 

Daniel de la Cuesta wrote in said last year's posts that he had to change some things in the shapelib source. Here is the link to his thread:

http://lists.maptools.org/pipermail/shapelib/2006-August/000285.html

Keeping his changes in mind I had a look at the shapelib source. I changed the following part, but as I don't now anything about C, I could only hazard a guess. This change was made on line 187 in the shapefil.h. I just changed the first ifdef zu ifndef and that activated the first expression while deactivating the second and the third.


#ifndef SHAPELIB_DLLEXPORT
#  define SHPAPI_CALL __declspec(dllexport)
#  define SHPAPI_CALL1(x)  __declspec(dllexport) x
#endif

#ifndef SHPAPI_CALL
#  define SHPAPI_CALL
#endif

#ifndef SHPAPI_CALL1
#  define SHPAPI_CALL1(x)      x SHPAPI_CALL
#endif


Then I compiled the shapelib again and did another dumpbin /exports, with the result, that I suddenly had 37 functions. Testing the new shapelib.dll I didn't get the MissingMethodException anymore, but an (apparently Native) Exception (0xc0000005, Address:0x0124322c, Reading: 0x00000010), without much description, directly on the device. Apparently the exception code 0xc0000005 is the code for an access violation, which was probably caused by incorrect P/Invoke or incorrect unsafe code usage. Thus I'm back to square one.

Does anybody has any other ideas? And could someone please explain to me, what I actually did change in the C code?

Cheers
Constanze Tschritter

-------- Original-Nachricht --------
Datum: Mon, 26 Feb 2007 13:31:09 -0500
Von: David.Gancarz at ci.orlando.fl.us
An: Shapelib Development <shapelib at lists.maptools.org>
CC: 
Betreff: Re: [Shapelib] Shapelib.dll PInvoke error

> Conny: 
> 
> It's been a while since I did anything with PocketPC, so I don't remember 
> all the differences between .NET on it versus full Windows.  But ... 
> regarding the shapelib.dll -- it dos not need to be included in your 
> Visual Studio project; it just needs to reside in a place the your 
> assembly can find it (typically, the same directory -- which is exactly 
> where the post build event puts it).  Copying it there manually, as you 
> did, accomplishes the same thing.  Shapelib.dll gets called at runtime. It
> does not become part of the .net assembly, so your Visual Studio solution 
> ReadArcShape needs no reference to it at all.  It only needs shapelib.dll 
> at runtime. 
> 
> Secondly, the version of shapelib.dll on MapTools.org is compiled for 
> windows, so you will need to recompile it for Windows CE.  The C/C++ 
> source and VS projects should be out on the Shapelib site.  That should be
> possible since there is nothing exotic or windows-specific about the 
> shapelib c code. 
> 
> Finally, I wouldn't  think you will need to revisit the PInvoke calls in 
> the .net wrapper.  As I recall the Compact Framework supports PInvoke -- 
> although you might want to check the details on that. 
> 
> I hope some of this helps, and good luck.
> 
> David Gancarz
> 
> ----------------------------------------
> Florida has a very broad public records law.  As a result, any written 
> communication created or received by City of Orlando officials and 
> employees will be made available to the public and media, upon request, 
> unless otherwise exempt.  Under Florida law, email addresses are public 
> records.  If you do not want your email address released in response to a 
> public records request, do not send electronic mail to this office. 
> Instead, contact our office by phone or in writing.
> 
> 
> 
> "Constanze Tschritter" <Conny3 at gmx.de> 
> Sent by: shapelib-bounces at lists.maptools.org
> 02/26/2007 01:02 PM
> Please respond to
> Shapelib Development <shapelib at lists.maptools.org>
> 
> 
> To
> shapelib at lists.maptools.org
> cc
> 
> Subject
> [Shapelib] Shapelib.dll PInvoke error
> 
> 
> 
> 
> 
> 
> Dear List,
> 
> When I tried to compile my Pocket PC 2003 project, the result was a 
> MissingMethodException saying the entry point SHPopen within the PInvoke 
> DLL shapelib.dll was not found (I’ve got the german version of Visual 
> studio 8, but this is more or less what it said). 
> 
> Here is the offending code snippet:
> 
> Const STRSHAPEPATH As String = "xxx\\xxx\\strassen.shp"
> 
> Private Sub ReadArcShape()
>         Dim myShapeType As ShapeLib.ShapeType = 
> ShapeLib.ShapeType.PolyLine
>         Dim hShape As IntPtr = New IntPtr()
>         Dim intNum As Integer = 0
>         Dim dblMinBounds As Double() = New Double(1) {0, 0}
>         Dim dblMaxBounds As Double() = New Double(1) {0, 0}
> 
> 'At this point I get the MissingMethodException
> hShape = ShapeLib.SHPOpen(STRSHAPEPATH, "rb")
>> End Sub
> 
> Looking up that error message at the internet I found some possible causes
> for the error but until now, nothing I tried changed anything: 
> 
> ?? 1) Platform:  I downloaded the Shapelib .Net Wrapper by David Gancarz 
> and recompiled the shapelib for Pocket-PC 2003. However I got an error 
> message, when I tried to use the same shapelib files he did. Thus I used a
> windows ce shapelib package which had been assembled by Mateusz Loskot and
> was able to compile those without problems. The only difference I noticed 
> was, that this package contained more files than David Gancarz had used. 
> 
> A test with
> 
> “Dumpbin /header shapefile.dll |find “machine”” resulted in 
>  
>                  “1C0 machine(ARM)” so I must have done something
> right. 
> 
> Afterwards I tried to recompile the Maptools-Project (which is said 
> wrapper project), now with the new shapelib.dll. The only error message I 
> got was that the post build event copy $(ProjectDir)shapelib.dll 
> $(TargetDir) had failed, so I copied it manually into my project folder. 
> I’m not sure if that was the right thing to do, because I don’t know
> the 
> background behind this.
> 
> I added the maptools.dll reference to my project, but got an error, when I
> tried the same with the shapelib (“Unable to add reference to 
> Shapelib.dll”). Do I even have to add that, too, or is sufficient to
> only 
> add the maptools.dll? Well everything seemed to be ok, though, Visual 
> studio recognized the Shapelib functions. 
> 
> ?? 2) Build Action: I set the build action of the shapelib.dll in my 
> project to content, but nothing changed.
> 
> ?? 3) PInvoke: I thought with the .Net wrapper I won’t have to worry
> about 
> PInvoke.(?)
> 
> I don’t know what else to do. I must have missed something, but I
> don’t 
> know what. Maybe someone here can give me a hint what I’m doing wrong. 
> Thank you very much in advance!
> 
> Cheers
> Constanze Tschritter
> 
> PS: Sorry for the long mail. I didn't know how to describe it in a shorter
> way.
> 
> 
> -- 
> Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
> Ideal fur Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
> _______________________________________________
> Shapelib mailing list
> Shapelib at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/shapelib
> 
> 

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: www.gmx.net/de/go/mailfooter/topmail-out



More information about the Shapelib mailing list