Re: Windows CE BinaryCompression
- From: "<ctacke/>" <ctacke[@]opennetcf[dot]com>
- Date: Sat, 13 Jan 2007 18:22:24 -0500
You are going about this the completely wrong way. That's not what the
function is for, and explaining how to get your data into some format that
would be compatible in all cases would be long and counterproductive. Get
a valid compression library or write something simple like RLE. You should
not be P/Invoking for something like this.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Wagner Bertolini Junior" <wagnerbertolini@xxxxxxxxxxxxxxxxxx> wrote in
message news:B5B8025E-5128-4C25-A038-DECE2F86E711@xxxxxxxxxxxxxxxx
I am just trying to compress a file.
Why, it doesn't work?
I saw someone using it.. but he was using C++ to do it.
But i think that is the same usage.
About the Word Aligned, means that the address of my pointer must be
aligned?
Now i get in trouble... I don´t know if i can do that over .NetCF but i
need
to do a research....
"<ctacke/>" wrote:
WORD aligned means it falls on a WORD divisible address (address % 2 ==
0).
DWORD aligned means it falls on a DWORD divisible address (address %4 ==
0)
What exactly are you trying to do here anyway? I seriously doubt that
you
should be using this undocumented kernel API from an app, let alone a
managed app.
--
Chris Tacke
OpenNETCF Consulting
Managed Code in the Embedded World
www.opennetcf.com
--
"Wagner Bertolini Junior" <wagnerbertolini@xxxxxxxxxxxxxxxxxx> wrote in
message news:uYcWqroNHHA.5016@xxxxxxxxxxxxxxxxxxxxxxx
Can anyone help me with this?
I found at winCe sources this function:
//------------------------------------------------------------------------------
// Compressors - bufin and bufout must be WORD aligned, lenout must be
at
least as
// large as lenin, CECOMPRESS_FAILED is returned if it doesn't fit,
else
compressed length
// CECOMPRESS_ALL_ZEROS returned if buffer entirely zero. If bufout is
NULL, the output
// length is computed, but the results are not stored. Lenin must be a
multiple of 2.
//------------------------------------------------------------------------------
DWORD
NKBinaryCompress(
LPBYTE bufin,
DWORD lenin,
LPBYTE bufout,
DWORD lenout
)
{
DWORD retval;
TRUSTED_API (L"NKBinaryCompress", CECOMPRESS_FAILED);
DEBUGMSG(ZONE_ENTRY, (L"NKBinaryCompress entry: %8.8lx %8.8lx %8.8lx
%8.8lx\r\n", bufin, lenin, bufout, lenout));
retval = CECompress(bufin, lenin, bufout, lenout, 1, 1024);
DEBUGMSG(ZONE_ENTRY, (L"NKBinaryCompress exit: %8.8lx\r\n",
retval));
return retval;
}
But i CAN´T understand the comment, what is WORD aligned?
i'm trying to use it and i'm receving an Error.. i will post the sample
code:
//DWORD BinaryCompress(LPBYTE bufin, DWORD lenin, LPBYTE bufout, DWORD
lenout);
//DWORD BinaryDecompress(LPBYTE bufin, DWORD lenin, LPBYTE bufout,
DWORD
lenout, DWORD skip);
[DllImport("coredll.dll", SetLastError=true)]
public static extern unsafe int BinaryCompress(byte* bufferIn, int
lenIn,
byte* bufferOut, ref int lenOut);
[DllImport("coredll.dll", SetLastError = true)]
public static extern unsafe int BinaryDecompress(byte* bufferIn, int
lenIn, byte* bufferOut, ref int lenOut, int skip);
string fileOpen = "\\Temp\\test.bmp";
byte[] bFile;
bFile = OpenFile(fileOpen);
byte[] bufferNew = new byte[bFile.Length];
int iLen = 0;
int ret = 0;
fixed(byte* bLP = bFile)
fixed (byte* bLPNew = bufferNew)
{
ret = BinaryCompress(bLP, (int)bFile.Length, bLPNew, ref
iLen);
if (ret != 0)
{
ret = Marshal.GetLastWin32Error();
MessageBox.Show(new Win32Exception(ret).Message); //
this always return 87 / Win32Exception
}
}
if anyone wants to see the OpenFile
private static byte[] OpenFile(string fileOpen)
{
byte[] bFile;
FileStream fs = File.OpenRead(fileOpen);
bFile = new byte[fs.Length];
byte[] bAux = new byte[1024];
int bytToRead = (int)fs.Length;
int count = 0;
int idx = 0;
while (bytToRead > 0)
{
count = fs.Read(bAux, 0, bAux.Length);
idx = (int)fs.Length - bytToRead;
for (int i = 0; i < count; i++)
bFile[idx+i] = bAux[i];
bytToRead -= count;
}
fs.Close();
return bFile;
}
The file length is 307254 bytes.
Any idea??
Thanks a lot.
.
- Follow-Ups:
- Re: Windows CE BinaryCompression
- From: Wagner Bertolini Junior
- Re: Windows CE BinaryCompression
- References:
- Windows CE BinaryCompression
- From: Wagner Bertolini Junior
- Re: Windows CE BinaryCompression
- From: <ctacke/>
- Re: Windows CE BinaryCompression
- From: Wagner Bertolini Junior
- Windows CE BinaryCompression
- Prev by Date: Re: Windows CE BinaryCompression
- Next by Date: Win CE 5.0 Application
- Previous by thread: Re: Windows CE BinaryCompression
- Next by thread: Re: Windows CE BinaryCompression
- Index(es):
Relevant Pages
|