### Author Topic: IImgCtx COM Interface  (Read 19154 times)

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### IImgCtx COM Interface
« on: June 17, 2012, 12:57:31 AM »
i am looking for information regarding  the IImgCtx COM Interface
i have found a few examples and i have the iimgctx.h file, which provides minimal information

but, the IE 5.5 SDK supposedly had some information on this interface
of course, i cannot find that SDK
any help would be appreciated   :t

#### Vortex

• Member
• Posts: 2697
##### Re: IImgCtx COM Interface
« Reply #1 on: June 17, 2012, 04:07:12 AM »
Hi Dave,

This is what I found :

An Image Decoder Based on IImgCtx

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #2 on: June 17, 2012, 09:39:50 AM »
thanks Erol
yah - i read that one - i was hoping to find out more   :P

it's probably enough info to work with
i want to "make a better mouse-trap", though

#### Dubby

• Member
• Posts: 60
##### Re: IImgCtx COM Interface
« Reply #3 on: June 17, 2012, 04:34:02 PM »

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #4 on: June 17, 2012, 07:44:54 PM »
thanks Dubby

yah - i am becoming a big fan of Geoff   :P
the biggest bits of info i got from his page were:

1) it is implemented in MSHTML
kind of knew that - i knew that it is used by IE to render HTML pages
thus, when images are loaded, it wants a UNICODE URL string
but - i have learned how to make UNICODE URL strings to get files and resources by name or ordinal   :P

2) it is used by ListView controls (COMCTL32.DLL) - this i did not know
i may be able to get another example of it's use

i am new to COM and i do not understand the CoInvoke macro - lol
so, i plan to use these TEXTEQU's to call the functions
probably only need a few of them to load images
Code: [Select]
`_IImgCtx_QueryInterface   TEXTEQU <dword ptr [eax]>     ;This,riid:REFIID,ppvObj:LPVOID_IImgCtx_AddRef           TEXTEQU <dword ptr [eax+4]>   ;This_IImgCtx_Release          TEXTEQU <dword ptr [eax+8]>   ;This_IImgCtx_Load             TEXTEQU <dword ptr [eax+0Ch]> ;This,pszUrl:PCWSTR,dwFlags:ULONG_IImgCtx_SelectChanges    TEXTEQU <dword ptr [eax+10h]> ;This,ulChgOn:ULONG,ulChgOff:ULONG,fSignal:BOOL_IImgCtx_SetCallback      TEXTEQU <dword ptr [eax+14h]> ;This,pfnCallback:PFNIMGCTXCALLBACK,pvPrivateData:PVOID_IImgCtx_Disconnect       TEXTEQU <dword ptr [eax+18h]> ;This_IImgCtx_GetUpdateRects   TEXTEQU <dword ptr [eax+1Ch]> ;This,prc:RECT*,prcImg:RECT*,pcrc:LONG*_IImgCtx_GetStateInfo     TEXTEQU <dword ptr [eax+20h]> ;This,pulState:ULONG*,psize:SIZE*,fClearChanges:BOOL_IImgCtx_GetPalette       TEXTEQU <dword ptr [eax+24h]> ;This,phpal:HPALETTE*_IImgCtx_Draw             TEXTEQU <dword ptr [eax+28h]> ;This,hdc:HDC,prcBounds:RECT*_IImgCtx_Tile             TEXTEQU <dword ptr [eax+2Ch]> ;This,hdc:HDC,pptBackOrg:POINT*,prcClip:RECT*,psize:SIZE*_IImgCtx_StretchBlt       TEXTEQU <dword ptr [eax+30h]> ;This,hdc:HDC,dstX:INT,dstY:INT,dstXE:INT,dstYE:INT,srcX:INT,srcY:INT,srcXE:INT,srcYE:INT,dwROP:ULONG`
from what i have read, installing IE9 broke a lot of code that uses the Draw function
i am hoping that the updated version of MSHTML will still load images, though

it seems to me that the interface can even render animated GIF's
maybe that's one of the uses of the callback function

#### Dubby

• Member
• Posts: 60
##### Re: IImgCtx COM Interface
« Reply #5 on: June 17, 2012, 11:00:14 PM »
yes it's able to render GIF... but unfortunately I can not find any documentation about it...
btw, I have found a pretty straight forward example (it's in C though, [PURELY C]) here:
http://forum.pellesc.de/index.php?topic=433.0
which link to example file here:
http://www.smorgasbordet.com/pellesc/sample_imgctx.htm

hope this helps...

#### qWord

• Member
• Posts: 1475
• The base type of a type is the type itself
##### Re: IImgCtx COM Interface
« Reply #6 on: June 17, 2012, 11:02:38 PM »
Hi,

I'm having the IE9 and it works here (Win7mx64).
In the attachment an example.

Regards, qWord

EDIT: corrected version
« Last Edit: April 21, 2013, 04:01:32 AM by qWord »
MREAL macros - when you need floating point arithmetic while assembling!

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #7 on: June 18, 2012, 12:38:48 AM »
thanks both of you
hmmm - i wonder if it is the StretchBlt function that does not work with IE9

qWord - i noticed that you did not use the Release function
i was wondering about that - some examples i have looked at use it - some do not

what's nice about IImgCtx is that it will open:
BMP, DIB, EMF, GIF, ICO, JPG, PNG, TIFF, WMF, and maybe PCX
and - it's a little easier to use than GDI+
it opens a stream, like GDI+, too
so - if IE9 has problems with the Draw function, i could use GDI+ for that part
it may be that MS has released a hotfix for it

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #8 on: June 18, 2012, 12:54:41 AM »

the IImgCtx Load function requires a UNICODE URL
which is nice - if the user has a UNICODE pathname, it will handle it
if used on a resource, the resource type must be 2110
you can use GetModuleFileNameW to get the UNICODE module path

resource by ordinal, 127 for example:
"res://<module path>/#2110/127", a UNICODE string

to use resource by name, it should be named something like MYPNG.PNG - all caps:
"res://<module path>/#2110/MYPNG.PNG", a UNICODE string
(resource names are UNICODE by nature)

possibly, the "/#2110" part may be omitted, as it is the only valid type for IImgCtx

of course, you can get a file:
"file://<file path>", a UNICODE string

and, it will load from a real URL, too
"http://somesite.com/someimage.png", a UNICODE string

#### qWord

• Member
• Posts: 1475
• The base type of a type is the type itself
##### Re: IImgCtx COM Interface
« Reply #9 on: June 18, 2012, 01:08:52 AM »
hmmm - i wonder if it is the StretchBlt function that does not work with IE9
I was also unable to get StretchBlt working. However that doesn't matter, because Draw also scale the image to fit the specified rectangle.

qWord - i noticed that you did not use the Release function
i was wondering about that - some examples i have looked at use it - some do not
Release is called in the WM_DESTROY-Handler.
MREAL macros - when you need floating point arithmetic while assembling!

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #10 on: June 18, 2012, 03:43:17 AM »
qWord - i really like your METHOD macro   :t
that seems to make the whole COM thing look easy

i am writing a multi-purpose routine for public use
is it ok if i use your macro ?
i will put "by qWord" in there, of course

#### qWord

• Member
• Posts: 1475
• The base type of a type is the type itself
##### Re: IImgCtx COM Interface
« Reply #11 on: June 18, 2012, 03:57:16 AM »
is it ok if i use your macro ?
yes, of course.
MREAL macros - when you need floating point arithmetic while assembling!

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #12 on: June 18, 2012, 05:31:30 AM »
great ! - that will make it much nicer looking

i actually decided to run the demo you wrote
it does not work for me - i get a black image area
your machine is probably faster than mine   :P

i think it's because the Load function is asynchronous
you have to test the GetStateInfo flags

Code: [Select]
`IMGLOAD_STOPPED    EQU 000400000h ; Imaged aborted - return errorIMGLOAD_ERROR      EQU 000800000h ; Error loading image - return errorIMGLOAD_COMPLETE   EQU 001000000h ; Image loaded - continue with image`
i was going to test those 3 flags - if they are all 0, do a Sleep,1 and try again
or maybe Sleep,2
the examples i have seen use Sleep,5 or Sleep,10
i don't think they realize how long 5 mS is in CPU cycles - lol

but - i was thinking i might do it like this:
2) create compatible DC/Bitmap/whatever to use the time
3) test the state flags as above
4) do BitBlt if successful

#### MichaelW

• Global Moderator
• Member
• Posts: 1196
##### Re: IImgCtx COM Interface
« Reply #13 on: June 18, 2012, 06:37:11 AM »
Dave,

Unless you change the minimum timer resolution (see timeBeginPeriod), specifying any sleep interval less than the default timer resolution, 10 or 15.625 ms depending on the system, will result in a sleep interval equal to the default resolution.

Code: [Select]
`;==============================================================================    include \masm32\include\masm32rt.inc    include \masm32\include\winmm.inc    includelib \masm32\lib\winmm.lib;==============================================================================;-----------------------------------------------------------------------------; This macro more or less duplicates the functionality of the BASIC language; TIMER function, returning the elapsed seconds since the performance counter; started counting as a REAL8 value with an effective resolution of a few; microseconds.;-----------------------------------------------------------------------------timer MACRO    IFNDEF _timer_pc_frequency_        .data            align 8            _timer_pc_frequency_      dq 0            _timer_pc_count_          dq 0            _timer_elapsed_seconds_   dq 0            _timer_initialized_       dd 0        .code    ENDIF    .IF _timer_initialized_ == 0        invoke QueryPerformanceFrequency, ADDR _timer_pc_frequency_        inc _timer_initialized_    .ENDIF    invoke QueryPerformanceCounter, ADDR _timer_pc_count_    fild _timer_pc_count_    fild _timer_pc_frequency_    fdiv    fstp _timer_elapsed_seconds_    EXITM <_timer_elapsed_seconds_>ENDM;==============================================================================    .data        t8 REAL8 0.0    .code;==============================================================================start:;==============================================================================    invoke Sleep, 3000    fld timer()    mov ebx, 1000    .WHILE ebx      invoke Sleep, 1      dec ebx    .ENDW    fld timer()    fsubr    fstp t8    printf("Sleep(1) delay  %2.3f ms\n", t8)    fld timer()    mov ebx, 1000    .WHILE ebx      invoke Sleep, 10      dec ebx    .ENDW    fld timer()    fsubr    fstp t8    printf("Sleep(10) delay %2.3f ms\n", t8)    invoke timeBeginPeriod, 1    fld timer()    mov ebx, 1000    .WHILE ebx      invoke Sleep, 1      dec ebx    .ENDW    fld timer()    fsubr    fstp t8    printf("Sleep(1) delay  %2.3f ms\n", t8)    invoke timeEndPeriod, 1    inkey    exit;==============================================================================end start`
Well Microsoft, here’s another nice mess you’ve gotten us into.

#### dedndave

• Member
• Posts: 8828
• Still using Abacus 2.0
##### Re: IImgCtx COM Interface
« Reply #14 on: June 18, 2012, 09:43:59 AM »
Code: [Select]
`Sleep(1) delay  1.953 msSleep(10) delay 10.742 msSleep(1) delay  1.953 msSleep(1) delay  1.954 msSleep(10) delay 10.742 msSleep(1) delay  1.953 ms`
i think we've been through this, before   :P