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

Hi monks! i'm trying to communicate with a DLL I have and pass two string variables to it, and get back a double. It isn't returning anything. There are no errors during debugging, but $prwin gets calle. I used the example from cpan. Any help would be greatly appreciated. Here part of my pl file:
use Win32::API; sub pl_prwin { my $prwin; my $hands; my $board; my $GetPrwin; my $lpBuffer; my $return; $hands = "AhKh|Td9s|QQ+,AQs+,AQo+|JJ-88|XxXx|XxXx|XxXx"; $board = "Ks7d4d"; $GetPrwin = new Win32::API( "OH-DLL.dll", "prwin1($hands, $board)", 'PP', 'N'); $lpBuffer = " " x 80; $return = $GetPrwin->Call(80, $lpBuffer); $lpBuffer =~ s/\0.*$//; $prwin = $lpBuffer; return $prwin; }

Replies are listed 'Best First'.
Re: Win32::API question
by ikegami (Patriarch) on Apr 25, 2009 at 03:13 UTC
    You mixed and matched the 2- and 4-arg version, and you don't actually pass your arguments?!
    use Win32::API; my $prwin1 = Win32::API->new('OH-DLL.dll', 'prwin1', 'PP', 'D') or die("Error linking to prwin1: $^E\n"); sub pl_prwin { my $hands = "AhKh|Td9s|QQ+,AQs+,AQo+|JJ-88|XxXx|XxXx|XxXx"; my $board = "Ks7d4d"; return $prwin1->Call($hands, $board); }

    Update: Fixed return type, as per tye's reply. Forgot to check that. Also added error message.

      Thank you, unfortunately that didn't work. Is there any thing I need to check on the DLL side?

        According to the docs, Win32::API, 'N' is long. For double, you want 'D'.

        Anybody ever tell you that "didn't work" is a pretty useless error report? :)

        - tye