Click to See Complete Forum and Search --> : COM automation in PHP problem(CORRECTION)


chingwaah
09-08-2002, 12:54 AM
This ATL (EXE) works fine when using VB as an automation CLIENT. However,
when attempting to use this same ATL in PHP, following code causes an
exception ("Warning: invoke() failed. ....threw exception."

I found this exception by wrapping the try block around the code as follow;

STDMETHODIMP CMyApp::OpenQuery(BSTR bstrQuery)
{
METHOD_PROLOGUE_ATL

try{
CWnd* pWnd =
((CFrameMain*)m_pMainWnd)->m_SearchToolbar.GetDlgItem(IDC_COMBO_SEARCH);
CWnd* pBtn =
((CFrameMain*)m_pMainWnd)->m_SearchToolbar.GetDlgItem(IDC_BUTTON_SEARCH);
pWnd->SetFocus();
pWnd->SetWindowText(CString(bstrQuery));

m_pMainWnd->SendMessage(WM_COMMAND, (WPARAM)MAKELONG(IDC_BUTTON_SEARCH,
0), (LPARAM)pBtn->m_hWnd);

//Return the view
*hView = GetWindowLong(pWnd->m_hWnd, GWL_USERDATA);
}
catch(...){
*hView = (long)-1;
}
return S_OK;
}

if I don't put the try block around the above, the PHP code would generated
the "WARNING: invoke() failed. ....threw exception." Further investigation,
I found that m_pMainWnd is NULL, even when the application is clearly
visible and running. I also tried AfxGetMainWnd() in side the above method
without success.

PS. I also tried AFX_MANAGE_STATE(AfxGetStaticModuleState()) as a
prologue code with the same result.

---------------------------------------------------------CODE---------------
------------------------------------------
PHP code:
<?php
$obj = new COM("AutoExe.Application") or die("Unable to create object");
$ret = $obj->OpenQuery("test");
$obj = null;
?>

jeremuck
09-11-2002, 11:19 AM
replace this line:
$ret = $obj->OpenQuery("test");


with

$ret = com_invoke($obj, "OpenQuery", "test");


In Dealing with COM there are four functions:

load_com (or new COM())

value com_get(class com_object, string property)

bool com_set(class com_object, string property_name, string value)

and finally

value com_invoke(class com_object, string method_name, string arg1, string arg2......)

I had the same problem, and using com_invoke fixed it. I don't know how you are supposed to know whether to use invoke and set or when you can access them directly.
It's probably safest to use the com functions all the time.


Ben

chingwaah
09-12-2002, 05:20 AM
Ben, Thank

However, prior to posting the original message, I have tried both methods of calling com without success.

In fact, I'm able to trace the call from php into the COM (using _asm int 3) method until I'm attempting to use the Afx______ function. At this point the m_pMainWnd is NULL, even when I made sure the apllication is visible.

Additional info.

this = > the application (the pointer is correct)
m_pMainWnd = NULL (go figure)
module state = is correct

Thx again.
Jeff