flamey has asked for the wisdom of the Perl Monks concerning the following question:
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?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A little help with Win32::API? (solution)
by ikegami (Patriarch) on Apr 25, 2010 at 02:51 UTC | |
by flamey (Scribe) on Apr 25, 2010 at 07:38 UTC | |
|
Re: A little help with Win32::API? (cleanup)
by ikegami (Patriarch) on Apr 25, 2010 at 03:05 UTC | |
by flamey (Scribe) on Apr 25, 2010 at 08:54 UTC | |
by ikegami (Patriarch) on Apr 25, 2010 at 16:11 UTC | |
by flamey (Scribe) on Apr 26, 2010 at 14:31 UTC | |
by flamey (Scribe) on Apr 25, 2010 at 09:00 UTC | |
|
Re: A little help with Win32::API? (alternative?)
by ikegami (Patriarch) on Apr 25, 2010 at 02:11 UTC |