Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
This will generate a hash tree of all enums in a OLE library. Much cleaner and more organized than the flat hash that Win32::OLE::Const makes. This also shows some use of the undocumented Win32::OLE side.
#!/usr/bin/perl -w use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::TypeInfo qw( TKIND_ENUM ); use Data::Dumper; my $typelib = Win32::OLE::Const->LoadRegTypeLib('IP NAT Helper'); my $enumTree = TypeLibToEnums($typelib); print Dumper($enumTree); sub VAR_CONST () { 2 } sub TypeLibToEnums { my %rethash; my $typelib = $_[0]; die "TypeLibToEnums: not a Win32::OLE::TypeLib obj" if ! ref($typelib) || ! $typelib->isa('Win32::OLE::TypeLib'); my $typeinfocount = $typelib->_GetTypeInfoCount(); for(0..$typeinfocount-1){ my $typeinfo = $typelib->GetTypeInfo($_); if($typeinfo->_GetTypeAttr()->{'typekind'} == TKIND_ENUM){ $rethash{$typeinfo->_GetDocumentation(-1)->{'Name'}} = TypeInfoToEnumHash($typeinfo); } } return \%rethash; } sub TypeInfoToEnumHash { my %rethash; my $typeinfo = $_[0]; die "TypeInfoToEnumHash: not a Win32::OLE::TypeInfo obj" if ! ref($typeinfo) || ! $typeinfo->isa('Win32::OLE::TypeInfo' +); my $attrs = $typeinfo->_GetTypeAttr(); die "the TypeInfo is not an ENUM" if !$attrs->{'cVars'} || $attrs->{'typekind'} != TKIND_ENUM ; for(0..$attrs->{'cVars'}-1){ my $vardesc = $typeinfo->_GetVarDesc($_); #check done in OLE.xs below not needed #die "the TypeInfo is not an ENUM" # if $vardesc->{'varkind'} != VAR_CONST; $rethash{$typeinfo->_GetDocumentation($vardesc->{'memid'})->{' +Name'}} = $vardesc->{'varValue'}; } return \%rethash; }
output
$VAR1 = { "ICOMMONCONFIG_DISPIDS" => { "ICOMMONCONFIG_DISPID_ENABLEDFO +RINTERNET" => 5, "ICOMMONCONFIG_DISPID_GETCOMMON +LINKPROPERTIES" => 14, "ICOMMONCONFIG_DISPID_GETTOTALB +YTESRECEIVED" => 17, "ICOMMONCONFIG_DISPID_GETTOTALB +YTESSENT" => 16, "ICOMMONCONFIG_DISPID_GETTOTALP +ACKETSRECEIVED" => 19, "ICOMMONCONFIG_DISPID_GETTOTALP +ACKETSSENT" => 18, "ICOMMONCONFIG_DISPID_LAYER1DOW +NSTREAMMAXBITRATE" => 2, "ICOMMONCONFIG_DISPID_LAYER1UPS +TREAMMAXBITRATE" => 1, "ICOMMONCONFIG_DISPID_MAXIMUMAC +TIVECONNECTIONS" => 11, "ICOMMONCONFIG_DISPID_PHYSICALL +INKSTATUS" => 3, "ICOMMONCONFIG_DISPID_SETENABLE +DFORINTERNET" => 4, "ICOMMONCONFIG_DISPID_TOTALBYTE +SRECEIVED" => 7, "ICOMMONCONFIG_DISPID_TOTALBYTE +SSENT" => 6, "ICOMMONCONFIG_DISPID_TOTALPACK +ETSRECEIVED" => 9, "ICOMMONCONFIG_DISPID_TOTALPACK +ETSSSENT" => 8, "ICOMMONCONFIG_DISPID_WANACCESS +PROVIDER" => 10, "ICOMMONCONFIG_DISPID_WANACCESS +TYPE" => 0, "ICOMMONCONFIG_DISPID_XGETICSST +ATISTICS" => 15, "ICOMMONCONFIG_DISPID_XPERSONAL +FIREWALLENABLED" => 12, "ICOMMONCONFIG_DISPID_XUPTIME" +=> 13 }, "IOSINFO_DISPIDS" => { "IOSINFO_DISPID_MAGICON" => 1, "IOSINFO_DISPID_OSBUILDNUMBER" => 4, "IOSINFO_DISPID_OSMACHINENAME" => 5, "IOSINFO_DISPID_OSMAJORVERSION" => 2, "IOSINFO_DISPID_OSMINORVERSION" => 3 }, "IWANIPCONNECTION_DISPIDS" => { "IWANIPCONNECTION_DISPIDS_MA +GICON" => 1, "IWANIPCONNECTION_DISPID_ADD +PORTMAPPING" => 32, "IWANIPCONNECTION_DISPID_CON +NECTIONSTATUS" => 4, "IWANIPCONNECTION_DISPID_CON +NECTIONTYPE" => 2, "IWANIPCONNECTION_DISPID_DEL +ETEPORTMAPPING" => 33, "IWANIPCONNECTION_DISPID_DOW +NSTREAMMAXBITRATE" => 7, "IWANIPCONNECTION_DISPID_EXT +ERNALIPADDRESS" => 12, "IWANIPCONNECTION_DISPID_EXT +ERNALPORT" => 14, "IWANIPCONNECTION_DISPID_FOR +CETERMINATION" => 26, "IWANIPCONNECTION_DISPID_GET +CONNECTIONTYPE" => 24, "IWANIPCONNECTION_DISPID_GET +EXTERNALIPADDRESS" => 34, "IWANIPCONNECTION_DISPID_GET +GENERICPORTMAPPINGENTRY" => 31, "IWANIPCONNECTION_DISPID_GET +LINKLAYERMAXBITRATES" => 29, "IWANIPCONNECTION_DISPID_GET +NATRSIPSTATUS" => 28, "IWANIPCONNECTION_DISPID_GET +SPECIFICPORTMAPPINGENTRY" => 30, "IWANIPCONNECTION_DISPID_GET +STATUSINFO" => 27, "IWANIPCONNECTION_DISPID_INT +ERNALCLIENT" => 17, "IWANIPCONNECTION_DISPID_INT +ERNALPORT" => 15, "IWANIPCONNECTION_DISPID_LAS +TCONNECTIONERROR" => 8, "IWANIPCONNECTION_DISPID_NAM +E" => 11, "IWANIPCONNECTION_DISPID_NAT +ENABLED" => 10, "IWANIPCONNECTION_DISPID_POR +TMAPPINGDESCRIPTION" => 18, "IWANIPCONNECTION_DISPID_POR +TMAPPINGENABLED" => 19, "IWANIPCONNECTION_DISPID_POR +TMAPPINGLEASEDURATION" => 20, "IWANIPCONNECTION_DISPID_POR +TMAPPINGNUMBEROFENTRIES" => 22, "IWANIPCONNECTION_DISPID_POR +TMAPPINGPROTOCOL" => 16, "IWANIPCONNECTION_DISPID_POS +SIBLECONNECTIONTYPES" => 3, "IWANIPCONNECTION_DISPID_REM +OTEHOST" => 13, "IWANIPCONNECTION_DISPID_REQ +UESTCONNECTION" => 25, "IWANIPCONNECTION_DISPID_RSI +PAVAILABLE" => 9, "IWANIPCONNECTION_DISPID_SET +CONNECTIONTYPE" => 23, "IWANIPCONNECTION_DISPID_UPS +TREAMMAXBITRATE" => 6, "IWANIPCONNECTION_DISPID_UPT +IME" => 5, "IWANIPCONNECTION_DISPID_XPO +RTMAPPINGINDEX" => 21 }, "IWANPOTSLINKCONFIG_DISPIDS" => { "IWANPOTSLINKCONFIG_DISPID +S_MAGICON" => 1, "IWANPOTSLINKCONFIG_DISPID +_DELAYBETWEENRETRIES" => 6, "IWANPOTSLINKCONFIG_DISPID +_GETCALLRETRYINFO" => 8, "IWANPOTSLINKCONFIG_DISPID +_GETISPINFO" => 7, "IWANPOTSLINKCONFIG_DISPID +_ISPINFO" => 3, "IWANPOTSLINKCONFIG_DISPID +_ISPPHONENUMBER" => 2, "IWANPOTSLINKCONFIG_DISPID +_LINKTYPE" => 4, "IWANPOTSLINKCONFIG_DISPID +_NUMBEROFRETRIES" => 5 } };

In reply to a hash tree of all OLE enums in a OLE library by bulk88

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (6)
    As of 2014-10-24 08:31 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (131 votes), past polls