1

We have a legacy perl code base that includes the below line:

use Win32::OLE::Const 'Microsoft Excel';

This has worked traditionally but is not working on newer 64-bit installations, such as Windows 10.

The error appears to be in the OLE.xs source as below, but I have a limited understanding of Windows functions and XS in general.

err = RegQueryValueA(hKeyLangid, "win32", szFile, &cbFile);

If this query fails, it never calls Win32::OLE::Const::_Typelib which is the function that stores the result. Checking my registry, the keys are indeed Win64 and not win32. Other keys that worked either have just win32 or both.

Is there a way to resolve this issue without editing the legacy module? It is widely used and any changes would involve some risk so I'm looking at alternatives first.

I'm aware we can do the below, but it doesn't stop the other Win32::OLE::Const line causing an error if it's not removed.

my $Excel = Win32::OLE->new('Excel.Application', 'Quit');
my $xl = Win32::OLE::Const->Load($Excel);
Nick P
  • 759
  • 5
  • 20
  • I do not see how to achieve that without changing the source code, given the value is hard coded. XS is perl's interface to call C/C++ code, btw. I cannot help myself, I've got to point out that the module is literally called 'Win32::OLE', so I don't know why you'd expect it to work on 64 bit Windows. – bytepusher Dec 28 '18 at 04:31
  • Seems like a duplicate of https://stackoverflow.com/questions/25509960/how-to-make-win32ole-work-on-64bit-ms-office-installation That seems like a simple workaround not requiring you to change the module, fwiw. – bytepusher Dec 28 '18 at 04:33
  • @bytepusher agreed that's the exact issue. So if adding the registry key is safe, then I guess we'll have to go down that path and roll out a patch to all our machines. – Nick P Dec 28 '18 at 12:57
  • well if the fix is only to replace the registry key - how about you put win64::OLE on cpan :) – bytepusher Dec 28 '18 at 15:53

1 Answers1

0

I'll provide a fix in case anyone wants to use it. It's not clear to me whether Win32::OLE is still being maintained, as the issues list at https://rt.cpan.org/Public/Bug/Display.html?id=48858 raised this exact item a number of months ago, so I'm not sure where to submit a patch.

As noted in that link there are a few ways to resolve this (such as giving preference to the win64 entry if both exist), however I've decided it would be best in our case to only query the win64 folder if win32 does not return anything useful.

To do this, in OLE.xs search for win32 and change as below.

err = RegQueryValueA(hKeyLangid, "win32", szFile, &cbFile);

// check win64 if win32 failed
if (err != ERROR_SUCCESS || cbFile <= 1)
    err = RegQueryValueA(hKeyLangid, "win64", szFile, &cbFile);
Nick P
  • 759
  • 5
  • 20