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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.