Link to home
Start Free TrialLog in
Avatar of sapbucket
sapbucket

asked on

How to use ActiveX control with PERL?

Hello,

  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->Cmethod(undef,undef,$Arg3);
    $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.

  Thanks!

  Thanks!!
Avatar of Sergy Stouk
Sergy Stouk
Flag of Canada image

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.
Avatar of sapbucket
sapbucket

ASKER

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
        IcImagingControl1.LiveStart()
        ' 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
        IcImagingControl1.LiveStart()
        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
        IcImagingControl1.LiveStop()
        If VideoHasStarted = True Then
            VideoHasStopped = True
        End If

        Status.Text = "Live Camera Feed has been stopped"
    End Sub
I will increase this to 500 points if I can get a solid answer :)
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
{00024500-0000-0000-C000-000000000046}
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.

I'm still in need of an answer, anyone know?
ASKER CERTIFIED SOLUTION
Avatar of holli
holli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
holli,

  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)

AxInterop.ICImageControl
imagingcontrol
Interop.ICImagingControl

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";
$imaging->LiveStart();
$imaging->MemorySaveImage("c:\\ocr\\test.bmp");

ok, first attempt:
C:\OCR\Dev>perl testActiveX.pl
Win32::OLE(0.1701) error 0x800401f3: "Invalid class string" at testActiveX.pl line 5
        eval {...} called at testActiveX.pl line 5
oops

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";
$imaging->LiveStart();
$imaging->MemorySaveImage("c:\\ocr\\test.bmp");

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 ...new('foo.goo')...?

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 ...new('foo.goo')...?
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.

regards,

holli

holli,

   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 :)
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:

'IcImagingControl1
        '
        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>
            <fps>15</fps>
            <fliph>0</fliph>
            <flipv>0</flipv>
            <vcdpropertyitems>
                  <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"/>
                        </element>
                  </item>
                  <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"/>
                        </element>
                  </item>
                  <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"/>
                        </element>
                  </item>
                  <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"/>
                        </element>
                  </item>
                  <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"/>
                        </element>
                  </item>
                  <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"/>
                        </element>
                  </item>
                  <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>
                        <element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0"/>
                        </element>
                  </item>
                  <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>
                        <element guid="{B57D3001-0AC6-4819-A609-272A33140ACA}" name="Auto">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E04}" value="0"/>
                        </element>
                        <element guid="{6519038C-1AD8-4E91-9021-66D64090CC85}" name="Auto Reference Parameter">
                              <itf guid="{99B44940-BFE1-4083-ADA1-BE703F4B8E03}" value="160"/>
                        </element>
                  </item>
            </vcdpropertyitems>
      </device>
</device_state>
DSTATE