Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello


i want to use lzo_1z decompress function from lzo1.07.dll file in C#

The syntax for the function is
C#
lzo_decomp (char* inp_buff, unsigned int* inp_len, char* buffer_decomp,
unsigned int *output_len, unsigned short *errorCode)


where,
Inp_buff- Specifies the input buffer (Compressed Buffer)
Inp_len- Specifies the length of input buffer (Compressed Length)
Buffer_decomp- Specifies the Buffer after decompression
output_len- Specifies the length after decompression ( Out put length )
errorCode- Specifies the error code


and call can be made as
lzo1z_decompress (out, decomp_inlen, in, & decomp_outlen, NULL)

i wanted to use above function in C#


C#
unsafe class lzoCompress {

[DllImport(@"C:\Documents and Settings\Developer1\My Documents\Visual Studio 2010\Projects\lzoCTCLDecompression\lzoCTCLDecompression\bin\Debug\lzo107.dll",CallingConvention=CallingConvention.StdCall)]

public static extern int lzo1z_decompress([MarshalAs(UnmanagedType.LPArray)] char[] inp_buff, ref ushort inp_len, [MarshalAs(UnmanagedType.LPArray)] char[] out_buff, ref int out_len, ref ushort errorCode);

public static char[] Decompress(byte[] src)
{
int origlen = BitConverter.ToInt32(src, src.Length - 4);
char[] ch = new char[origlen];
string str = BitConverter.ToString(src);
ch = str.ToCharArray();
char[] dst = new char[origlen];
int outlen = origlen;
int Srclength = src.Length - 4;
ushort inp_len = (ushort)src.Length;
int out_len = dst.Length;
ushort error = 0;
try
{
int i =lzo1z_decompress(ch, ref inp_len, dst, ref out_len, ref error);
} catch (Exception e) { }
}



i am getting an error as pinvoke
stackimbalance error
in try block
Posted
Updated 24-Jan-12 19:49pm
v5

You have already asked this question here[^], and been given some suggestions. Please do not repost the same question more than once.
 
Share this answer
 
v2
Comments
Richard MacCutchan 24-Jan-12 5:56am    
What does that mean? If you cannot manage to ask your question clearly and with full information then it is unlikely you will get any meaningful answers.
Why do you want to jump through hoops if you can get a LZO .NET wrapper?
Please see here: LZO.NET Highspeed Compression for .NET[^].

Regards,

Manfred
 
Share this answer
 
Comments
Member 4354249 24-Jan-12 6:08am    
The problem is i am getting the compressed data with LZO1Z compression. so i cannot change it
In your DllImport you have the option CallingConvention=CallingConvention.StdCall. Are you sure that the compression library uses this form, as using the wrong option here will probably cause the error you are seeing?
 
Share this answer
 
Comments
Member 4354249 25-Jan-12 5:53am    
if i am using not using that still i am getting that error...
i think the syntax of the calling function is not correct can u help me with the syntax
lzo_decomp (char* inp_buff, unsigned int* inp_len, char* buffer_decomp,
unsigned int *output_len, unsigned short *errorCode)

i need to convert the above in C#
Richard MacCutchan 25-Jan-12 6:14am    
Sorry I don't have much else to offer without knowing more about the function you are trying to invoke. I notice that you are sending a C# character array when the function requires a char*, but I think you should be using a byte array, since characters in C++ are 8 bits wide not 16 as in C#.
Richard MacCutchan 25-Jan-12 6:56am    
I just had a look at the P/Invoke website and found this reference which may help in figuring out the correct syntax.
Member 12093789 8-Jan-16 23:29pm    
Dear Friend,

I am also trying to resolve same problem,

Do you got any solution for the same?

If possible then please share with me, I will be very thankful for your help.

my mail id is mailmelok@gmail.com

Regards
Member 4354249 26-Jan-12 22:25pm    
its not helping can u tell me how do write this function's attributes in C???

lzo_decomp (char* inp_buff, unsigned int* inp_len, char* buffer_decomp,
unsigned int *output_len, unsigned short *errorCode)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900