http://www.perlmonks.org?node_id=443406

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

Hello,
I have to find a GUID of type library (or type library name) for a given OLE object name. I.e. for 'Excel.Applicaiton' it should return either 'Microsoft Excel 9.0 Object LIbrary' or its GUID. If possible, without creating OLE object 'Excel.Application'! I digged in the registry and didn't find information associated with "sections" named 'Excel.Application' that allow to retrive this information.. But OLE does this somehow..
If there is no Perl way of doing it, could you please suggest C API name that allows to do it?

Thanks in advance for your answers!

  • Comment on How to find GUID of Typelibrary for a given OLE Object?

Replies are listed 'Best First'.
Re: How to find GUID of Typelibrary for a given OLE Object?
by Thelonious (Scribe) on Mar 30, 2005 at 11:54 UTC
    I don't have that version of Excel installed, so I looked up Outlook instead:

    use Win32::TieRegistry; my $clsid = $Registry->{'HKEY_LOCAL_MACHINE\SOFTWARE\Classes'. '\Outlook.Application\CLSID\\'}->{'\\'}; print $Registry->{'HKEY_CLASSES_ROOT\CLSID\\'.$clsid}->{'\\'}; __END__ Microsoft Outlook 8.0 Object Library

    I didn't find the GUID. I hope someone else can help with that...

    hth

      You do have the "GUID" - that's what is in the $clsid there - or rather that is a GUID.

      /J\

      Thank you for your answer!

      But if I apply your solution to 'Excel.Application' it prints 'Microsoft Excel' (that is NOT a type library, since Win32::OLE::Const->EnumTypeLibs() call doesn't list it as type library). But for some reason your solution works the way I dreamed about for 'Outlook.Application' ( I would find out it too if I digged in registry using 'Outlook.Application' as a sample).

      Does anybody have any other ideas?

Re: How to find GUID of Typelibrary for a given OLE Object?
by barbie (Deacon) on Mar 30, 2005 at 14:02 UTC
    I believe the following is the kind of thing you're after:
    package Typelibs; use warnings; use strict; use Win32::OLE::Const; # list of all registered type libraries my @Library; Win32::OLE::Const->EnumTypeLibs(sub { my ($clsid,$title,$version,$langid,$filename) = @_; return unless $version =~ /^([0-9a-fA-F]+)\.([0-9a-fA-F]+)$/; my ($maj,$min) = (hex($1), hex($2)); push @Library, [$clsid,$title,$maj,$min,$langid,$filename]; }); sub ExistsTypeLib { my $typelib = shift; for my $lib (@Library) { return @$lib if($lib->[1] =~ /^$typelib/); } return undef; } 1;

    You can then call TypeLibs::ExistsTypeLib('Microsoft Excel') and it should return a list consisting of the ClassID, Title, Major Version Number, Minor Version Number, LanguageID, and Executable Filename.

    I now have a modified version to check whether Outlook is installed for my Outlook CPAN modules.

    --
    Barbie | Birmingham Perl Mongers user group | http://birmingham.pm.org/

      Ooops. Actually the return undef should be return () in this instance.

      --
      Barbie | Birmingham Perl Mongers user group | http://birmingham.pm.org/

      Thank you for your sample, but your code won't return anything for 'Excel.Application' (since the type library in question is named 'Microsoft Excel 9.0 Object Library'.. Do you have any other ideas?
        This is the PROGID, which doesn't appear to be returned by Win32::OLE. However you could cheat and add the following to the previous code:
        sub ApplicationTypeLib { my $typelib = shift; $typelib =~ s/\.Application//; for my $lib (@Library) { return @$lib if($lib->[1] =~ /$typelib/); } return (); }

        --
        Barbie | Birmingham Perl Mongers user group | http://birmingham.pm.org/