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);
I'll provide a fix in case anyone wants to use it. It's not clear to me whether
Win32::OLEis 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
win64entry if both exist), however I've decided it would be best in our case to only query thewin64folder ifwin32does not return anything useful.To do this, in
OLE.xssearch forwin32and change as below.