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

I am trying to determine the binary type of various files using the Win32 API GetBinaryType. For some reason the code below does not quite work. It doesn't return any value. Any suggestions why?
#!perl use strict; use Win32::API; my $filename="C:\\WINDOWS\\system32\\notepad.exe"; my $GetBinaryType ||= new Win32::API("kernel32", "GetBinaryTypeA", ['P +','P'],'N') || die $^E; my $type = ' 'x5; my $Bool = $GetBinaryType->Call($filename, $type); print " $Bool, ($filename, $type)\n"; #$type should return one of the following values, but it returns nothi +ng. :( # 0 A Win32 based application # 1 An MS-DOS based application # 2 A 16-bit Windows based application # 3 A PIF file that executes an MS-DOS based application # 4 A POSIX based application # 5 A 16-bit OS/2 based application

Replies are listed 'Best First'.
Re: GetBinaryType API
by ikegami (Patriarch) on Sep 22, 2004 at 04:18 UTC

    One minor change:
    print " $Bool, ($filename, ", unpack("L", $type), ")\n";

    And for better test results, I tried:
    my $filename="C:\\WINDOWS\\system32\\command.com";.
    It gave:
    1, (C:\WINDOWS\system32\command.com, 1)

      Thanks. Works like a charm now..