The MASM Forum

General => The Workshop => Topic started by: dedndave on June 17, 2012, 12:57:31 AM

Title: IImgCtx COM Interface
Post by: dedndave 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
Title: Re: IImgCtx COM Interface
Post by: Vortex on June 17, 2012, 04:07:12 AM
Hi Dave,

This is what I found :

An Image Decoder Based on IImgCtx (http://www.codeproject.com/Articles/7065/An-Image-Decoder-Based-on-IImgCtx)
Title: Re: IImgCtx COM Interface
Post by: dedndave 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
Title: Re: IImgCtx COM Interface
Post by: Dubby on June 17, 2012, 04:34:02 PM
Geoff Chappell site maybe:
http://www.geoffchappell.com/studies/windows/ie/mshtml/interfaces/iimgctx.htm
Title: Re: IImgCtx COM Interface
Post by: dedndave 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
Title: Re: IImgCtx COM Interface
Post by: Dubby 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...
Title: Re: IImgCtx COM Interface
Post by: qWord 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
Title: Re: IImgCtx COM Interface
Post by: dedndave 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
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 18, 2012, 12:54:41 AM
i will share some more information that i have learned...

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   :biggrin:
"http://somesite.com/someimage.png", a UNICODE string
Title: Re: IImgCtx COM Interface
Post by: qWord 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.
Title: Re: IImgCtx COM Interface
Post by: dedndave 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   :biggrin:

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
Title: Re: IImgCtx COM Interface
Post by: qWord on June 18, 2012, 03:57:16 AM
is it ok if i use your macro ?
yes, of course.
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 18, 2012, 05:31:30 AM
great ! - that will make it much nicer looking   :biggrin:

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 error
IMGLOAD_ERROR      EQU 000800000h ; Error loading image - return error
IMGLOAD_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:
1) Load
2) create compatible DC/Bitmap/whatever to use the time
3) test the state flags as above
4) do BitBlt if successful
Title: Re: IImgCtx COM Interface
Post by: MichaelW on June 18, 2012, 06:37:11 AM
Dave,

Unless you change the minimum timer resolution (see  timeBeginPeriod (http://msdn.microsoft.com/en-us/library/windows/desktop/dd757624(v=vs.85).aspx)), 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
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 18, 2012, 09:43:59 AM
Code: [Select]
Sleep(1) delay  1.953 ms
Sleep(10) delay 10.742 ms
Sleep(1) delay  1.953 ms

Sleep(1) delay  1.954 ms
Sleep(10) delay 10.742 ms
Sleep(1) delay  1.953 ms

i think we've been through this, before   :P
Title: Re: IImgCtx COM Interface
Post by: MichaelW on June 18, 2012, 12:12:26 PM
i think we've been through this, before   :P

Yes, I think we have, but I still don't understand how your system could have these defaults. Is it a configuration change that you made, or some MCE thing?
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 18, 2012, 12:28:07 PM
well, before we go off thinking my machine is unique, let's run it on a few different machines   :P

but - yah, my machine is somewhat unique in this forum - lol
i am running XP MCE2005 SP3
i think i am the only MCE guy in here
Title: Re: IImgCtx COM Interface
Post by: FORTRANS on June 18, 2012, 11:28:11 PM
Hi,

   I'm getting errors on the printf lines.  Pointers?

Steve
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 18, 2012, 11:43:31 PM
it needs to be assembled with masm32 package v11, Steve
printf is a newer macro


qWord...
i am having trouble understanding how "_this" is implemented
i do not find it defined in the METHOD macro, or anywhere in the masm32 package
i know that it is the interface pointer - i just don't know how or where it is defined

disassembly of the "Load" call
Code: [Select]
:00401352 C745B000000000          mov dword[ebp-50], 00000000
:00401359 C745B400000000          mov dword[ebp-4C], 00000000
:00401360 C745B8C8000000          mov dword[ebp-48], 000000C8
:00401367 C745BCC8000000          mov dword[ebp-44], 000000C8
:0040136E 8D45B0                  lea eax, dword[ebp-50]
:00401371 50                      push eax
:00401372 FF3594304000            push dword[00403094]
:00401378 FF3590304000            push dword[00403090]
:0040137E FF5628                  call dword[esi+28]

EDIT - ok - i get it
it is just a parameter name   :P  (DOH !)
Title: Re: IImgCtx COM Interface
Post by: FORTRANS on June 19, 2012, 12:13:28 AM
Hi Dave,

   Thank you, that makes sense.

Regards,

Steve
Title: Re: IImgCtx COM Interface
Post by: qWord on June 19, 2012, 12:15:19 AM
this is the object pointer, more specific a pointer to a structure that’s first member points allways to the virtual function table. The other members are the public and private data of the class. (c++ object model)
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 19, 2012, 12:17:57 AM
thanks qWord
yah - i figured it out - lol
Title: Re: IImgCtx COM Interface
Post by: Zen on June 19, 2012, 05:26:48 AM
DAVE !!!
Quote from: DAVE !!!
...I am new to COM and I do not understand the CoInvoke macro - LOL,...
Although you now know what a COM object is,...here is an overview of COM activation: How Does COM Activation Work Anyway? (http://blogs.msdn.com/b/larryosterman/archive/2004/10/12/241420.aspx)
The CoInvoke macro does what CoCreateInstance (http://msdn.microsoft.com/en-us/library/windows/desktop/ms686615(v=vs.85).aspx) does (for C++ programmers).
QWORD's explanation of the this pointer above is correct,...the central principal of the COM specification is that all COM objects are binary compatible, regardless of what language it was written in.

...And, as always,...I'm usually wrong about assembly language programming stuff,...
Title: Re: IImgCtx COM Interface
Post by: dedndave on June 19, 2012, 09:15:14 AM
thanks baltoro - an interesting read