I'm trying to take a segment of C++ code and port it to perl to work
into an existing script.  The C code does nothing more than sends a
message to a running program(Streets on a Disk) using WM_COPYDATA, and
returns data from the same...  Below is the Perl code I've tried,
followed by the C code.  I would appreciate ANY help on this, as I'm not
very proficient in C(yet!) and have not yet grasped pack()/unpack() nor
Win32::API.
FWIW: I'm on Win2k Pro - AS 623

use Win32::GUI;
use constant NULL=>0;
use constant WM_COPYDATA => 74;

my $myCommand="[EMAIL PROTECTED]   text\n";
my $wparm = pack("I", NULL);
my $dwData=pack("L",$myCommand);
my $lpCopydatastruct=pack("pLp",$dwData,0,NULL);

$st32H=Win32::GUI::FindWindow("StreetsOnADisk","");  ## this seems to
give me "The handle is invalid"
Win32::GUI::SendMessage($st32H,WM_COPYDATA,$lpCopydatastruct,0);

I've also tried API:

use Win32::API;
use constant NULL=>0;
use constant WM_COPYDATA => 74;

my $myCommand='@CUSTOM_MENU_OK   text'."\n";
my $wparm = pack("I", NULL);
my $dwData=pack("L",$myCommand);
my $lpCopydatastruct=pack("pLp",$dwData,0,NULL);
my $FindWindowEx=new Win32::API('User32','FindWindowEx',[qw(N N P P)],'N');
## this gives me "The specified procedure could not be found"
my $SendMessage=new Win32::API("User32","SendMessage",[qw(N N N N)],'N');
my $hwnd=$FindWindowEx->Call($parent_hwnd,undef,'StreetsOnADisk',undef);
my $lresult=$SendMessage->Call($st32H,WM_COPYDATA,$wparm,$lpCopydatastruct);

And then the C++ code which works just fine for me:

void CAPITestDlg::OnButton1() 
{
        CWnd *pWnd = CWnd::FindWindow("StreetsOnADisk", NULL);

        if (pWnd)
        {
        char commands[100];
        strcpy(commands,"@CUSTOM_MENU_OK   text\n");

        COPYDATASTRUCT cds;
        cds.dwData = 0; //reserved for later use
        cds.cbData = strlen(commands)+1; /* enter the length of the
        command string in the buffer+1 */
        cds.lpData = (void*) commands; /* point to command buffer */
                Sleep(1000);
        LRESULT result = pWnd->SendMessage(WM_COPYDATA,
                                        
(WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),
                                        (LPARAM)&cds);
        if(result==FALSE)  AfxMessageBox("Streets is busy...",MB_OK | 
MB_ICONSTOP);
        }
        else /* on error: */
        {
        AfxMessageBox("Streets On A Disk is not running...",MB_OK | 
MB_ICONSTOP);
        }       
}
BOOL CAPITestDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pcds)
    {
    if(pcds->dwData == 0)
      {
      /* indicates an error processing the commands */
      /* show error log: */
      AfxMessageBox((char *) pcds->lpData,MB_OK | MB_ICONINFORMATION );
      }
    else  /* results were found without errors: */
      {
      /* show results: */
      AfxMessageBox((char *) pcds->lpData,MB_OK | MB_ICONINFORMATION  );
      }

    return CDialog::OnCopyData(pWnd, pcds);
    }

<sig>  Anthony George <[EMAIL PROTECTED]> Systems Engineer.
Do your technical services need medical attention?  We can help.  EMSTS, LLC.
800-304-8269   231-720-1600   http://www.emsts.com  </sig>



Reply via email to