Grab an ActiveX event

I'm currently working with a fingerprint reader SDK that we're calling an ActiveX method. The problem is that we need to grab an event that is fired from the device in order to get the ID of the device we want to call with the method. I've read some about the Win32::OLE->WithEvent() but do not know how to tailor it to my situation, or if its even possible.

There is an event like below:

private: System::Void axGrFingerXCtrl2_SensorPlug(System::Object *  sender, _IGrFingerXCtrlEvents_SensorPlugEvent *  e) {
axGrFingerXCtrl2->CapStartCapture(e->idSensor);
}

We need to use Perl to get an ID of the fingerprint reader that is returned with the event call. Is there anyway to grab an even like this, and if so how?
scanhelpAsked:
Who is Participating?
 
clockwatcherConnect With a Mentor Commented:
Try:

package FingerEventHandlers;

sub SensorPlug {
  my ($self, $idSensor) = @_;
  print "$idSensor plugged in\n";
  print $self->CapStartCapture($idSensor);
 
}

sub SensorUnplug {
  my ($self, $idSensor) = @_;
  print "$idSensor was unplugged\n";
}

sub FingerDown {
  my ($self, $idSensor) = @_;
  print "Got a finger down from $idSensor\n";
}

sub FingerUp {
  my ($self, $idSensor) = @_;
  print "Got a finger up from $idSensor\n";
}

sub ImageAcquired {
  my ($self, $idSensor, $width, $height, $rawImage, $res) = @_;
  print "Got an image $width x $height\n";
}

1;

package main;

use strict;
use Win32::OLE qw(EVENTS);

my $finger = Win32::OLE->new("GrFingerX.GrFingerXCtrl");

Win32::OLE->WithEvents($finger, 'FingerEventHandlers');
$finger->Initialize();
$finger->CapInitialize();

Win32::OLE->MessageLoop();
0
 
clockwatcherCommented:
Do you have a non dotnet sample to look at?  Or a link to the SDK documentation for the device you're using?
0
 
tone28Commented:
Without knowing how you are creating the ActiveX objects in perl I would recommend reading this example.

http://www.perl.com/pub/a/2005/04/21/win32ole.html

Plus have you had a chance to look at the perldoc for OLE?

Tone
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
scanhelpAuthor Commented:
We're using the GrFinger SDK (http://www.griaule.com/page/en-us/grfinger_sdk). I've been scanning the Win32::OLE documentation to get an idea of how to model the way they handle events with the OLE->WithEvents() but have been unable to make it work. At this point im not sure if it is possible or whether I'm just not doing it right.
0
 
clockwatcherCommented:
Can't test it because I don't have a fingerprint device, but I think this will work:

example.pl
-------------

package FingerEventHandlers;

sub SensorPlug {
  my ($self, $idSensor) = @_;
  print "$idSensor was plugged in\n";
}

sub SensorUnplug {
  my ($self, $idSensor) = @_;
  print "$idSensor was unplugged\n";
}

sub FingerDown {
  my ($self, $idSensor) = @_;
  print "Got a finger down from $idSensor\n";
}

sub FingerUp {
  my ($self, $idSensor) = @_;
  print "Got a finger up from $idSensor\n";
}

sub ImageAcquired {
  my ($self, $idSensor, $width, $height, $rawImage, $res) = @_;
  print "Got an image $width x $height\n";
}

1;

package main;

use strict;
use Win32::OLE qw(EVENTS);

my $finger = Win32::OLE->new("GrFingerX.GrFingerXCtrl");
Win32::OLE->WithEvents($finger, 'FingerEventHandlers', '_IGrFingerXCtrlEvents');
Win32::OLE->MessageLoop();
0
 
scanhelpAuthor Commented:
I'm not getting flags showing anything invalid in the handling. I am getting a compile error in the line:

Win32::OLE->WithEvents($finger, 'FingerEventHandlers', '_IGrFingerXCtrlEvents');

The error says "Win32::OLE error 0x80070057: 'The parameter is incorrect' at FingerEventHandlers". I was looking up what could be the cause of this and found an article interactiing with IE, which says that M$ sends back data in an invalid format. Do you believe that this could be the case in this application? The main point behind this entire program is to just save the scanned image file to the local disk, and part of doing that is handling these events as no image can be saved without handling these events. So I'm stuck at this point until I can figure this out. Any suggestions?
0
 
clockwatcherCommented:
At compile time?  What do you get with?  

 perl -cw example.pl

The error you're describing doesn't sound possible to get at compile-time.  Can you post the exact error with line number?

Also try just this:

example2.pl
--------------
use strict;
use Win32::OLE qw(EVENTS);

sub ehandler {
  my ($obj, $event) = @_;
  print "$event\n";
}

my $finger = Win32::OLE->new("GrFingerX.GrFingerXCtrl");
Win32::OLE->WithEvents($finger, \&ehandler, '_IGrFingerXCtrlEvents');
Win32::OLE->MessageLoop();

And let me know what you get back.
0
 
scanhelpAuthor Commented:
example2.pl is giving the same error message as example.pl.

I am using Perl Express IDE, with ActivePerl Interpreter.

Here is the error message that I am receiving:
Win32::OLE(0.1703) error 0x80070057; "The parameter is incorrect" at example2.pl line 12
  eval(...) called at example2.pl line 12
0
 
scanhelpAuthor Commented:
Okay that got it working, thank you.  I plan on giving you the allotted points, but could you answer a couple more thing for me.

I am trying to host this on a server, so the user can scan their finger and save it to the server.

What is the best way to deploy this so it runs on the client-side?  Will the user need to install the Perl runtime?
0
 
clockwatcherCommented:
I recommend packaging it up into an executable with PerlApp from the ActiveState Perl Dev Kit (http://www.activestate.com/Products/Perl_Dev_Kit/?tn=1) and deploying the executable.  If that's not an option and you want to run this client-side in perl, then you'll need to include a perl install with your app.  You'll also (of course) need to install Griaule's ActiveX control on the client.  

Personally, I'd probably write up a C/C++ XS wrapper around their standard DLL (rather than screw with their ActiveX one) and package the whole thing up with PerlApp.  Depending on the extent you're going to be using the library, you may even be able to get away with Win32::API and Win32::API::Callback.
0
 
scanhelpAuthor Commented:
Clockwatcher you’ve been an astounding help on this pet project. I very much appreciate your time and consideration on this matter. Please accept these points and our thanks for the help. Your feedback has been invaluable.
0
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.

All Courses

From novice to tech pro — start learning today.