I was hoping the following code would give me the target of an adnertised shortcut in Windows. Well, in the code below, to MS Word 2007 installed on my PC.
use 5.10.0; use strict; use warnings; use Win32::API; # UINT MsiGetShortcutTarget( # __in LPCTSTR szShortcutTarget, # __out LPTSTR szProductCode, # __out LPTSTR szFeatureId, # __out LPTSTR szComponentCode # ); my $MsiGetShortcutTarget = Win32::API->new( 'msi.dll', 'UINT MsiGetShortcutTarget(LPCTSTR targetFile, LPTSTR p +roductCode, LPTSTR featureID, LPTSTR componentCode)', ); my( $file, $product, $feature, $component ) = ( 'Microsoft Office Word 2007.lnk', "\0" x 39, "\0" x 39, "\0" x 39 ); my $retCode = $MsiGetShortcutTarget->Call( $file, $product, $feature, +$component ); say $retCode; $product =~ s/\0.*$//; $component =~ s/\0.*$//; say "$product|\n$feature|\n$component|"; # INSTALLSTATE MsiGetComponentPath( # __in LPCTSTR szProduct, # __in LPCTSTR szComponent, # __out LPTSTR lpPathBuf, # __inout DWORD *pcchBuf # ); my $MsiGetComponentPath = Win32::API->new( 'msi.dll', 'MsiGetComponentPath', 'PPPP', 'I' ); my( $path, $pathLength ) = ( "\0" x 260, "\0" x 8 ); my $installState = $MsiGetComponentPath->Call( $product, $component, $ +path, $pathLength ); say $installState; $pathLength = unpack( 'L', $pathLength ); say $pathLength; say "{$path}";
After a call to MsiGetShortcutTarget() I get return code 0 (success), and correct values for the product feature and component.
After a call to MsiGetComponentPath(), I get the correct $pathLength ( on my PC its 54 ->
C:\Program Files\Microsoft Office\Office12\WINWORD.EXE).. but the $path is unchanged - it's still 260 blank chars.
What am I doing wrong?
In reply to A little help with Win32::API? by flamey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |