Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to use ActiveX control with PERL?

Posted on 2004-11-19
11
Medium Priority
?
1,342 Views
Last Modified: 2008-01-09
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!!
0
Comment
Question by:sapbucket
  • 6
  • 3
  • 2
11 Comments
 
LVL 6

Expert Comment

by:sstouk
ID: 12630995
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.
0
 
LVL 3

Author Comment

by:sapbucket
ID: 12631790
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
0
 
LVL 3

Author Comment

by:sapbucket
ID: 12631809
I will increase this to 500 points if I can get a solid answer :)
0
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!

 
LVL 6

Expert Comment

by:sstouk
ID: 12631983
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.

0
 
LVL 3

Author Comment

by:sapbucket
ID: 12640865
I'm still in need of an answer, anyone know?
0
 
LVL 6

Accepted Solution

by:
holli earned 1000 total points
ID: 12662986
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

Interop.Camera

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

ImagingControl

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";
$imaging->LiveStart();

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

regards,
holli




0
 
LVL 3

Author Comment

by:sapbucket
ID: 12664109
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?
0
 
LVL 6

Expert Comment

by:holli
ID: 12666299
>>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

0
 
LVL 3

Author Comment

by:sapbucket
ID: 12670394
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 :)
0
 
LVL 3

Author Comment

by:sapbucket
ID: 12670485
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
0
 
LVL 6

Expert Comment

by:holli
ID: 12672789
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
0

Featured Post

Industry Leaders: 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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

578 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