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

G'day.
I've just stepped into the, erm, wonderful world of Win32 programming. I have a dll which is needed to translate a password in an application we use. I've been given the specs of the dll as follows:

Function: bgfnTextDecrypt Description: Export Ordinal: 0 Returns Boolean: BOOL Parameters String: LPSTR Receive String: LPSTR
I'm trying to translate this into either a Win32::API or Win32::API::Prototype programme.
I have tried the following pieces of code:
#!perl use strict; use Win32::API; my $bgfnTextDecrypt = new Win32::API('eq_handy', 'bgfnTextDecrypt','PP +','P'); if(not defined $bgfnTextDecrypt) { die "Can't import API bgfnTextDecrypt: $!\n"; } print "Eerk\n"; my $lpBuffer = " " x 80; print "Eerk2\n"; my $return = $bgfnTextDecrypt->Call('password-crypt', $lpBuffer); print "Eerk3\n"; my $decrypt = substr($lpBuffer, 0, $return); print "$decrypt\n";
and
#!perl use strict; use Win32::API::Prototype; ApiLink( 'eq_handy.dll', 'BOOL bgfnTextDecrypt( LPSTRING lpString, LP +STRING, lpBuffer )' ) || die; my $lpString="password-crypt"; my $lpBuffer = pack( "L*", $lpString); bgfnTextDecrypt($lpString); my $pass = unpack( "L*", $lpBuffer ); print( "The pass is: $pass\n";
As I have never coded in Win32 before, I'm a little lost.
Is there anyone who can point me in the right direction? Even a similar MS dll as an example would be wonderful.

Thanks.
Neil

EDIT: Changed the dll name in the second example.

Replies are listed 'Best First'.
Re: Win32::API and ::Prototype assistance
by neilh (Pilgrim) on Jul 29, 2005 at 12:20 UTC
    Some potentially working code :

    #!perl #use strict; use Win32::API::Prototype; ApiLink( 'eq_handy.dll', 'BOOL bgfnTextDecrypt( LPSTR lpString, LPSTR +, lpBuffer )' ) || die ($!); my $passphrase="encrypt-phrase"; my $lpString = pack( "L2", $passphrase,0); print "Hi there\n"; $nBufferLength = 256; $lpBuffer = NewString( $nBufferLength ); if (bgfnTextDecrypt($lpString,$lpBuffer, $nBufferLength)) { print "It worked!\n"; } my $pass = unpack( "L*", $lpBuffer ); print "The pass is:",$pass,"\n";
    Output is:
    Hi there It worked! The pass is:189
    The actual pass is bluemean.
    I think my unpack is wrong.. any suggestions?
    Neil
      Well I got it to work. It turned out that my pack and unpack were wrong.
      Thanks to the Pack/Unpack Tutorial (aka How the System Stores Data) for the ideas.

      #!perl use strict; use Win32::API::Prototype; ApiLink( 'eq_handy.dll', 'BOOL bgfnTextDecrypt( LPTSTR lpString, LPTS +TR, lpBuffer )' ) || die ($!); my $passphrase="encrypt-pass"; my $lpString = pack( "A*", $passphrase,0); print "Hi there\n"; my $nBufferLength = 256; my $lpBuffer = NewString( $nBufferLength ); if (bgfnTextDecrypt($lpString,$lpBuffer, $nBufferLength)) { print "It worked!\n"; } my $pass = unpack( "A*", $lpBuffer ); print "The pass is:",$pass,"\n";
      Back to my box.

      Neil