[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

WebBrowserClass returning system.__comobject instead of string

Posted on 2004-08-01
7
Medium Priority
?
2,107 Views
Last Modified: 2008-01-09
I have a WebBrowserClass object called Explorer contained in my C# object.

I use the following code to access the element with an id of "footerClientArea" of the currently loaded page:

      HTMLDocument htmlDocument = (HTMLDocument)Explorer.Document;
      IHTMLElement e;
      e = htmlDocument.getElementById("footerClientArea");
      if (e!=null)      
      {
            string s = "";
            s = e.getAttribute("style", 0).ToString().ToLower();
            System.Windows.Forms.MessageBox.Show(null,s,"title");
      }
      e = null;
      htmlDocument = null;

What I am expecting is a message box containing the value of the "style" attribute, however, all I get is "system.__comobject"

it is strange, because when I display a message box with e.innerHTML, it correctly displays the HTML inside the element.  I am assuming that I need to cast the return value of getAttribute to some object, but what object?  Intellisense states that the return value of  getAttribute is of type "object", which doesn't help.  I know from the documentation that it should be returning a string, but the compiler won't accept a the value into a string variable without a cast, and casting the return value to a string doesn't work either...

Any help would be greatly appreciated!

0
Comment
Question by:protemus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
7 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11689963
it would depend on what type of object it is ....

what do you get when you add a watch on the object ? it should be able to tell you what fields you need in debug.
0
 

Author Comment

by:protemus
ID: 11700452
um... I don't really know what adding a watch to it is going to do.....

Maybe I didn't clearly state my problem, here is a more in depth explanation...

My class contains a WebBrowserClass member like so:

protected WebBrowserClass Explorer;

It is attached in a straightforward way by creating RCW from Com interface like so:

sp.QueryService( ref guid,ref riid,out w );
Explorer = (WebBrowserClass) Marshal.CreateWrapperOfType(
                        w as IWebBrowser,
                        typeof(WebBrowserClass) );

Then when I am sure a web page is loaded into the explorer object, I try to look at the HTML by accessing the document member of the WebBrowserClass object like so:

HTMLDocument htmlDocument = (HTMLDocument)Explorer.Document;

All that works perfectly, then I search for a specifically named DIV within the HTML like so:

IHTMLElement e;
e = htmlDocument.getElementById("footerClientArea");

Still, all is well because if I display a message box with e.innerHTML, it displays the correct HTML that is inside the DIV.  However, when I try to get just the value of a specific attribute of that DIV like the style attribute as follows:

s = e.getAttribute("style", 0)

Instead of a string like the docs say it is supposed to return, I get a class that identifies itself as "system.__comobject" (it doesn't even compile without a cast)

I think maybe it has something to do with the wrapper not marshalling the type correctly, but I am at a loss.  Another theory I have is that the function is actually returning a variant type instead of a straight string.  If that is the case, does anyone know how to get passed this point?


0
 

Author Comment

by:protemus
ID: 11700736
With a little more research, I have confirmed that the type being returned by the function ia actually a variant.  There must be a way to extract the BSTR value from the variant that is returned as a System.__ComObject.  However, from scouring the net, I could only fin references for marshalling managed to unmanaged, not vice-versa.

Anyone know?  

I would REALLY REALLY appreciate any insight here.
0
 
LVL 3

Accepted Solution

by:
PocketMatt earned 2000 total points
ID: 11713855
Hi protemus

to invoke functions on a __ComObject you can do the following:

object s;
s = e.getAttribute("style", 0).ToString().ToLower();
s = s.GetType().InvokeMember("",System.Reflection.BindingFlags.Default,null,s,null);
MessageBox.Show(s.ToString());

the Type.InvokeMember - Method is used to invoke a Member on an object of a class you do not really know. all you need to know is the name of the Member you need to invoke to get the string back. by passing "" you invoke the default member..
i'm not sure if this really works.. what i know is, that you need the InvokeMember - Method of the Type. maybe with another Membername...

hope this helps
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question