Re: Win32::API Module

2001-05-23 Thread Joe Yates

At 05:04 AM 21-05-01 -0700, Helio S. Junior wrote:
>I would like to know how to use win32 functions which take structures as 
>their parameter.
>For example, the API 'SHBrowseForFolder' take the following structure:
>
>typedef struct _browseinfo {
> HWND hwndOwner;
> LPCITEMIDLIST pidlRoot;
> LPTSTR pszDisplayName;
> LPCTSTR lpszTitle;
> UINT ulFlags;
> BFFCALLBACK lpfn;
> LPARAM lParam;
> int iImage;
>};
>
>How do i 'translate' this structure and use this function with Win32::API 
>module?

First thing, I'm glad there's someone else out there using Win32::API.

1. decide what type of items you are dealing with and pack() them:

>typedef struct _browseinfo {
> HWND hwndOwner;
> LPCITEMIDLIST pidlRoot;
> LPTSTR pszDisplayName;
> LPCTSTR lpszTitle;
> UINT ulFlags;
> BFFCALLBACK lpfn;
> LPARAM lParam;
> int iImage;
>};

You've got the following (L = 32-bit integer (long or int), P = char pointer):
 LLPP

2. Get function pointers using WIN32::API->new
 my $SHBrowseForFolder = new Win32::API("shell32", 
"SHBrowseForFolder", ["P"], "L");
 etc

3. Call the functions.

Code is attached

Joe Yates


#!perl

use strict;
use WIN32::API;

my $SHBrowseForFolder = new Win32::API("shell32", "SHBrowseForFolder", ["P"], "L");
my $SHGetPathFromIDList = new Win32::API("shell32", "SHGetPathFromIDList", ["LP"], 
"L");
if($SHBrowseForFolder == 0)
  {
  print "Failed to initialise function SHBrowseForFolder().\r\n";
  }
if($SHGetPathFromIDList == 0)
  {
  print "Failed to initialise function SHGetPathFromIDList().\r\n";
  }
my $sFolder = ChooseFolder();
print "Folder: $sFolder\r\n";
exit 1;

=pod
typedef struct _browseinfo
  { 
  HWND hwndOwner; 
  LPCITEMIDLIST pidlRoot; 
  LPTSTR pszDisplayName; 
  LPCTSTR lpszTitle; 
  UINT ulFlags; 
  BFFCALLBACK lpfn; 
  LPARAM lParam; 
  int iImage; 
  } BROWSEINFO;
=cut

my $BIF_RETURNONLYFSDIRS = 1;
my $BIF_DONTGOBELOWDOMAIN = 2;

sub ChooseFolder()
  {
  my $pszDisplayName = "\0" x 0x200;
  my $lpszTitle = "Choose the folder\0";
  my $ulFlags = $BIF_RETURNONLYFSDIRS | $BIF_DONTGOBELOWDOMAIN;
  #  hw pi DisplayName  Title   Flags cb lp Im
  my $pbi = pack("LLPP", 0, 0, $pszDisplayName, $lpszTitle, $ulFlags, 0, 0, 0);
  my $lIDList = $SHBrowseForFolder->Call($pbi);
  if($lIDList == 0)
{
return "";
}
  my $sBuffer = "\0" x 0x200;
  $SHGetPathFromIDList->Call($lIDList, $sBuffer);
  $sBuffer =~ /\0/o;
  my $sPath = $`;
  return "$sPath";
  }



Re: Traversing a directory tree

2001-05-10 Thread Joe Yates

At 04:38 PM 10-05-01 +0530, Amarnath Honnavalli Anantharamaiah wrote:
>Ho do I traverse the directory tree and find the file present in it.
>I mean I should have an output similar to find command in shell.
>
>e.g find . -name lock -print

Find("/etc", "abcd");

sub Find($$)
   {
   my ($sPath, $sMatch) = shift(@_);
   opendir(DIR, $sPath);
   # Get all files in folder
   my @asFiles = grep { -f "$sPath$_" && /$sMatch/ } readdir(DIR);
   my @asFolders = grep { -d "$sPath$_" && $_ !~ /^\.{1,2}$/ } readdir(DIR);
   closedir DIR;
   foreach my $sFolder (@asFolders)
 {
 Find($sFolder);
 }
   foreach my $sFileName (@asFiles)
 {
 my $sPathFileName = "$sPath/$sFileName";
 print "$sPathFileName\n";
 }
   }




Re: IDE for perl?

2001-05-09 Thread Joe Yates

At 10:19 AM 09-05-01 -0400, Rod Suter wrote:
>I'm using perl through emacs, but I want to bring along some people on 
>NT4.0.  They're accustomed to Visual Studio, and want IDE features, such 
>as project directories, global search and replace, debugger linking, 
>source code error hilighting, etc. Can anyone suggest a good group 
>environment for developing perl? My first urge is to set up Ultra-Edit 
>with some appropriate customization.

EditPlus is very good.

Joe Yates




Re: Perl and WindowsNT

2001-05-09 Thread Joe Yates

At 12:42 PM 08-05-01 -0400, Carl Rogers wrote:
>Sorry if this is a dumb question.. (I know, there is no such thing as a 
>dumb question- only questions asked by dumb people:)
>
>I used the opendir() function in my Perl script to point to a folder with 
>200+ text files for the purpose of extracting data from each file.
>
>If I run the script with opendir/readdir pointing to a directory on a 
>shared drive, I'll get to a point where Perl tells me "Can't open file- no 
>such file or directory"

This may be a dumb answer, but, here goes:

Are you adding the path to the file name?
opendir() gives you plain file names, you have to add the path to them to 
open them.

   my $sPath = ...any path
   opendir(DIR, $sPath);
   # Get all files in folder
   my @asFiles = grep { -f "$sPath$_" } readdir(DIR);
   closedir DIR;
   foreach my $sFile (@asFiles)
 {
 my $sPathFileName = "$sPath\\$sFile";
 open INFILE, "<$sPathFileName";
 ...
 close(INFILE);
 }

Hope that helps.

Joe




Re: microsoft sql2000

2001-05-09 Thread Joe Yates

At 04:46 PM 08-05-01 -0700, you wrote:
>Hello perl friends. I need to know if perl works with microsoft sql2000. if
>it does, which module do i need to get? thanks

I use DBI.

1. Set up the database you want to use as a 'Data Source' (Administrative 
Tools| Data Sources (ODBC)),
2. Then...
 use DBI;
 my $dbh = DBI->connect('dbi:ODBC:DATA_SOURCE_NAME', 'USER_NAME', 
'PASSWORD');
     ...do your stuff
 $dbh->disconnect;

Joe Yates