Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,
I think Win32::API could be the answer to my problem anyway. I've been asked to change a perlscript to interface with a dll (something I've never done before). The function I want to call in the dll looks like this
INT GetFileVersionTxt(STRING sFile, out STRING sVersion)
as you guessed it simply outputs a version number for a particular file. Here's as far as I got (badly):
#!usr/bin/perl use Win32::API; my $filename="C:/WINNT/ieuninst.exe"; $Api = new Win32::API(fileversion.dll, GetFileVersionTxt, [P,$filename +], [P,$output]); print "\output - $output";
I used the Filversion module before, didn't have any problems, this dll gives slightly different results, which my managers would prefer to get, otherwise I wouldn't have to call it.Any pointers as to how I can get this working would be greatly appreciated.
Jonathan

Replies are listed 'Best First'.
Re: Win32::API question
by Ninthwave (Chaplain) on Jun 02, 2004 at 18:04 UTC

    You create dthe API object but you need to return a result from a call to that object. Note I do not have the dll in question so I can not test but I would think your code should look like this:

    use Win32::API; my $filename="C:/Windows/ieuninst.exe"; my $Api = new Win32::API("fileversion.dll", "GetFileVersionTxt", P, P) +; # Set some memory aside for the returned value my $output = "\x00" x 1024; # Call the function in the dll $Api->Call($filename,$output); # Remove the unused padding in the string my $final = ($output =~ /(.*?)\x00/); print "\output - $final";

    This is from an example in Chapter 9 of Win32 API from Win32 Perl Programming by David Roth modified to match your criteria. I would like to play with dll to test this as I think it would need some tweaking to run. I also suggest reading the pod for Win32::API as they have some excellent examples of getting data in and out of the functions loaded.

    "No matter where you go, there you are." BB
      my $Api = new Win32::API("fileversion.dll", "GetFileVersionTxt", P, P) +;
      should be changed to
      my $Api = new Win32::API("fileversion.dll", "GetFileVersionTxt", ['P', + 'P'], 'I');
      or
      my $Api = new Win32::API("fileversion.dll", "GetFileVersionTxt", 'PP', + 'I');
      The third parameter is suposed to be a string or array ref of the input parameters, and the forth is a string for the return value.

        Cheers I alway forget the single quotes.

        I usually catch errors like that if I test code. But I was running from work without a dll to use. Oh well, maybe next time my first reply will be better ;)
        But than Win32::API for me is always sitting with a sample and changing it to meet my needs based on the functions called. Funny enough to see what got added to the meditations How to make Win32::API easy to use

        "No matter where you go, there you are." BB