COM equality testing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am getting some whacked out results when I am testing
COM objects for equality.

If you run the code below then the document object differs
from everything but itself (including ie.document is not
the same thing as ie.document.parentWindow.document)

On the other hand, the window object shows the same
as everything else except ie and ie.document.

I've tested this against both JSscript and VBScript
methods, shown below, and the results are
consistent. Can anyone explain this behaviour,
please?

Thanks,
Csaba Gabor from Vienna

'COM comparisons
Dim ie, com1, com2, doc, wnd, div, out
Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate2 "about:blank"
ie.document.body.innerHTML = "<div id=foo></div>"

Set doc = ie.document
Set wnd = doc.parentWindow
Set div = ie.document.getElementById("foo")

out = compare(doc, ie.document, "doc/doc: ")
out = out & compare(doc, wnd.document, "doc/doc 2: ")
out = out & compare(doc, wnd, "doc/window: ")
out = out & compare(doc, ie, "doc/ie: ")
out = out & compare(doc, doc.body, "doc/body: ")
out = out & compare(doc, div, "doc/div: ") & vbCrLf

out = out & compare(wnd, doc, "window/doc: ")
out = out & compare(wnd, wnd.document, "window/doc 2: ")
out = out & compare(wnd, wnd.document.parentWindow, _
"window/window: ")
out = out & compare(wnd, ie, "window/ie: ")
out = out & compare(wnd, doc.body, "window/body: ")
out = out & compare(wnd, div, "window/div: ") & vbCrLf

ie.Quit()
MsgBox out

Function compare(com1, com2, txt)
If COMeqVB(com1,com2) _
Then compare = txt & "same" & vbCrLf _
Else compare = txt & "different" & vbCrLf
End Function

Function COMeqVB (com1, com2)
COMeqVB = (com1 Is com2)
End Function

Function COMeqJS (com1, com2)
Dim code
Set oScript = CreateObject("MSScriptControl.ScriptControl")
oScript.Language = "JScript"
code = "function comeq(com1,com2) { return (com1==com2); }"
oScript.AddCode code
oScript.addObject "com1", com1
oScript.addObject "com2", com2
COMeqJS = oScript.Eval("comeq(com1,com2)")
End Function

'Actual results are (under IE 6 / Win XP Pro):
' doc: same, diff, diff, diff, diff, diff
' window: diff, same, same, diff, same, same
'Expected results are:
' First two same in the doc section,
' Third one the same in the window section
' All the rest should be different
.



Relevant Pages

  • Re: Do I need to build a new platform (creat new nk.bin)
    ...  If you don't know anything about Windows ... To enable both COM1 and COM2, you need to include the components to support ... But the device ports thats mean COM1 and COM2 are making problems. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: serial port interfaced EEPROM reader no longer detected after temporary removal
    ... I wonder if the original instance of COM1 got set to be COM2? ... In the advanced options I looked at the possibility to rename the port, and noticed that COM2 has behind it, but as far as I know I don't have COM2 on my system. ... The manufacturer of the EEPROM reader tells me that the software scans for available serial ports and you can set one that is available. ...
    (microsoft.public.windowsxp.hardware)
  • Re: serial port interfaced EEPROM reader no longer detected after temporary removal
    ... But the craziest thing is that nowhere do I see COM2 except in the rename option for COM1. ... In the advanced options I looked at the possibility to rename the port, and noticed that COM2 has behind it, but as far as I know I don't have COM2 on my system. ... The manufacturer of the EEPROM reader tells me that the software scans for available serial ports and you can set one that is available. ...
    (microsoft.public.windowsxp.hardware)
  • Re: FTP server comprimised
    ... Com1, Com2 etc are reserved names hence why you were prevented from ... This appears to be a favorit trick of ... the server for others to download. ...
    (microsoft.public.win2000.security)
  • Re: Reading names of comports [COM1, COM2 etc]
    ... I want to see COM1, COM2 etc. ... // WICCOMPORTERROR of an error is detected ... In my Delphi 5 help file, there is some example code demonstrating how to use the results of that function to get the data you really need. ...
    (alt.comp.lang.borland-delphi)