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

Win32::OLE -- translation from vbs to pl

by whumann (Acolyte)
on Aug 27, 2013 at 17:45 UTC ( #1051175=perlquestion: print w/replies, xml ) Need Help??
whumann has asked for the wisdom of the Perl Monks concerning the following question:

I've recently translated some OLE code from vbs to perl and in most cases it went quite well. The following however I can't get working. vbs-code:
Dim pcbApp Set pcbApp = GetObject(, "MGCPCB.ExpeditionPCBApplication") Dim pcbDoc Set pcbDoc = pcbApp.ActiveDocument Dim key key = pcbDoc.Validate(0) Dim licenseServer Set licenseServer = CreateObject("MGCPCBAutomationLicensing.Applicatio +n") Dim licenseToken licenseToken = licenseServer.GetToken(key) msgbox licenseToken
translated like this:
use strict; use warnings; use Win32::OLE; my $pcbApp; eval {$pcbApp = Win32::OLE->GetActiveObject('MGCPCB.ExpeditionPCBAppli +cation')}; die "Expedition not installed" if $@; die "Expedition not running" unless defined $pcbApp; my $pcbDoc = $pcbApp->ActiveDocument; die "No active document." unless $pcbDoc; my $key = $pcbDoc->Validate(0); my $licenseServer = Win32::OLE->new('MGCPCBAutomationLicensing.Applica +tion'); die "Automation license acquisition failed: " . Win32::OLE::LastError( +) unless defined $licenseServer;
The vbs code runs and displays the licenseToken at the end. The perl code fails with
Automation license acquisition failed: Win32::OLE(0.1709) error 0x8007 +007e: "The specified module could not be found"
Using 'CreateObject' instead of 'new' doen't change anything (from the docs I expect them to be equivalent). Any idea how to track down the source of this error?


Replies are listed 'Best First'.
Re: Win32::OLE -- translation from vbs to pl
by Anonymous Monk on Aug 28, 2013 at 00:20 UTC

    More info might be found in the event viewer

    But, you should check registry for MGCPCBAutomationLicensing..., check to see that the assoiated .dll can be located, and all the prerequisites it has can be located, located and loaded

    you can use depends.exe ....

    or you simply might need to Win32::OLE->Initialize to a different model

      I don't know the Event Viewer too well. I looked at some logs but couldn't find anything related. Probably looked in the wrong place (or didn't know what to look for). Additonal poiters where to look appreciated!

      The registry entries, as far as my weak knowledge goes, look o.k.. I also wouldn't exepect a problem here when the vbs works fine.

      Dependency Walker reports it can't find GPSVC.DLL and IESHIMS.DLL, but these dependencies are deep down in MGCPCBAUTOMATIONLICENSING.DLL -> ADVAPI32.DLL -> WINTRUST.DLL -> CRYPT32.DLL -> .... Not sure what to make of that.

      All three possible values for Win32::OLE->Initialize() don't make a diference.

      There's a thread here about someone with problems porting the same code form to C#. I'm not sure if his solution (adding a reference to the appropriate COM object in visual studio) has any perl equivalent.

      Any additional ideas available? Thanks, Wolfram
        You arent using Dependenc Walker the best way. DW has a "Profile" feature. You will have to pick perl.exe, give it command args, and run the perl process in DW. This way all GetProcAddress and LoadLibrary es will be loged. The "The specified module could not be found" message will appear in there probably or its Win32 error code equivelent (0x8******* codes are Native API/COM error codes, not GetLastError codes). What you were looking at in your post was STATIC analysis. You did put the Initialize() before any other Win32::OLE calls except the use right? Worst case, stepping Win32::OLE's XS code is the only way to figure out what happened and what exactly went wrong. I've done it before to Win32::OLE and found a bug in Win32::OLE that already was on OLE's RT page.

        Written on a smart phone so sorry for spelling mistakes.
        oh yeah, what bulk88 is saying, try using depends.exe like this   depends.exe /c /f:1 /pb /ot:temp.txt ...perl.exe ...
      you simply might need to Win32::OLE->Initialize to a different model ...

      In cursorily reading this quote, here I really wish that you were not “Anonymous” (or that PM had not logged you out at the wrong instant ...), because I really would like to know more-specifically just what you meant by this.   Intuitively, it seems like this is most likely to be the crux of the problem.   After all, if the VB program works (although I notice that the two are not exactly the same at the end...), reason says that the Perl “equivalent” should do so, too.   If the registry entry were bad, neither program would work...

      So, “for those of us in the Peanut Gallery,” could you please elaborate on this?   What are the choices here?   How do they affect the program’s behavior? ...

      (Let’s make this thread as one-stop-shopping useful as possible to the Gentle Readers three years hence...)

        In cursorily ...

        read the documentation Win32::OLE->Initialize

Re: Win32::OLE -- translation from vbs to pl
by whumann (Acolyte) on Aug 28, 2013 at 13:15 UTC

    Some more info that I don't know what to do with -- but maybe others know: Using Microsoft's OLE/COM Object Viewer I find 'MGCPCB.ExpeditionPCBApplication' under Automation Objects but 'MGCPCBAutomationLicensing' under Type Libraries. In coclass 'Application', a method 'GetToken' is listed, so everything looks fine here.

    It even looks like the access to the 'MGCPCBAutomationLicensing' Type Library works up to a point: when I change the class name to something other than 'Application' the error message changes from '...module could not be found' to 'error 0x800401f3: "Invalid class string"'

    Regards, Wolfram
Re: Win32::OLE -- translation from vbs to pl
by sundialsvc4 (Abbot) on Aug 28, 2013 at 20:50 UTC

    Do you see anything at all in the Event Viewer application?   Any app-level messages that OLE might have placed there?

      Well, in Event Viewer -> Windows Logs -> Application there are messages from 'Office Software Protection Platform Service', 'Security-SPP', 'Windows Error Reporting' and many others. But nothing form Perl or MGCPCBAutomationLicensing or anything I would connect to my issue.
Re: Win32::OLE -- translation from vbs to pl
by whumann (Acolyte) on Aug 30, 2013 at 12:43 UTC
    A partial solution: as an experiment just downloaded a 32bit strawberry perl 5.16.3 (instead of the 64bit 5.16.2 I use as default) and there it works: loading MGCPCBAutomationLicensing, getting and validating the licenseToken and then working with the validated $pcbDoc.

    However, I have no idea WHY it works here...
      probably you can't mix 32bit and 64bit dlls

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1051175]
Front-paged by Corion
holli yawns

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2017-09-24 11:43 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (274 votes). Check out past polls.