[Shapelib] SHPOpen (and SHPCreate) only recognizes the first letter of filename

David.Gancarz at ci.orlando.fl.us David.Gancarz at ci.orlando.fl.us
Wed Jul 18 08:33:40 EDT 2007


Tom:

As I recall, Pocket PC uses a unicode charset.  The chars managed in 
shpopen.c are 1 byte with char arrays null-terminated.  So, when you pass 
a string "test.shp", the unicode version ( 2-byte characters) of test.shp 
is t 0x00 e 0x00 s 0x00 t 0x00 . 0x00 s 0x00 h 0x00 p 0x00.  The ascii 
version is test.shp 0x00.  The c code sees t 0x00 and assumes it has 
reached the end of the char array since there exists a null terminator 
(0x00).  My guess is you are going to need to manually switch back and 
forth between 1-byte and 2-byte string chars during calls to the c dll and 
the PocketPC file system to get this to work for you; i.e., fake out the 
system by packing the non-null chars into a 2-byte unicode string  and 
pass that pseudo-unicode string to shpopen.  Writing the file out to the 
PocketPC file system is going to be a problem, though, because the 
filenames are going to be gibberish.  Somehow, you'll need to convert them 
back to unicode that correctly represents the intended filenames.

The alternative is to make some nontrivial mods to the c source to make it 
unicode.  If it were me, first I'd play around with the (inelegant) 
workaround, above.

Btw, I expect CharSet.Auto is equivalent to CharSet.Unicode on PocketPC. 
It is not surprising that CharSet.Ascii fails, since PocketPC is strictly 
unicode.

Hope this helps. 

David Gancarz, P.E.
Systems Development Manager
City of Orlando
400 S Orange Ave
Orlando, FL 32802
(407) 246-3062
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.



Tom Kazimiers <2voodoo at gmx.de> 
Sent by: shapelib-bounces at lists.maptools.org
07/18/2007 07:04 AM
Please respond to
Shapelib Development <shapelib at lists.maptools.org>


To
shapelib at lists.maptools.org
cc

Subject
[Shapelib] SHPOpen (and SHPCreate) only recognizes the first letter     of 
filename






Hi there,

after struggleing some days around with getting Shapelib compiled for
Pocket PC 2003 and Windows CE I finally succeeded with this and came up
to the .Net wrapper I found on the net which is quite helpfull as I do
not need to care about all the P/Invoke stuff out of C#.
This worked after some work, too but for my last problem I did not find
any solution.

If I want to open or create a file with SHPOpen and SHPCreate only the
first letter of the given filename is recognized. Furthermore if I have
a filepair "t.shx" and "t.shp" and want to open "test" - then t is opened.

First of all I had to change something in the wrapper - namely the
charset as Ascii (which was written there) was not found on my computer
so I set it to auto:

[DllImport("Shapelib.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SHPOpen(string szShapeFile, string szAccess);

Could this already be a problem?

Now I want to open a file:

IntPtr hShp = ShapeLib.SHPOpen("test", "rb");

which succeeds if there is a file "t.shx" and "t.shp", but not if there
are the files "test.shx" and "test.shp".
With the t-files I can read everything and work with them, but I want
full filenames. The problem gets even worser if I want to use
directories. (all the files mentioned above where saved in "root") as
SHPOpen can't handle this. The same is true for creation of 
shapefile-pairs.

I could image that there is a charset problem as I changed this in the
MapTools.cs, but I don't know how to solve this.

Do you have any ideas or hints?

Thank you in advance.
Tom


_______________________________________________
Shapelib mailing list
Shapelib at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/shapelib

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.maptools.org/pipermail/shapelib/attachments/20070718/c74d2103/attachment.html


More information about the Shapelib mailing list