Using a C DLL in Visual Basic.net

Dave

Member
Joined
Jan 19, 2003
Messages
23
I have a DLL which is compiled from C which I need to use in vb.net.

So far I have this:

Code:
Declare Auto Function UnCompress Lib "lzss.dll" Alias "_uncompress_data" (ByVal Data As String, ByVal Length As Integer) As String

But when trying to run this:

Code:
dim out as String = UnCompress(indata, len(indata))

I get the following error message:

An unhandled exception of type System.NullReferenceException occurred

Additional information: Object reference not set to an instance of an object.

The C declaration of this function is as follows:

Code:
unsigned char __declspec(dllexport) *uncompress_data(unsigned char *inbuf,int *buflen)

What am I doing wrong?
 
Try This

Declare Auto Function UnCompress Lib "lzss.dll" Alias "_uncompress_data" (ByVal Data As String, ByVal Length As Integer) As String

UnCompress(indata, len(indata))

dim out as String = indata
 
OK then try this

Declare Function UnCompress Lib "lzss.dll" Alias "_uncompress_data" (ByRef Data As String, ByRef Length As Integer) As String

UnCompress(indata, len(indata))

dim out as String = indata
 
unsigned char ???? Could be that the dll function is looking for a char when you are passing it a string.
 
its an array of chars, but changing the type to Char() makes no diffrence and if you change the returned type to Char() you get a Could not marshal the return data type error
 
Back
Top