GRFTool (grf.dll -> vb.net)

Wrote new code? Fixed a bug? Want to discuss technical stuff? Feel free to post it here.

Moderator: Moderators

Message
Author
johnny
Noob
Noob
Posts: 9
Joined: 14 Apr 2008, 04:46

GRFTool (grf.dll -> vb.net)

#1 Post by johnny »

Hi,

anyone got a small tutorial how to use the grf.dll in vb.net?

Code: Select all

    ' GRF Types
    Enum GrfErrorType
        GE_SUCCESS
        GE_BADARGS
        GE_INVALID
        GE_CORRUPTED
        GE_NSUP
        GE_NOTFOUND
        GE_INDEX
        GE_ERRNO
        GE_ZLIB
        GE_ZLIBFILE
        GE_NODATA
        GE_BADMODE
        GE_NOTIMPLEMENTED
    End Enum

    Public Structure GrfError
        Dim type As GrfErrorType
        Dim line As Integer
        Dim name As String
        Dim func As String
        Dim extra As Int64
    End Structure

    Public Structure GrfFile
        Dim compressed_len_aligned As Integer
        Dim compressed_len As Integer
        Dim real_len As Integer
        Dim flags As Int16
        Dim hash As Integer
        Dim name As String
        Dim data As String
    End Structure

    Public Structure Grf
        Dim filename As String
        Dim len As Integer
        Dim type As Integer
        Dim version As Integer
        Dim nfiles As Integer
        Dim files() As GrfFile
        Dim first As GrfFile
        Dim last As GrfFile

        Dim allowCrypt As Int16
        Dim f As System.IO.File
        Dim allowWrite As Int16
        Dim zbuf As Object ' void
    End Structure

    Public Structure GrfOpenCallback
        Dim file As GrfFile
        Dim mError As GrfError
    End Structure

    ' GRF Library (grf.dll) functions
    Public Declare Function GrfOpen Lib "grf.dll" Alias "grf_open" (ByVal fname As String, ByVal mode As String, ByVal mError As GrfError, ByVal callback As GrfOpenCallback) As Grf
    'Public Declare Function GrfOpen Lib "grf.dll" Alias "grf_open_callback" (ByVal fname As String, ByVal mode As String, ByVal mError As GrfError, ByVal callback As IntPtr) As Grf
    Public Declare Function GrfExtract Lib "grf.dll" Alias "grf_extract" (ByVal grf As Grf, ByVal grfname As String, ByVal file As String, ByVal mError As GrfError) As Integer
    Public Declare Function GrfClose Lib "grf.dll" Alias "grf_close" (ByVal grf As Grf)
    Public Declare Function GrfFree Lib "grf.dll" Alias "grf_free" (ByVal grf As Grf)

Sub Main()
        Try
            Dim myGrf As Grf
            Dim err As GrfError
            Dim cb As GrfOpenCallback
            myGrf = GrfOpen("data.gpf", "rb", err, cb)
        Catch ex As Exception
            Console.WriteLine(ex.ToString)
        End Try
    End Sub
Which one to use? grf_open or grf_open_callback?
Getting an error:

Code: Select all

Method's type signature is not PInvoke compatible.