Hi everyone,

I tried to us BI_JPEG and BI_PNG as values for the BiCompression field in BITMAPINFOHEADER but i found out that these 2 values are not declared in windows.inc. Therefore, i inserted these 2 values on my own.

Question:
1. Do i need to recompile any of the libraries?
2. If someone tries to run my program and his / her system's windows.inc file does not have these 2 values, will my program crash?

Thanks.
Posted on 2004-03-01 04:47:58 by trexxz
1. You'll only need to re-assemble your own stuff using these values
2. No, of course not - but your program won't work on windows versions not supporting these BiCompression types (check MSDN/PlatformSDK for requirements). Windows.inc only affects programmers, not end-users.
Posted on 2004-03-01 08:50:53 by f0dder
Thanks f0dder.

I found out that in windows.inc, BITMAPINFO struct is declared as

BITMAPINFO STRUCT
bmiHeader BITMAPINFOHEADER <>
bmiColors RGBQUAD <>
BITMAPINFO ENDS

From the MSDN library, it states that for the bmiHeader variable, applications can use the BITMAPV4HEADER structure for added functionality.

Question:
1. How do i make the bmiHeader variable to use BITMAPINFOHEADER as well as BITMAPV4HEADER struct?

Thanks.
Posted on 2004-03-02 01:50:13 by trexxz
Be warned that BI_JPEG and BI_PNG are not what many people had hoped they were, you might be one of them:
PSDK: JPEG and PNG Extensions for Specific Bitmap Functions and Structures

On certain versions of Microsoft? Windows?, the StretchDIBits and SetDIBitsToDevice functions allow JPEG and PNG images to be passed as the source image to printer devices. This extension is not intended as a means to supply general JPEG and PNG decompression to applications, but rather to allow applications to send JPEG- and PNG-compressed images directly to printers having hardware support for JPEG and PNG images.

The BITMAPINFOHEADER, BITMAPV4HEADER and BITMAPV5HEADER structures are extended to allow specification of biCompression values indicating that the bitmap data is a JPEG or PNG image. These compression values are only valid for SetDIBitsToDevice and StretchDIBits when the hdc parameter specifies a printer device.


Thomas
Posted on 2004-03-02 04:31:03 by Thomas
Thanks for your advice, Thomas!

After a more in-depth study of the documentation of the MSDN library, i think you are right. I do not need to pass images to printer devices.

My program is able to display JPEG images on win XP,win 2000 and win 98 OSs. However, it crashes on win NT4. That is why i'm looking into the use of BI_JPEG and BI_PNG.

Do you have any ideas on what is the cause of it? What are the common problems or issues?

Thanks.
Posted on 2004-03-02 06:34:04 by trexxz
Windows can load JPG and GIF natively using some OLE functions, check out Ernie's site for that. PNGs can be loaded with my PNG library, see my site.

Thomas
Posted on 2004-03-02 06:56:05 by Thomas
I think that Windows NT simply lacks the OLE/COM functions /interfaces needed to load JPEG and GIF without doing it yourself ;) (or using a 3rd party lib/dll)

So when you attempt to call an interface that does NOT exist --> your application normaly crashes
It is not a problem in windows.inc it is an issue of that OS ...

AFAIK updating NT to SP6 and adding a new version of IE (5 or 6) might magically solve that ;) because the functions for loading JPEG are used/updated by IExplore
Posted on 2004-03-02 08:29:44 by BogdanOntanu
Thanks Thomas, BogdanOntanu!

Where can i download the Ernie's latest image.lib?

Does it work on all windows OS?
Posted on 2004-03-03 05:20:03 by trexxz
trexxz, image.lib simply uses the COM functionality to load the images. So upgrading image.lib won't solve problems with old windows versions. However, do ask yourself - do you need to support systems older than NT4 with service pack 6?
Posted on 2004-03-03 10:31:39 by f0dder
I'm using Ernie's image.lib to load my images now.

On my Win XP machine, i'm able to load bitmaps and jpegs.
However on my NT4 machine updated with SP 6, my program crashs while displaying jpegs. Bitmaps work fine though.

Any ideas?

:confused:
Posted on 2004-03-04 03:59:26 by trexxz
Perhaps NT4+SP6 doesn't support the necessary COM interfaces after all, or Ernie's image.lib is bugged. *shrug*. Try stepping through a debugger and see where the program fails (this doesn't mean "find the line where the crash happens", but finding the first place where a API call returns an invalid value).
Posted on 2004-03-04 08:10:31 by f0dder
On Win NT, my program is very unstable. Sometimes, it crashes, sometimes it doesn't...
I tried to catch any error messages that might appear after every invoke statement but i couldn't get any. I suspect it is the "Invoke OleLoadPicture" part. But it didn't give me errors.

Question:
1. I'm using CreateDIBSection, the BITMAPINFO and BITMAPINFO HEADER structures for JPG images.
Is there anything i should take note which is different from BITMAP images?

2. Does a JPG image have color tables?

3. After a JPG image goes through CreateDIBSection, will it's DIB bit values be created?

4. Are the Bitmaps returned from BitmapFromFile, BitmapFromResource, BitmapFromMemory DIBs or DDBs?

Thanks.
Posted on 2004-03-05 04:06:49 by trexxz
The error message that is displayed is

An application error has occurred
Exception: access violation (0xc0000005),Address: 0x00407054

:confused:
Posted on 2004-03-05 04:35:03 by trexxz
Do some work yourself, trace the app in a debugger (like OllyDbg), figure out which line causes the crash.
Posted on 2004-03-07 15:21:13 by f0dder
i have traced my program and the error occurs here:

function: RtlFreeHeap
77f64d6a 85d2 test edx,edx
77f64d6c 53 push ebx
77f64d6d 56 push esi
77f64d6e 57 push edi
77f64d6f 0f8412020000 je RtlFreeHeap+0x227 (77f64f87)
77f64d75 8b7d08 mov edi, ss:0101e322=????????
77f64d78 8b5d0c mov ebx, ss:0101e322=????????
77f64d7b 0b5f10 or ebx, ds:0101ea06=????????
77f64d7e f7c3600f036f test ebx,0x6f030f60
77f64d84 0f85f3010000 jne RtlFreeHeap+0x21d (77f64f7d)
FAULT -> 77f64d8a 8a42fd mov al, ds:01037a0e=??
77f64d8d 8d72f8 lea esi, ds:01037a0e=????????
77f64d90 a801 test al,0x1
77f64d92 0f84bf010000 je RtlFreeHeap+0x1f7 (77f64f57)
77f64d98 f6c207 test dl,0x7
77f64d9b 0f85b6010000 jne RtlFreeHeap+0x1f7 (77f64f57)
77f64da1 807e0410 cmp byte ptr ,0x10 ds:01b50904=??
77f64da5 0f83ac010000 jnb RtlFreeHeap+0x1f7 (77f64f57)
77f64dab 8d8fc0040000 lea ecx, ds:001304c0=001305c0
77f64db1 833900 cmp dword ptr ,0x0 ds:77bcb228=77bc7400
77f64db4 742e jz RtlFreeHeap+0x84 (77f64de4)
77f64db6 83bfc404000000 cmp dword ptr ,0x0 ds:001304c4=00000000

It is after a jump to RtlFreeHeap
I did some searching on the Internet and apparently there are other people with this problem.

Described by the Microsoft Knowledge Website article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;189612
Posted on 2004-03-08 00:36:47 by trexxz
Maybe you are passing the wrong parameters to HeapFree or GlobalFree.
Posted on 2004-03-08 06:43:40 by roticv
The crash is in a system module, probably caused by freeing a wrong pointer. Now you need to find the line of code in your program that is calling a free routine ends up calling NtDll.RtlFreeHeap - this is stuff like HeapFree, LocalFree, GlobalFree, and a few others as well. If you're lucky you can use the stack window in OllyDbg to see the offending calling code.

There's a slight chance this could be a register preservation problem, so you might want to check that as well. And get familiar with OllyDbg (or another debugger of choice), it's a great thing to master.

I doubt the knowledge-base article has any relation to your problem.
Posted on 2004-03-08 07:43:06 by f0dder
roticv, f0dder, thanks for the tip!

:alright:
Posted on 2004-03-08 11:55:33 by trexxz
f0dder, thank you for introducing me to OllyDbg. This is really good debugging tool! :alright:

After a whole day of debugging my program, i can confidently say that the problem doesn't lie with my code.

If i'm loading bitmaps without Ernie's image.lib, my program works perfectly. I am using LoadImage to load bitmaps.

However, when i try to load JPEGs with BitmapFromResource, my program has errors with NtDll.RtlFreeHeap.
Although my program crashes on NT4 and not XP, i'm able to detect that error on XP with OllyDbg.

The log data states: Debug string: Invalid Address specified to RtlFreeHeap (00140000,0014BAE*)

I have checked all my memory allocations, frees, destroys and they are correct.

What should i do now? :confused:
Posted on 2004-03-09 03:44:31 by trexxz
You can test your code with MemProof, Purify or BoundsChecker.
Can you post the code ?
TQN
Posted on 2004-03-09 05:27:45 by TQN