[Gdal-dev] C# Bindings

Simon Perkins sy at perkins.net
Thu Nov 2 00:58:13 EST 2006


Hi,

I've just tried to use the GDAL C# SWIG bindings on Windows for the 
first time today and ran into a couple of problems. I'm using Visual 
Studio 2005 Express with SWIG 1.3.29.

I compiled GDAL and then typed:

 > cd swig\csharp
 > nmake /f makefile.vc interface
 > nmake /f makefile.vc
 > nmake /f makefile.vc test

The first two makes seem to work OK. The final test throws an exception 
and prints the following:

Unhandled Exception: System.TypeInitializationException: The type 
initializer fo
r 'OGR.ogr' threw an exception. ---> System.TypeInitializationException: 
The typ
e initializer for 'OGR.ogrPINVOKE' threw an exception. ---> 
System.TypeInitializ
ationException: The type initializer for 'SWIGExceptionHelper' threw an 
exceptio
n. ---> System.DllNotFoundException: Unable to load DLL 'gdal_ogr_wrap': 
The spe
cified module could not be found. (Exception from HRESULT: 0x8007007E)

...

As with so many VS 2005 problems, this turned out to be a manifest 
issue. Inserting a few lines into the makefile.vc to embed the manifest 
files into the DLLs fixed this. I'll check in these changes if nobody 
objects. I suspect that similar lines need to be added for other SWIG 
languages on windows if anyone else feels like doing that...

However, I'm still a little unclear about exactly how to use the SWIG 
libraries. My primary interest is in the GDAL RasterIO functions, which 
seem to be present as Band.ReadRaster() and Band.WriteRaster(). The C# 
function signatures for these are:

public int ReadRaster(int xoff, int yoff, int xsize, int ysize, 
SWIGTYPE_p_int buf_xsize, SWIGTYPE_p_int buf_ysize, SWIGTYPE_p_int buf_type)
 
public int WriteRaster(int xoff, int yoff, int xsize, int ysize, int 
buf_len, SWIGTYPE_p_int buf_xsize, SWIGTYPE_p_int buf_ysize, 
SWIGTYPE_p_int buf_type)

These functions seem to be missing some arguments. In particular, how do 
you pass in the buffer where data is to be read from / written to? What 
are those SWIGTYPE_P_int types? Can anyone give me an example of how to 
use these functions? Do they work? If not can anyone give me some 
pointers on fixing them?

Cheers,

Sy




More information about the Gdal-dev mailing list