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

Hi, I am trying to use a procedure exported by a .dll. I am using Win32::API. $function = new Win32::API('dllfile.dll', 'functionname', 'P','I') || die $!; This returns "The specified procedure could not be found." I tried using dumpbin /exports dllfile.dll I got the same function name but with a suffix _ and prefix @4 _functionname@4 Looking forward for a help in this.

Replies are listed 'Best First'.
Re: Win32::API accessing DLL
by philiprbrenan (Monk) on Sep 07, 2012 at 13:19 UTC

    Windows has multiple calling conventions for functions. I believe the DLL is exposing different entry points to support these conventions. Please see: http://unixwiz.net/techtips/win32-callconv.html#conv

Re: Win32::API accessing DLL
by Corion (Patriarch) on Sep 07, 2012 at 12:15 UTC
    So, have you tried to import that function using its mangled name? What happened?
Re: Win32::API accessing DLL
by bulk88 (Priest) on Sep 08, 2012 at 00:24 UTC
    Use the decorated name. MS DLLs are special since they were all made with DEF files where the names are plain and undecorated. @4 means your function takes one 32 bit parameter and is stdcall. cdecls dont have a @12345.
Re: Win32::API accessing DLL
by nikosv (Deacon) on Sep 08, 2012 at 13:12 UTC
    use dependency walker to load your dll and examine it. Also check "How do I view the parameter and return types of a function?" in the faq
Re: Win32::API accessing DLL
by Anonymous Monk on Sep 07, 2012 at 21:02 UTC
    Be very careful that upper/lower case matches exactly...