[Gdal-dev] Any tips for VB .NET?
Paul, Michael
michael.paul at tao.es
Tue Mar 21 05:31:12 EST 2006
Hi,
I think that there at least three possibilities to access GDAL from witin
VB.Net:
- you may reference the wrapper assembly DLLs generated by the GDAL SWIG
interfaces, these SWIG interfaces are included within the GDAL sources.
Instead of having to declare functions to access native code, these wrapper
exposes classes to any .Net language (C#, VB.Net, Delphi, ..). If you are
new to SWIG and .Net this may be the hard way to follow,
- there also exists a less official GDAL wrapper implemented in C#, Simon
Perkins published a few months ago a Visual Studio solution, which is ready
to be used (including VB.Net). I think it is called gdal_csharp. It also
exposes .Net classes, which are wrapping the GDAL C API,
- if you prefer so, you may also declare yourself all the necessary function
calls within VB.Net to access the C API. What I have done to know correct
syntax is invoking Lutz Roeder's Reflector upon the compiled wrapper IL
code. Output is stated at the end of message. I've not tested the output,
but it seems OK.
Both SWIG wrappers and C# wrapper are less tested and functional incomplete.
Nevertheless, for most things you'll want to do from within VB.Net it will a
good starting point.
Kind Regards,
Michael.
=============================================
Reflector output:
Friend Class InterOp
' Methods
Shared Sub New()
Public Sub New()
Friend Shared Function CPLGetLastErrorMsg() As String
<DllImport("gdal_fw.dll", EntryPoint:="CPLGetLastErrorMsg")> _
Private Shared Function CPLGetLastErrorMsgExt() As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALAllRegister()
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALClose(ByVal hDriver As HandleRef)
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALCreate(ByVal hDriver As HandleRef,
<MarshalAs(UnmanagedType.LPStr)> ByVal filename As String, ByVal width As
Integer, ByVal height As Integer, ByVal nBands As Integer, ByVal type As
DataType, ByVal options As HandleRef) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALCreateCopy(ByVal hDriver As HandleRef,
<MarshalAs(UnmanagedType.LPStr)> ByVal filename As String, ByVal hDataset As
HandleRef, ByVal bStrict As Integer, ByVal options As HandleRef, ByVal
progressFn As HandleRef, ByVal progressData As HandleRef) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALDestroyDriverManager()
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetAccess(ByVal hDataset As HandleRef) As
Integer
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetDatasetDriver(ByVal hDataset As
HandleRef) As IntPtr
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetDriverShortName",
CharSet:=CharSet.Ansi)> _
Private Shared Function GDALGetDatasetDriverExt(ByVal hDataset As
HandleRef) As IntPtr
Friend Shared Function GDALGetDescription(ByVal hDriver As HandleRef)
As String
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetDescription",
CharSet:=CharSet.Ansi)> _
Private Shared Function GDALGetDescriptionExt(ByVal hDriver As
HandleRef) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetDriver(ByVal iDriver As Integer) As
IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function
GDALGetDriverByName(<MarshalAs(UnmanagedType.LPStr)> ByVal pszName As
String) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetDriverCount() As Integer
Friend Shared Function GDALGetDriverLongName(ByVal hDriver As
HandleRef) As String
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetDriverLongName",
CharSet:=CharSet.Ansi)> _
Private Shared Function GDALGetDriverLongNameExt(ByVal hDriver As
HandleRef) As IntPtr
Friend Shared Function GDALGetDriverShortName(ByVal hDriver As
HandleRef) As String
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetGeoTransform(ByVal hDataset As
HandleRef, <In, Out> ByVal Transform As Double()) As CPLErr
Friend Shared Function GDALGetMetadata(ByVal hDataset As HandleRef,
ByVal domain As String) As Dictionary(Of String, String)
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetMetadata")> _
Private Shared Function GDALGetMetadataExt(ByVal hDataset As
HandleRef, <MarshalAs(UnmanagedType.LPStr)> ByVal domain As String) As
IntPtr
Friend Shared Function GDALGetMetadataItem(ByVal hDataset As
HandleRef, ByVal key As String, ByVal domain As String) As String
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetMetadataItem")> _
Private Shared Function GDALGetMetadataItemExt(ByVal hDataset As
HandleRef, <MarshalAs(UnmanagedType.LPStr)> ByVal key As String,
<MarshalAs(UnmanagedType.LPStr)> ByVal domain As String) As IntPtr
Friend Shared Function GDALGetProjectionRef(ByVal hDataset As
HandleRef) As String
<DllImport("gdal_fw.dll", EntryPoint:="GDALGetProjectionRef",
CharSet:=CharSet.Ansi)> _
Private Shared Function GDALGetProjectionRefExt(ByVal hDataset As
HandleRef) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterBand(ByVal hDataset As HandleRef,
ByVal index As Integer) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterColorInterpretation(ByVal hBand As
HandleRef) As Integer
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterCount(ByVal hDataset As HandleRef)
As Integer
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterXSize(ByVal hDataset As HandleRef)
As Integer
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALGetRasterYSize(ByVal hDataset As HandleRef)
As Integer
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALOpen(<MarshalAs(UnmanagedType.LPStr)> ByVal
pszFilename As String, ByVal eAccess As Access) As IntPtr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALRasterIO(ByVal hBand As HandleRef, ByVal
flag As RWFlag, ByVal xOff As Integer, ByVal yOff As Integer, ByVal xSize As
Integer, ByVal ySize As Integer, ByVal data As IntPtr, ByVal bufXSize As
Integer, ByVal bufYSize As Integer, ByVal type As DataType, ByVal
pixelStride As Integer, ByVal lineStride As Integer) As CPLErr
<DllImport("gdal_fw.dll")> _
Friend Shared Function GDALSetGeoTransform(ByVal hDataset As
HandleRef, <In, Out> ByVal Transform As Double()) As CPLErr
<DllImport("gdal_fw.dll")> _
Friend Shared Sub GDALSetMetadataItem(ByVal hDataset As HandleRef,
<MarshalAs(UnmanagedType.LPStr)> ByVal key As String,
<MarshalAs(UnmanagedType.LPStr)> ByVal value As String,
<MarshalAs(UnmanagedType.LPStr)> ByVal domain As String)
' Fields
Private Const gdalDll As String = "gdal_fw.dll"
End Class
-----Mensaje original-----
De: gdal-dev-bounces at lists.maptools.org
[mailto:gdal-dev-bounces at lists.maptools.org] En nombre de Holywhippet
Enviado el: martes, 21 de marzo de 2006 4:53
Para: gdal-dev at lists.maptools.org
Asunto: [Gdal-dev] Any tips for VB .NET?
I'd like to try and use GDAL from withing VB .NET if I can. In theory I can
use "Declare Function" to link to the GDAL dll. However, I tried calling
GDALOpen and assigning the output to a generic Object. I get an error saying
the function value can't be returned as a variant. I'm not sure if this path
is possible in general. Has anyone gotten GDAL to run using VB .NET?
--
View this message in context:
http://www.nabble.com/Any-tips-for-VB-.NET--t1315468.html#a3506881
Sent from the GDAL - Dev forum at Nabble.com.
_______________________________________________
Gdal-dev mailing list
Gdal-dev at lists.maptools.org
http://lists.maptools.org/mailman/listinfo/gdal-dev
More information about the Gdal-dev
mailing list