Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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

by Anonymous Monk
on Mar 30, 2005 at 10:52 UTC ( #443406=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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...


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


      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 |

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

      Barbie | Birmingham Perl Mongers user group |

      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 |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://443406]
Approved by Corion
and the leaves swirl about...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (11)
As of 2018-06-21 13:16 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (118 votes). Check out past polls.