Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

'emptyenum' error w/ use Win32::OLE::Const 'Microsoft Word'

by ff (Hermit)
on Mar 02, 2005 at 13:51 UTC ( [id://435825]=perlquestion: print w/replies, xml ) Need Help??

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

Hello monks,
I'm exercising the nuclear option of debugging that isn't a choice on the current poll of debugging methods, i.e. I'm hoping that SoPW can shed light. A previous post (Re: RE (tilly) 1: Win32::OLE) mentions the same problem and there is a reply that says emptyenum is being used twice. But where? By what? How can I influence the running of Win32::OLE::Const?

My program is generating a series of 15 messages like:

Constant subroutine emptyenum redefined at C:/Perl/site/lib/Win32/OLE/Const.pm line -1.

The warnings do seem to be harmless because my program is creating the Word documents that I want via templates. My problems are:
1. I'd like to be positive these messages are harmless and won't cause me problems if I leave them alone.
2. If harmless, I'd be okay with turning off warnings before/after Const invocation but the documentation about them seems to say that these errors are so important that they can't be muted. Of course I could temporarily send errors to a meaningless error file but that seems like asking for trouble later on.
3. Is it possible to fix the problems that are causing the warnings?

While it was mentioned that emptyenum was being run more than once, that didn't do much for me because I couldn't see anywhere where it WAS being run. I couldn't find it in Const.pm nor in my own code. However, I did pull out my handy-dandy OLE browser that comes with ActiveState's perl and noticed that

# Type Library Browser for wdCharacterCaseHID shows emptyenum

Now there's zillions of little pieces of stuff that is investigatable (?) about MS Word with that tool and it was mostly a shot in the dark that elicited that nugget. But not a total shot, as relevant lines from my code include:

use Win32::Shortcut; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; my $x = Win32::OLE->GetActiveObject('Word.Application'); # snip $x->Selection->Delete( { Unit=>wdCharacter, Count=>1 } ); # The above is my kiddy-scripted version of some VisualBasic that I # came upon: Selection.Delete Unit:=wdCharacter, Count:=1

which is what made me check out the properties of wdCharacterCaseHID. Now, that nugget may be totally irrelevant whereupon I'm exhibiting my cluelessness about what to do.

Some cluck commands that I embedded into Const.pm also give some results that puzzle me. When the code above runs (the code is in a sub called 'word_subs.pl' in a package called 'ws'), cluck tells me:

ws::BEGIN() called at C:/Perl/site/lib/Win32/OLE/Const.pm line 120

Line 120 is the line in 'word_subs.pl' above that invokes Const.pm.

However, when my main program gets around to invoking a different sub ('out_subs.pl' from a different package 'email_out'), and that sub has lines including:

use strict; use warnings; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook';

then cluck tells me:

email_out::BEGIN() called at out_subs.pl line 1027

and in this case cluck's output seems to properly notify that the Const.pm module was being invoked from line 1027 of out_subs.pl (the line with the 'Microsoft Outlook' string). The fact of no complaints from the Outlook stuff would seem to say that emptyenum is being used strangely within Word....

Replies are listed 'Best First'.
Re: 'emptyenum' error w/ use Win32::OLE::Const 'Microsoft Word'
by guha (Priest) on Mar 02, 2005 at 15:57 UTC

    There is another way to get to the Word-constants, which in my experience is more stable, when there are many constants, as there indeed are in Word.

    I would like to encourage you to try this instead to see if it helps:
    use Win32::Shortcut; use Win32::OLE qw(in with); use Win32::OLE::Const; ##=>Changed my $wdc = Win32::OLE::Const->Load("Microsoft Word"); ##=>Added my $x = Win32::OLE->GetActiveObject('Word.Application'); # snip $x->Selection->Delete( { Unit=> $wdc->{wdCharacter}, ##=>Changed Count=>1 } );

    Searching through some old email conversations with jand, the author/maintainer of Win32::OLE, from 2002 I found this.

    >>Another feature is that standard way to handle wdCONSTANTS >> >>use Win32::OLE::Const 'Microsoft Word'; >> >>does not work anymore, I resorted to >> >>use Win32::OLE::Const; >>.... >> $obj->{_WD} = Win32::OLE::Const->Load("Microsoft Word"); # 9.0 Obje +ct >>Library"); > > Hmm, do you get any errors or anything? > "Constant subroutine emptyenum redefined at C:/DEV/Perl/site/lib/Win32/OLE/Const. pm line 65535." times 13 (Bad luck ??)

    Nothing new under the sun, it seems. But the indicated way works.

    Notice that your erroneous linenumber is -1 whereas mine is 65535, 16 bit integers or what?

    HTH

      ++guha!

      Success! Thank you. No more emptyenum complaints (at least after initial testing. :-)

      I applied your suggestion to all such wd occurrences:

      # instead of: # $x->Selection->Collapse( { Direction=>wdCollapseEnd } ); # do: $x->Selection->Collapse( { Direction=>$wdc->{wdCollapseEnd} } );

      As this example also shows, I left other Word-particular terms (such as Selection, Collapse, Direction) alone.

      P.S. Yes, I wondered why mine had -1 when others had 65535, but that was a weirdness to leave for another time.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://435825]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-24 13:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found