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:😮penQuery(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;
?>