Hi all,

Trying to use Win32::GUI  Perl module to programmatically control a window in 
Windows from Perl. The window is a program called WinLirc which is used to 
control and iR Blaster for controlling equipment.

There’s already a command line program that interfaces with this window called 
transmit.exe, but I am trying to write a Perl version to make a web based 
interface.  So far, I can get the handle on the window and even issue a 
CloseWindow, so I know I’m hooked into it, but I am having trouble with sending 
the commands over WM_COPYDATA. Not sure if I’m building and packing my command 
line the same way transmitdoes it. Can anyone understand what they are doing by 
looking at the VC++ transmit.cpp code below?

Basically, you invoke transmit to send commands to the WINLirc window like this:

C:/transmit.exe Cable CHNUP 1

So, I assume in transmit.cpp, the lpCmdLine value receives the value “Cable 
CHNUP 1” which is what I hardcoded into my corresponding $command variable in 
Perl, for testing purposes.

Here’s the VC++ code from the transmit.cpp:

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
                LRESULT copyDataResult;
                HWND pOtherWnd = FindWindow(NULL, "WinLirc");
                if (pOtherWnd)
                {
                                COPYDATASTRUCT cpd;
                                cpd.dwData = 0;
                                cpd.cbData = strlen(lpCmdLine);
                                cpd.lpData = (void*)lpCmdLine;
                                copyDataResult = 
SendMessage(pOtherWnd,WM_COPYDATA,(WPARAM)hInstance,(LPARAM)&cpd);
        // copyDataResult has value returned by other app
                }
                else
                {
                                return 1;
                }
                return 0;
}


Anyhow here’s my best attempt at translation into Perl:

#!/usr/bin/perl
# WinLiRC Perl interface

chdir ("cgi-bin");

use Win32::GUI;

$windowtitle='WinLIRC';
$command='Cable CHNUP 1';

$handle=Win32::GUI::FindWindow('', $windowtitle);

if ($handle eq "") {print "WinLIRC window not open."; exit(0);}

$copy_data_struct=pack('L2P',0,length($command),$command);

$result=Win32::GUI::SendMessage($handle,WM_COPYDATA,0,$copy_data_struct);

print "$result"

I keep getting a result code of "0" which tells me the command is failing. More 
than likely it's encoded wrong...

Any help would be greatly appreciated!

Thanks,

Mike




      

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to