in reply to Re: Win32::API giving a program error
in thread Win32::API giving a program error

Hi there,
Thanks to you both for the quick response. yes, the $output variable was a typo. As for the naming convention, I got that from an exceprt in "Win32 Perl Programming", here's the code again:
#!usr/bin/perl use Win32::API; my $filename="C:/Program Files/America Online 9.0g/aol.exe"; my $apiobject = new Win32::API("C:/Documents and Settings/Mdaviesie/De +sktop/dver_1.3/fileversion.dll", "GetFileVersionTxt", 'PP','I') or di +e "Failed to acquire API: $^E"; #Set some memory aside for the returned value my $string="\x00" x 1024; #Call the function in the dll $apiobject->Call($filename,$string); #Remove the unused padding in the string my $final = ($string =~/(.*?)\x00/); print "\$final - $final";
A bit of background, all the dll is supposed to return is the version number of the named file. The function I want to call looks like this:
INT GetFileVersionTxt(STRING sFile, out STRING sVersion)
The dll returns a version number (I was using the fileversion modules before, but their output is slightly different to what this dll returns - which is why I have to try to work with it). If anybody could provide me with a pointer as to why this is returning the error message,
Thanks again,
Jonathan

Replies are listed 'Best First'.
Re^3: Win32::API giving a program error
by Anonymous Monk on Jun 03, 2004 at 14:35 UTC
    Hi,

    A couple of notes. First, the line:

    my $final = ($string =~/(.*?)\x00/);

    probably should be:

    my ($final) = $string =~/(.*?)\x00/;

    otherwise $final would be a the success of the match, not the first capture block.


    Second, you may want to check the file path you are using. Many MS libraries need Windows file paths, not Perl-esque (or Unix like) ones. I have had this problem with Win32::COM a lot. I would want to give it a Perl-esque and I would get odd COM errors.

    So, instead of:

    my $filename="C:/Program Files/America Online 9.0g/aol.exe";

    try:

    my $filename="C:\\Program Files\\America Online 9.0g\\aol.exe";

    I can't explain why it would give you the error you are getting (and it may have nothing to do with it), but it is something you might want to check on.

    Ted