TheDauthi has asked for the wisdom of the Perl Monks concerning the following question:

This is a bit long and convoluted, so bear with me. No code yet - the problem is that I don't see where to start tackling this problem.

Initial problem - I have an ancient VB6 app that embeds several Internet Explorer ActiveX objects. Recently, I needed to embed some form of scripting to it, and decided to use my favorite language. A few hours later, I had created an ActiveX control using Activestate's PerlCtrl app, and had it loading scripts and interacting with the IE control (among other parts of the app).

All good. Works great... Until I come to the part where I need to interact with frames embedded within those controls. IE's security model doesn't let you interact with the document under those controls directly. You have to use the IOleContainer interface to enumerate the control, then get the IWebBrowser2 interface of the enumerated objects. (see This for details).

AFAIK, Win32::OLE doesn't support getting random interfaces - it uses IDispatch, IVariant, and those ilk for the heavy lifting.

Well, I thought, I'll create some XS, pass the WebBrowser pointer to it, do the ugly stuff, then pass it back, somehow creating a Win32::OLE object. That's nice, except for two parts - getting the right pointer, and getting it back into an Win32::OLE object. Win32::OLE does appear to store the right interface pointer, but not anywhere I can see a way to get at it without compiling my own version of it. Even then, I'll have to create the Win32::OLE object with some convulutions.

Then I considered writing a COM control in C/C++, and got as far as writing the first few lines of C++ before I realized that I'll still need the original object to pass it through.

Finally, I decided that I would ask some perl gurus before I started writing this monstrosity. Has anyone ever come across something like this, another approach, or can think of a better way to accomplish this, or of some detail that I am currently missing?

Replies are listed 'Best First'.
Re: Internet Explorer Frames - Win32::OLE
by Anonymous Monk on Jul 02, 2010 at 22:31 UTC

      Aha! That's a start - that lets me return the new Win32::OLE object. I had already seen CreatePerlObject, but I didn't think of a way to call it without recompiling the XS. Since it just makes a DLL... DynaLoader/calling it with Win32::API is clever.

      For that matter, I -may- be able to change that "Get COM object from HWND" to get me the original document inside the XS. From there, it's just a small leap to getting the right interface.

      This may well be enough to get me started. Thanks!