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

Hello guru's, I have just started working win32::API module. On executing below code.. use strict; use warnings; use Win32::API; my $iAddNum = Win32::API->new('Arithmetic','addNumbers','NN','N'); my $return = $iAddNum->Call(10,15); print "Sum: ",$return; I get an error "Cant call method "Call" on undefined value at add.pl line 6. can you please help me in understanding, why this error pop's up and also give solution to it? thanks in advance

Replies are listed 'Best First'.
Re: Cant call method : win32::API
by ikegami (Patriarch) on Sep 15, 2009 at 06:12 UTC
    Start by changing
    my $iAddNum = Win32::API->new('Arithmetic','addNumbers','NN','N');
    to
    my $iAddNum = Win32::API->new('Arithmetic','addNumbers','NN','N') or die("dll import: $^E\n");
      I made the changes you suggested, now I getting error "the specfied procedure could not be found"...Please help
        "the specfied procedure could not be found"

        The dll is being found ok, but the function you're calling could not be found. I'm guessing that's either because the function is not exported by the dll, or it doesn't use the stdcall convention.

        Update: Can you tell us how the dll was built ? (That might help.)

        Cheers,
        Rob
Re: Cant call method : win32::API
by syphilis (Archbishop) on Sep 15, 2009 at 06:08 UTC
    Is Arithmetic.dll in a location where it will get found ?
    Were the functions declared with the stdcall calling convention ? (Not sure if this is still a requirement for dll's being accessed by Win32::API.)
    Does Arithmetic.dll export the 'addNumbers' function ? (Running dumpbin /EXPORTS Arithmetic.dll will tell you.)
    Is the dll functional when used from C programs ?

    Another way to access the Arithmetic.dll functions is to use Inline::C (or XS) - though you'll need to have an import lib (Arithmetic.lib) for that to work, unless you're using the MinGW compiler. Trying to access the Arithmetic.dll functions using Inline::C might provide better agnostics if there's a problem with the dll itself.

    Cheers,
    Rob