News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

IImgCtx COM Interface

Started by dedndave, June 17, 2012, 12:57:31 AM

Previous topic - Next topic

dedndave

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


dedndave

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

Geoff Chappell site maybe:
http://www.geoffchappell.com/studies/windows/ie/mshtml/interfaces/iimgctx.htm

dedndave

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
_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

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

#6
Hi,

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

Regards, qWord

EDIT: corrected version
MREAL macros - when you need floating point arithmetic while assembling!

dedndave

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

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

qWord

Quote from: dedndave on June 18, 2012, 12:38:48 AMhmmm - 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.

Quote from: dedndave on June 18, 2012, 12:38:48 AMqWord - 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

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

qWord

MREAL macros - when you need floating point arithmetic while assembling!

dedndave

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

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

MichaelW

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.


;==============================================================================
    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

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