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

Thanks to the wisdom of the Monks who helped me before, I have Win32::OLE working. I have found several examples of controlling Excel and Word and have been able to make them work.

Now I'm trying to get started on my real application and am once again in need of understanding and enlightenment.

The problem is that the application I want to access is a non-Microsoft program from a third party and which doesn't provide a lot in the way of documentation. I have some VB examples, but I'm not having much success translating them to Perl.

I use OLE-Browser and see the library (HALiCnt) that contains the functions I want to access. I see the class (HALi) and Function {Function Init() As Boolean}. But the rub is that I don't know what the Application Name is. That is when creating the OLE Server Object:

my $server = WIn32::OLE->new('xxx.Application')
Nothing I can put in for the xxx seems to be right. I think what I am looking for here is the 'Root name' if I interpret some documentation I have seen correctly, so I guess the question is "How do I find the Root Name of an arbitrary server?"

I have also tried many different combinations of GetActiveObject as well as new to no avail. The usual error is something like "invalid Class String"

I have searched the tutorials in the Monastery, as well as CPAN and so on, but every tutorial seems to assume I want to control Excel, Word or some other such application.

Is there a good document on interfacing to an arbitrary application about which little is known? How about something on taking VB OLE examples and translating them to Perl. I know about arrows instead of dots and such, but not much more.

I fear I am going to be forced to learn VB and to write my application in VB unless the Monks can show me the way.

Thanks,

Nathan

Replies are listed 'Best First'.
Re: More on OLE from Perl
by Mr. Muskrat (Canon) on Jun 13, 2004 at 18:31 UTC

    You say that you have some VB examples. Looking at them should give you some idea of what name to use in Perl. Perhaps it's a CLSID? If so, you do something like:

    my $app = Win32::OLE->new('{12345678-9ABC-DEF0-1234-56789ABCDEF0}'); # substitute the real CLSID or ProgID

    Would you show us the VB examples and the Perl code that you tried? We give much better answers if we have something to work with.

      Ok, here's the setup from the VB form sample. Note the CLSID string, and the reference to the ocx module.
      VERSION 5.00
      Object = "{9EA22D70-0EAA-4F54-80BB-3AA640DF1B96}#2.0#0"; "HALi.ocx"
      Begin VB.Form Form1 
      ...blah...blah...
      
      So I tried this
      use Win32::OLE;
      my $HALi = Win32::OLE->new('{9EA22D70-0EAA-4F54-80BB-3AA640DF1B96}');
      
      When I run it, it does not return any errors. Cool!

      So I move to the next step and add the init function.

      The VB init is:

      HALi.Init()
      
      So I translate this to:
      $HALi->{HALi}->Init();
      
      I get a "Can't call method Init on undefined value" error.

      It's late and I'm tired, and probably missing something obvious. I'm getting past the server creation, but hanging on the init function. Maybe a fresh look tomorrow will show me the error of my ways. Suggestions appreciated.

      Nathan

        It looks like all you need is $HALi->Init();. The extra ->{HALi} wasn't in the VB snippet you provided.
      Yes, they have the CLSID. Doh! Using that never occurred to me. I'll try it.

      Nathan