Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Perl program calling external .dll functions

by manojghosh (Novice)
on Mar 17, 2011 at 11:41 UTC ( #893734=perlquestion: print w/replies, xml ) Need Help??
manojghosh has asked for the wisdom of the Perl Monks concerning the following question:

Please suggest diffrent methods or ideas in implementing the .dll function call from a perl program in windows. i have tried Win32::API but failed to do so. If perlXS package can help me out? or there is any other method? like i am calling
use Win32::API; my $temp='123456789'; $sp=' '; my $fun=new Win32::API('DataGenerate.dll','GetACC','LL','L' ) or die $ +^E; my $y = $fun->Call($temp,$sp); print($y);
whereas our GetACC() is defined like this: Long GetACC(String,String); The interpreter crashes as i am running this ...!

Replies are listed 'Best First'.
Re: Perl program calling external .dll functions
by marto (Archbishop) on Mar 17, 2011 at 11:46 UTC
Re: Perl program calling external .dll functions
by Jenda (Abbot) on Mar 17, 2011 at 15:09 UTC

    Waitasecond ... what language is the DLL implemented in? C#? If it's a .Net DLL you can't call it using Win32::API. ActiveState's PerlNET would work, not sure what other options you have.

    Enoch was right!
    Enjoy the last years of Rome.

Re: Perl program calling external .dll functions
by ikegami (Pope) on Mar 17, 2011 at 17:35 UTC

    I don't know what «String» is — it's not a standard C type or a WinAPI type — but it's definitely not the same as «uint32_t» ("L").

    I don't know what «Long» is — it's not a standard C type or a WinAPI type either — but it's not necessarily the same as «uint32_t» ("L").

    Could you provide more information about those types? Also, could you find out what calling convention is used? Win32::API assumes __stdcall unless you tell it it's __cdecl.

      simply the the .dll function is written in C++ and 2 string type arguments are passed through it. and it has a long return type. actually this .dll behaves fine with calling from VB6.0 but trying with perl, interpreter crashes in its call or return 0 on passing argument type mentioned as 'P'(Pointer to string).

        Assuming the STL even defines the internal storage format of a String, I don't know what it is. Whatever it is, it's definitely not a uint32_t as you're telling Win32::API it is.

        "P" passes a pointer to the a copy of the scalar's string buffer. Don't know if your String is compatible with what you are passing were you to use "P". But you're not using "P". You're using "L".

        You've provided no useful data about the type. You didn't provide the calling convention used.

        I think you'd be much better off using Inline::CPP.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://893734]
Approved by marto
and a soft breeze sighs...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2018-05-23 23:12 GMT
Find Nodes?
    Voting Booth?