P
Paul Ferrill
Can anyone help with the code to call the following C routines:
/* Memory model that allows to access memory at offsets of lzo_uint.
*/
#if !defined(__LZO_MMODEL)
# if (LZO_UINT_MAX <= UINT_MAX)
# define __LZO_MMODEL
# elif defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_MMODEL __huge
# define LZO_999_UNSUPPORTED
# elif defined(__LZO_PALMOS16) || defined(__LZO_TOS16)
# define __LZO_MMODEL
# else
# error "__LZO_MMODEL"
# endif
#endif
/* no typedef here because of const-pointer issues */
#define lzo_byte unsigned char __LZO_MMODEL
#define lzo_bytep unsigned char __LZO_MMODEL *
#define lzo_charp char __LZO_MMODEL *
#define lzo_voidp void __LZO_MMODEL *
#define lzo_shortp short __LZO_MMODEL *
#define lzo_ushortp unsigned short __LZO_MMODEL *
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
#define lzo_int32p lzo_int32 __LZO_MMODEL *
#define lzo_uintp lzo_uint __LZO_MMODEL *
#define lzo_intp lzo_int __LZO_MMODEL *
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
LZO_EXTERN(int)
lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
LZO_EXTERN(int)
lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
I've tried multiple combinations of ByVal, ByRef, DllImport, Declare
Function, etc. and all seem to throw the same exception of:
Object reference not set ton an instance of an object.
Here's the code I'm currently trying:
Public Class Class1
Declare Function lzo1x_1_compress Lib "lzo.dll" ( _
<[In](), Out()> ByVal Src() As Integer, _
ByVal SrcLen As Integer, _
<[In](), Out()> ByVal Dst() As Integer, _
ByVal DstLen As Integer, _
ByRef wrkMem As IntPtr) As Integer
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim i, r, x, y As Integer
Dim ibuff(1024), obuff(2048), wrkmem(8192) As Integer
For i = 1 To 1024
ibuff(i) = i
Next i
x = 1024
Dim mbuffer As IntPtr =
Marshal.AllocCoTaskMem(Marshal.SizeOf(y) * 8192)
Try
r = Class1.lzo1x_1_compress(ibuff, x, obuff, y, mbuffer)
Catch ex As Exception
Debug.WriteLine("Exception " & ex.Message)
End Try
Debug.WriteLine("Result " & r)
End Sub
/* Memory model that allows to access memory at offsets of lzo_uint.
*/
#if !defined(__LZO_MMODEL)
# if (LZO_UINT_MAX <= UINT_MAX)
# define __LZO_MMODEL
# elif defined(__LZO_DOS16) || defined(__LZO_WIN16)
# define __LZO_MMODEL __huge
# define LZO_999_UNSUPPORTED
# elif defined(__LZO_PALMOS16) || defined(__LZO_TOS16)
# define __LZO_MMODEL
# else
# error "__LZO_MMODEL"
# endif
#endif
/* no typedef here because of const-pointer issues */
#define lzo_byte unsigned char __LZO_MMODEL
#define lzo_bytep unsigned char __LZO_MMODEL *
#define lzo_charp char __LZO_MMODEL *
#define lzo_voidp void __LZO_MMODEL *
#define lzo_shortp short __LZO_MMODEL *
#define lzo_ushortp unsigned short __LZO_MMODEL *
#define lzo_uint32p lzo_uint32 __LZO_MMODEL *
#define lzo_int32p lzo_int32 __LZO_MMODEL *
#define lzo_uintp lzo_uint __LZO_MMODEL *
#define lzo_intp lzo_int __LZO_MMODEL *
#define lzo_voidpp lzo_voidp __LZO_MMODEL *
#define lzo_bytepp lzo_bytep __LZO_MMODEL *
LZO_EXTERN(int)
lzo1x_decompress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem /* NOT USED */ );
LZO_EXTERN(int)
lzo1x_1_compress ( const lzo_byte *src, lzo_uint src_len,
lzo_byte *dst, lzo_uintp dst_len,
lzo_voidp wrkmem );
I've tried multiple combinations of ByVal, ByRef, DllImport, Declare
Function, etc. and all seem to throw the same exception of:
Object reference not set ton an instance of an object.
Here's the code I'm currently trying:
Public Class Class1
Declare Function lzo1x_1_compress Lib "lzo.dll" ( _
<[In](), Out()> ByVal Src() As Integer, _
ByVal SrcLen As Integer, _
<[In](), Out()> ByVal Dst() As Integer, _
ByVal DstLen As Integer, _
ByRef wrkMem As IntPtr) As Integer
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim i, r, x, y As Integer
Dim ibuff(1024), obuff(2048), wrkmem(8192) As Integer
For i = 1 To 1024
ibuff(i) = i
Next i
x = 1024
Dim mbuffer As IntPtr =
Marshal.AllocCoTaskMem(Marshal.SizeOf(y) * 8192)
Try
r = Class1.lzo1x_1_compress(ibuff, x, obuff, y, mbuffer)
Catch ex As Exception
Debug.WriteLine("Exception " & ex.Message)
End Try
Debug.WriteLine("Result " & r)
End Sub