Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Call a function from DLL

by Discipulus (Canon)
on Jul 15, 2019 at 06:51 UTC ( [id://11102849]=note: print w/replies, xml ) Need Help??


in reply to Call a function from DLL

Hello Cleware and welcome to the monstery and to the wonderful world of perl!

I suspect nothing is wrong with your import: the error Undefined subroutine &main::Print refers to your statement Print($return); infact in perl you have print not Print and no parens are needed (or you'll get another error like print interpreted as function at.. ).

Also do not never forget to use strict; use warnings; at the top of your perl programs.

As per the Win32::API docs is good to check if the import was done (the two die in the below code):

use Win32::API; $function = Win32::API::More->new( 'mydll', 'int sum_integers(int a, int b)' ); #### $^E is non-Cygwin only die "Error: $^E" if ! $function; #### or on Cygwin and non-Cygwin die "Error: ".(Win32::FormatMessage(Win32::GetLastError())) if ! $func +tion;

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: Call a function from DLL
by Cleware (Novice) on Jul 15, 2019 at 07:49 UTC

    Dear Discipulus,

    Thank you very much for offering to help,

    Actually the I have another question:

    the idea is , I want to call the function FCWIntiObject() and the return value must be as object.

    then I want to call the second function int FCWOpenCleware(object*) which it takes the return value from the previous function as an argument.

    could you help me?

    thanks in advance.

      Dealing with C++ (as opposed to C) function calls is something of a problem because the C++ compiler mangles function names to allow for function overloading and such C++ magic. Name mangling tends to be rather specific to individual C++ compilers as are calling conventions. You need some very specific information about the compiler you are using to even call the functions. Passing objects back and forth may either be easy (if you treat them as completely opaque objects) or potentially very complicated if you need to get involved in memory management and accessing parts of the object.

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

        I would thank you for your reply, but acutely I have no idea to do that in Perl

        Do you have any suggestion?

        thanks in advance

      Your best bet is probably to nest calls, as in
      $FCWOpenCleware->Call( $FCWIntiObject->Call() )


      holli

      You can lead your users to water, but alas, you cannot drown them.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11102849]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-26 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found