in reply to Re: Win32 CSIDL_LOCAL_APPDATA
in thread Win32 CSIDL_LOCAL_APPDATA

xdg wrote:

CSIDL_LOCAL_APPDATA is a subroutine. So you've got to call it to return the right numeric flag for GetFolderPath.

$realhome = Win32::GetFolderPath( CSIDL_LOCAL_APPDATA() );

Revising the relevant code per your suggestion ...

if ($^O eq 'MSWin32') { require Win32; import qw(CSIDL_LOCAL_APPDATA); $realhome = Win32::GetFolderPath( CSIDL_LOCAL_APPDATA() ); }

... I now get this error:

Undefined subroutine &main::CSIDL_LOCAL_APPDATA called at import.pl li +ne 11.

jimk

Update:Or, from the command-prompt:

F:\AAAother\data>perl -MExporter -e "require Win32; Exporter::import ' +CSIDL_LOCAL_APPDATA'; print Win32::GetFolderPath( CSIDL_LOCAL_APPDATA +() );" Undefined subroutine &main::CSIDL_LOCAL_APPDATA called at -e line 1.

Further update:I just consulted the MS documentation, which provides 0x001c as the hex numerical value for CSIDL_LOCAL_APPDATA (). Substituting that into the previous code (and simplifying a bit), I get:

if ($^O eq 'MSWin32') { require Win32; print Win32::GetFolderPath( 0x001c ), "\n"; }

... which DWIMs on my system as:

C:\Documents and Settings\kbuser\Local Settings\Application Data

(Big sigh of relief!) Now, let's see if it works in the application from which all of the foregoing is excerpted. Thanks for your help.

jimk

Yet another update:Although the path listed immediately above is the return value generated by GetFolderPath (both in my implementation and in that suggested later by xdg), no such path could be found on my system, at least not through Windows Explorer/My Computer. That's because the directory level 'Local Settings' is absent. In order to get my application to work, I had to do the following (done from memory, so I don't guarantee it):

$realhome = Win32::GetFolderPath( CSIDL_LOCAL_APPDATA() ); $realhome =~ s|(.*?)\\Local Settings(.*)|$1$2|;

Replies are listed 'Best First'.
Re^3: Win32 CSIDL_LOCAL_APPDATA
by xdg (Monsignor) on Aug 23, 2005 at 16:51 UTC

    I suspect you've been through too many iterations trying to get it to work to see the code clearly. Stepping back, you need to specify the package to import (ah, the irony of import):

    if ($^O eq 'MSWin32') { require Win32; Win32->import( qw(CSIDL_LOCAL_APPDATA) ); $realhome = Win32::GetFolderPath( CSIDL_LOCAL_APPDATA() ); }

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re^3: Win32 CSIDL_LOCAL_APPDATA
by holli (Abbot) on Aug 23, 2005 at 17:59 UTC
    what happens when you put a
    print CSIDL_LOCAL_APPDATA . "\n";
    into your both versions? Does that show the same value? Also, are you sure the perl in your path is the same perl that is associated with the .pl extension?
    That may sound dumb but i encountered that once. A guy in the office called me to assist in a perl error message.
    Can't locate Something.pm in @INC ...
    Me: Easy. You don't have Something.pm installed.
    He: (sighs) I know but I have written Something.pm It is there. Look. (and showed me the file c:\perl\site\lib\Something.pm
    Me: Mmh.

    I spend 2 hours searching for the reason. It turned out that this colleague had installed a "raw" perl (without installer or other such luxury). And because c:\perl was already used by AS Perl, he, in his wisdom, decided to install the second perl in c:\per1 and altered the path accordingly. So, when you typed
    perl somescript.pl
    the second perl executed the script. And when you typed
    somescript.pl
    or doubleclicked the script cia Explorer the AS Perl was in charge.


    holli, /regexed monk/