How to use ActiveX control with PERL?


  I recently purchased a firewire camera that came with an ActiveX control for operating the camera via my application. The documentation that came with it was geared towards VB6. I was able to get it up-and-running on VB6 with only 4 lines of code! I thought this very neat.

  However, I am a PERL programmer. I want to use this ActiveX, and any other ActiveX, from my PERL code. I have seen references made to Win32::OLE, which I searched for on CPAN, but all the examples are for controlling Microsoft Office applications.

  Can someone please show me how to use an ActiveX control from PERL?

  How do you know what properties and methods the ActiveX control has available?

  For example (from CPAN):
    $ex = Win32::OLE->new('Excel.Application') or die "oops\n";
    $ex->Amethod("arg")->Bmethod->{'Property'} = "foo";
    $ex->Dmethod($RequiredArg1, {NamedArg1 => $Value1, NamedArg2 => $Value2});

    $wd = Win32::OLE->GetObject("D:\\Data\\Message.doc");
    $xl = Win32::OLE->GetActiveObject("Excel.Application");

    How do you know to use 'Excel.Application'? This is not obvious.

   Can PERL access any ActiveX control?
   Are there any software support tools that I should know about when dealing with ActiveX? (I can imagine a progam called ActiveX::Browse that enumerates all public methods and attributes for the Control, etc.)

   My development environment is: WindowsXp Pro, Komodo 3.0.1, MySQL.

   Note: I DO NOT want to convert PERL to ACTIVEX. This uses PerlCtrl and is NOT what I want. What I want is to make an ActiveX control available for PERL.

   If someone REALLY knows the answers to this I will "up" the points to 500. If you can tackle any of the sub-questions I will split points.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Post your code that was working with VB6.

In Perl it uses the same functions, but different syntax, so it should be possible to do it.
sapbucketAuthor Commented:
You can image the form is populated with the Image Viewer, and two command buttons (start and stop video). The Image Viewer displays a live feed from the firewire camera.

Note: I am using VB.NET, not VB6. I hope this doesn't change things. Also,  I had to do a few things to load the ActiveX control into the toolbox. But once there, this is all:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Store in VideoHasStarted whether a video stream
        ' has been started once. If VideoHasStarted is True,
        ' you can be sure that there is an image that can be processed.
        VideoHasStarted = True
        ' VideoHasStopped is set to False, because the live
        ' video has just been started.
        VideoHasStopped = False
        Status.Text = "Main Form is Loading"

    End Sub

    Private Sub cmdStartLive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StartLive.Click
        If VideoHasStopped = True Then
            VideoHasStarted = True
        End If
        Status.Text = "Live Camera Feed in Progress"
    End Sub

    Private Sub cmdStopLive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopLive.Click
        If VideoHasStarted = True Then
            VideoHasStopped = True
        End If

        Status.Text = "Live Camera Feed has been stopped"
    End Sub
sapbucketAuthor Commented:
I will increase this to 500 points if I can get a solid answer :)
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Sorry, I think I might have jumped the gun.

From your code there is nothing that resembles connecting to an existing windows control, creating an object and then manipulating it...
BTW "Excel.Application" is the Program ID of the specific class, to which you connect to create an Object.
Search through your registry HKEY_CLASSES_ROOT for it.

Someone might as well use
instead of Excel.Application to create an object of this class, then open an instance of this class as an object (The Excel program) and manipulate it by calling methods of this object.

ActiveX is a host to a specific class, so my idea was to find out what class it is (it might be a new class installed when you installed this Capturing application), then just use the Win32::OLE (this is the right automation tool for creating a class object and manipulating it) to create an object of this class and execute methods, available to it.
In theory it is straight forward, but in practice there are few people who actually do it in windows through Perl.

Win32::OLE module however is a module, which can create Windows class objects and same automation commands, that Windows Scripting Host can do through VB Script.

Sorry, I cannot be more specific here. Perhaps someone mightl help you better.

sapbucketAuthor Commented:
I'm still in need of an answer, anyone know?
You will first need to find out the correct class-id of the control you want to use (as sstouk already said).
To find out the correct id, have a look at the object-browser of your visual studio.

In order to set up your vb-project you did have to add a reference to your camera-control. right? Double-click the reference and the object-browser window will open. In that window you will see something like


as a child of "Camera" you will see something like


so the full class-name of your control (for vb) is Interop.Camera.ImagingControl.

if you leave "interop." away you have the com-classname, so you can the instantiate that class in perl using win32-ole:

use Win32::OLE;
$imaging = Win32::OLE->new('Camera.ImagingControl') or die "oops\n";

here "Imaging" and "Camera" are placeholders that you will have to replace with the proper values,
i am not a clairvoyant.



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sapbucketAuthor Commented:

  Thank you very much for responding to this question. Indeed I do have what you describe, but there are three:

(none have a "child" as far as I can tell)


Using your rules I am testing the following code:

# ok, in VB6 I would save the image buffer using: ImgBuffer.SaveAsBitmap(saveFileDialog1.FileName, TIS.Imaging.ICImagingControlColorformats.ICY8)
# where ImgBuffer is a "ImagingControl"
use Win32::OLE;
$imaging = Win32::OLE->new('ImagingControl') or die "oops\n";

ok, first attempt:
Win32::OLE(0.1701) error 0x800401f3: "Invalid class string" at line 5
        eval {...} called at line 5

So, $imaging = Win32::OLE->new('ImagingControl') or die "oops\n"; has error.

second attempt:

#!/usr/bin/perl -w
#use strict;

use Win32::OLE;
$imaging = Win32::OLE->new('ICImagingControl') or die "oops\n";

same error

Trying all different combinations........

Ok, no matter what i try I get the same error.

Is the format of $imaging = Win32::OLE->new('Camera.ImagingControl') or die "oops\n"; always'')...?

I think this problem is almost solved...Is there another way to lookup the com-classname?
>>Is the format of $imaging = Win32::OLE->new('Camera.ImagingControl') or die "oops\n"; always'')...?
afaik, yes.

>>Is there another way to lookup the com-classname?
do you have visual studio 6? there is another com-explorer. i once heard about ComSPY++ but i dont know anything specific.
maybe you should launch a new question like "how can i find an activex-classname" or something similar.



sapbucketAuthor Commented:

   i got it - you were right on the money. Many thanks!!!

   I used the Tools-> OLE/COM object viewer (not window). At first I was overwhelmed because there are literally thousands of Objects. But I found the one I was looking for under "embeddable objects".

   It was 'IC.ICImagingControl'

   Thanks :)
sapbucketAuthor Commented:
One last question:

I am now initializing the ActiveX control. I didn't know the exact procedure so I looked in the VB6 declarations section of code that inits the Camera. The code is EXTREMELY verbose. I am wondering if this is typical or not? All of the methods seem straightforward, LiveDisplayHeight, LiveDisplayWidth, etc. except for one of them: DeviceState. Do you think I should copy and paste that long string of stuff into PERL? All of the "Microsoft.VisualBasic.ChrW" lines make me think 'NO.'

This is tough for me because I do not know how to decompose what is going on and I have no documentation. I just might have to contact the manufacturerer :(

Here it is:

        Me.IcImagingControl1.AllowDrop = True
        Me.IcImagingControl1.DeviceState = "<device_state libver=""2.0"" filemajor=""1"" fileminor=""0"">" & Microsoft.VisualBasic.ChrW(10) & "    <device name=""DFK 31F" & _
        "03"" base_name=""DFK 31F03"" unique_name=""DFK 31F03 1001FDA4FD"">" & Microsoft.VisualBasic.ChrW(10) & "        <videoform" & _
        "at>UYVY (640x480)</videoformat>" & Microsoft.VisualBasic.ChrW(10) & "        <fps>15</fps>" & Microsoft.VisualBasic.ChrW(10) & "        <fliph>0</fliph>" & Microsoft.VisualBasic.ChrW(10) & " " & _
        "       <flipv>0</flipv>" & Microsoft.VisualBasic.ChrW(10) & "        <vcdpropertyitems>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{284C" & _
        "0E06-010B-45BF-8291-09D90A459B28}"" name=""Brightness"">" & Microsoft.VisualBasic.ChrW(10) & "                <element g" & _
        "uid=""{B57D3000-0AC6-4819-A609-272A33140ACA}"" name=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "                    <" & _
        "itf guid=""{99B44940-BFE1-4083-ADA1-BE703F4B8E03}"" value=""32"" />" & Microsoft.VisualBasic.ChrW(10) & "                " & _
        "</element>" & Microsoft.VisualBasic.ChrW(10) & "            </item>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{284C0E08-010B-45BF-8291-" & _
        "09D90A459B28}"" name=""Hue"">" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3000-0AC6-4819-A6" & _
        "09-272A33140ACA}"" name=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1-40" & _
        "83-ADA1-BE703F4B8E03}"" value=""63"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "            </it" & _
        "em>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{284C0E09-010B-45BF-8291-09D90A459B28}"" name=""Satura" & _
        "tion"">" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3000-0AC6-4819-A609-272A33140ACA}"" na" & _
        "me=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1-4083-ADA1-BE703F4B8E03" & _
        "}"" value=""32"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "            </item>" & Microsoft.VisualBasic.ChrW(10) & "            <ite" & _
        "m guid=""{284C0E0A-010B-45BF-8291-09D90A459B28}"" name=""Sharpness"">" & Microsoft.VisualBasic.ChrW(10) & "              " & _
        "  <element guid=""{B57D3000-0AC6-4819-A609-272A33140ACA}"" name=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "         " & _
        "           <itf guid=""{99B44940-BFE1-4083-ADA1-BE703F4B8E03}"" value=""8"" />" & Microsoft.VisualBasic.ChrW(10) & "     " & _
        "           </element>" & Microsoft.VisualBasic.ChrW(10) & "            </item>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{284C0E0B-010B" & _
        "-45BF-8291-09D90A459B28}"" name=""Gamma"">" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3000" & _
        "-0AC6-4819-A609-272A33140ACA}"" name=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B" & _
        "44940-BFE1-4083-ADA1-BE703F4B8E03}"" value=""0"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "    " & _
        "        </item>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{284C0E0D-010B-45BF-8291-09D90A459B28}"" " & _
        "name=""White Balance"">" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3001-0AC6-4819-A609-27" & _
        "2A33140ACA}"" name=""Auto"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1-4083-ADA" & _
        "1-BE703F4B8E04}"" value=""1"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "            </item>" & Microsoft.VisualBasic.ChrW(10) & "   " & _
        "         <item guid=""{284C0E0F-010B-45BF-8291-09D90A459B28}"" name=""Gain"">" & Microsoft.VisualBasic.ChrW(10) & "      " & _
        "          <element guid=""{B57D3000-0AC6-4819-A609-272A33140ACA}"" name=""Value"">" & Microsoft.VisualBasic.ChrW(10) & " " & _
        "                   <itf guid=""{99B44940-BFE1-4083-ADA1-BE703F4B8E03}"" value=""95""" & _
        " />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3001-0AC6-481" & _
        "9-A609-272A33140ACA}"" name=""Auto"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1" & _
        "-4083-ADA1-BE703F4B8E04}"" value=""0"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "            </" & _
        "item>" & Microsoft.VisualBasic.ChrW(10) & "            <item guid=""{90D5702E-E43B-4366-AAEB-7A7A10B448B4}"" name=""Expo" & _
        "sure"">" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57D3000-0AC6-4819-A609-272A33140ACA}"" na" & _
        "me=""Value"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1-4083-ADA1-BE703F4B8E03" & _
        "}"" value=""736"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "                <element guid=""{B57" & _
        "D3001-0AC6-4819-A609-272A33140ACA}"" name=""Auto"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""" & _
        "{99B44940-BFE1-4083-ADA1-BE703F4B8E04}"" value=""0"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & _
        "                <element guid=""{6519038C-1AD8-4E91-9021-66D64090CC85}"" name=""Aut" & _
        "o Reference Parameter"">" & Microsoft.VisualBasic.ChrW(10) & "                    <itf guid=""{99B44940-BFE1-4083-ADA1-" & _
        "BE703F4B8E03}"" value=""160"" />" & Microsoft.VisualBasic.ChrW(10) & "                </element>" & Microsoft.VisualBasic.ChrW(10) & "            </item>" & Microsoft.VisualBasic.ChrW(10) & "   " & _
        "     </vcdpropertyitems>" & Microsoft.VisualBasic.ChrW(10) & "    </device>" & Microsoft.VisualBasic.ChrW(10) & "</device_state>" & Microsoft.VisualBasic.ChrW(10)
        Me.IcImagingControl1.ImageRingBufferSize = 5
        Me.IcImagingControl1.LiveDisplayHeight = 480
        Me.IcImagingControl1.LiveDisplayWidth = 640
        Me.IcImagingControl1.Location = New System.Drawing.Point(0, 8)
        Me.IcImagingControl1.MemoryCurrentGrabberColorformat = TIS.Imaging.ICImagingControlColorformats.ICY8
        Me.IcImagingControl1.Name = "IcImagingControl1"
        Me.IcImagingControl1.Size = New System.Drawing.Size(640, 480)
        Me.IcImagingControl1.TabIndex = 0
as you may have noticed the vb-code simply creates an string that is containing an xml-document.

written in perl-style, using a HERE-document, the same thing look more straightforward of course:

$imaging->{DeviceState} = <<"DSTATE";
<device_state libver="2.0" filemajor="1" fileminor="0">
      <device name="DFK 31F03" base_name="DFK 31F03" unique_name="DFK 31F03 1001FDA4FD">
            <videoformat>UYVY (640x480)</videoformat>
                  <item guid="{284C0E06-010B-45BF-8291-09D90A459B28}" name="Brightness">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="32"/>
                  <item guid="{284C0E08-010B-45BF-8291-09D90A459B28}" name="Hue">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="63"/>
                  <item guid="{284C0E09-010B-45BF-8291-09D90A459B28}" name="Saturation">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="32"/>
                  <item guid="{284C0E0A-010B-45BF-8291-09D90A459B28}" name="Sharpness">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="8"/>
                  <item guid="{284C0E0B-010B-45BF-8291-09D90A459B28}" name="Gamma">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="0"/>
                  <item guid="{284C0E0D-010B-45BF-8291-09D90A459B28}" name="White Balance">
                        <element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="1"/>
                  <item guid="{284C0E0F-010B-45BF-8291-09D90A459B28}" name="Gain">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="95"/>
                        <element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0"/>
                  <item guid="{90D5702E-E43B-4366-AAEB-7A7A10B448B4}" name="Exposure">
                        <element guid="{B57D3000-0AC6-4819-A609-272A33140ACA}" name="Value">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="736"/>
                        <element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0"/>
                        <element guid="{6519038C-1AD8-4E91-9021-66D64090CC85}" name="Auto Reference Parameter">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="160"/>
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.