http://www.perlmonks.org?node_id=551569

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

Hi Monks!!

I am using the Win32::API module to call a Dynamic Link Library(DLL)
named "chkValues.dll"). My DLL has a function in it called
adnValues: extern "C" __declspec(dllexport) double adnValues(double x, double y) { double z; z = x + y; cout << x << " " << y << " " << z << endl; return(z); }
My perl script to call this looks like:
use Win32::API; $fld1 = $ARGV[0]; $fld2 = $ARGV[1]; $myFunc = Win32::API->new('adnValues', 'double adnValues(double x, double y)'); $outval = $myFunc->Call($fld1, $fld2); print "$outval";
When i am executing this, perl script exits at the Call line, giving me the "Perl
Command Line Interpreter has encountered a problem and needs to close.
We are sorry for the inconvenience" message.
I Noticed that if I change my dll function to take no arguments (hard coding
x and y within the function) and return a double, I have no issues,
e.g. $myFunc = Win32::API->new('adnValues', 'double adnValues()'); $outval = $myFunc->Call();
I also tried the alternative syntax:
$myFunc = Win32::API->new('adnalues', 'adnValues', 'DD', 'D')
with no success. I'm strucking here pls help me monks ...

2006-10-07 Unapproved by planetscape once evidence of habitual plagiarism uncovered.

Replies are listed 'Best First'.
Re: why Crashing windows API using perl??
by cdarke (Prior) on May 25, 2006 at 11:58 UTC
    It's probably the calling convention. Change your C to:
    double __stdcall adnValues(double x, double y)
    You can use WINAPI instead of __stdcall (that's 2 underscores) if you #include <windows.h>.
      I also meet this problem days ago, and I solve my problem as same as cdarke said. I agree cdarke's suggestion. WINAPI is better.
Re: why Crashing windows API using perl??
by gellyfish (Monsignor) on May 25, 2006 at 11:11 UTC

    Have you tried using the DLL from some other language to see if the problem exists there?

    /J\

Re: why Crashing windows API using perl??
by liverpole (Monsignor) on Oct 06, 2006 at 19:47 UTC
    Hey madtoperl,

    Are you by any chance also using the username "jesuashok"?

    The reason I ask is that [id://jesuashok|he] also has trouble with crediting his sources, even to the point of asking questions which are taken from other sources, after removing the authors' names first.

    On March 8, 2006, the following was posted at this site:

    + I'm trying to use the Win32::API module to call a simple test case DLL (call it "addValues.dll"). My DLL has a function in it called addValue +s: + extern "C" __declspec(dllexport) double addValues(double a, double b) { double c; c = a + b; cout << a << " " << b << " " << c << endl; return(c); } + My perl script to call this looks like: + use Win32::API; + $num1 = $ARGV[0]; $num2 = $ARGV[1]; + $myFunc = Win32::API->new('addValues', 'double addValues(double a, double b)'); $out = $myFunc->Call($num1, $num2); print "$out"; + When executing this, perl bombs at the Call line, giving me the "Perl Command Line Interpreter has encountered a problem and needs to close. We are sorry for the inconvenience" message. + Note that if I change my dll function to take no arguments (hard codin +g a and b within the function) and return a double, I have no problems, e.g. + $myFunc = Win32::API->new('addValues', 'double addValues()'); $out = $myFunc->Call(); + I have also tried the alternative calling syntax: + $myFunc = Win32::API->new('addValues', 'addValues', 'DD', 'D') + with no success.
    Now, apart from changing a few variable names (eg. "z = x + y;" instead "c = a + b;"), your post is identical to the one from 2 1/2 months earlier!  I notice you event have a typo where you changed "addValues" to "adnValues", but misspelled the function name:
    $myFunc = Win32::API->new('adnalues', 'adnValues', 'DD', 'D')

    Furthermore, like some of jesuashok's examples of plagiarism, you seem very interested in Perl poetry.  Unfortunately, in a number of cases, you have stolen that poetry from other people, and tried to pass it off as your own.  marto posted this node showing 5 examples where you took someone else's work without giving credit!

    So, why are you ripping off other people's work?!


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: why Crashing windows API using perl??
by Anonymous Monk on May 25, 2006 at 11:57 UTC