Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

win32::sendmessage and pack help.

by Fuas (Initiate)
on Feb 19, 2008 at 09:35 UTC ( #668761=perlquestion: print w/ replies, xml ) Need Help??
Fuas has asked for the wisdom of the Perl Monks concerning the following question:

hi there. I've been trying to work this out for a few days now. Im trying to script an ftp client to backup files from a server. using a program called ftprush. this allows the user to script commands via the windows api sendmessage. I want to be able to call this via perl and send some files as a backup server. the website provides a dll and a .exe file for doing this. but reading though the file I'm sure it can be intergrated. here is the code I've attempted.
use Win32::GUI; use Win32::API; my $rushhandle = Win32::GUI::FindWindow("tfmrush", ""); $command="RushApp.Util.Standalone.Login('backup','','')"; my $copy_data_struct = pack( 'L2P', 2, length( $command ), $command ); #Win32::GUI::PostMessage($rushhandle,WM_COPYDATA,$wparm,$lpCopydatastr +uct); #my $SendMessage=new Win32::API("User32","SendMessage",[qw(N N N N)],' +N'); #my $lresult=$SendMessage->Call($rushhandle,WM_COPYDATA,$wparm,$lpCopy +datastruct); Win32::GUI::SendMessage($rushhandle, WM_COPYDATA, 0, $copy_data_struct +);
here is the C code from the dll.
TargetWindow := FindWindow('TfmRush', nil); CopyDataStruct.dwData := 1000; CopyDataStruct.cbData := strlen(Data) + 1; CopyDataStruct.lpData := Data; wCallbackWindow.fIrcHandle := mWnd; SendMessage(TargetWindow, WM_COPYDATA, 0, LParam(@CopyDataStruct));
I've left the # from my code so you can see what I've tried. I've got a feeling the error is in the pack command. but reading thou the perldoc to be honest it all goes over my head. thanks for takeing the time to read and for any help offered. Ken. **UPDATE** Thank you igelkott for all the help. I got it working :) thanks for a friend on mirc for helping too :) ykwya.
use Win32::GUI; use Win32::API; use constant WM_COPYDATA => 74; my $rushhandle = Win32::GUI::FindWindow("tfmrush", ""); my $command = "RushApp.FTP.Login('backup','',0);"; my $copy_data_struct = pack('L2P', 1000, length( $command ), $command) +; print Win32::GUI::SendMessage($rushhandle, WM_COPYDATA, 0, $copy_data_ +struct);

Comment on win32::sendmessage and pack help.
Select or Download Code
Re: win32::sendmessage and pack help.
by igelkott (Curate) on Feb 19, 2008 at 09:47 UTC
    Unless there's some special reason to use ftprush specifically, it might be easier to switch to a perl module like Net::FTP.
      I wanted to use rush because of 2 things. 1 the ease of use for ssl encrypted sockets. and the way it can handle multi sites very easy. I know Net::FTP can do this too. and can get ssleay wrappers to make it work via ssl too. but I do like rush and know its possible.
        Are sure that RushApp.Util.Standalone.Login shouldn't really be RushApp.Util.Standalone.Connect? I can't claim to be an expert on the windows GUI modules but everything else looks reasonable.

        General advice: Check your return values, eg, do you really have a valid "rushhandle", etc?

Re: win32::sendmessage and pack help.
by cdarke (Prior) on Feb 19, 2008 at 11:23 UTC
    here is the C code from the dll

    Not C, possibly Delphi?

    My mate Google found this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://668761]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-12-28 06:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (179 votes), past polls