sg_madhu
October 23rd, 2004, 06:16 AM
Hi,
I am working on UPnP software. I can able to search the device and services using UPnP API's. If I uses invoke action with empty arguments its failed. any body have any idea or any sample program, please help me.
In InvokeAction code, HRESULT is failed with "Failed to invoke action...%S ", bstrActionName...
anybody knows what is error in this, please let me know...
#define SF_ACT_BK_POWEROFF _T(L"BacklightPowerOff")
void CSmartFrameDeviceDlg::OnBnClickedBtnPwrOff()
{
BSTR bstrActionName;
bstrActionName = SysAllocString(SF_ACT_BK_POWEROFF);
InvokeActionOnOff(m_pAppService, bstrActionName);
}
void CSmartFrameDeviceDlg::InvokeActionOnOff(IUPnPService *pService, BSTR bstrActionName)
{
HRESULT hr;
if (bstrActionName)
{
SAFEARRAYBOUND rgsaBound[1];
SAFEARRAY *psa = NULL;
rgsaBound[0].lLbound = 0;
rgsaBound[0].cElements = 0;
psa = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
if (psa != NULL)
{
// LONG lStatus;
VARIANT varInArgs;
VariantInit(&varInArgs);
varInArgs.vt = VT_VARIANT | VT_ARRAY;
V_ARRAY(&varInArgs) = psa;
hr = pService->InvokeAction(bstrActionName, varInArgs, NULL, NULL);
if (SUCCEEDED(hr))
TRACE("\nInvokeAction \"%S\" success...", bstrActionName);
else if (hr == UPNP_E_ACTION_REQUEST_FAILED)
TRACE("\nThe device had an internal error; the request could not be executed.");
else if (hr == UPNP_E_DEVICE_ERROR)
TRACE("\nAn unknown error occurred.");
else if (hr == UPNP_E_DEVICE_TIMEOUT)
TRACE("\nThe device has not responded within the 30 second time-out period.");
else if (hr == UPNP_E_ERROR_PROCESSING_RESPONSE)
TRACE("\nThe device has sent a response that cannot be processed; for example, the response was corrupted.");
else if (hr == UPNP_E_INVALID_ACTION)
TRACE("\nThe action is not supported by the device.");
else if (hr == UPNP_E_INVALID_ARGUMENTS)
TRACE("\nOne or more of the arguments passed in vInActionArgs is invalid.");
else if (hr == UPNP_E_PROTOCOL_ERROR)
TRACE("\nAn error occurred at the UPnP control-protocol level.");
else if (hr == UPNP_E_TRANSPORT_ERROR)
TRACE("\nAn HTTP error occurred. Use the IUPnPService::LastTransportStatus property to obtain the actual HTTP status code.");
else
TRACE("\nFailed to invoke action...%S ", bstrActionName);
SafeArrayDestroy(psa);
}
else
TRACE("\nFailed to create safe array ");
}
else
TRACE("\nFailed to allocate action name string");
}
I am working on UPnP software. I can able to search the device and services using UPnP API's. If I uses invoke action with empty arguments its failed. any body have any idea or any sample program, please help me.
In InvokeAction code, HRESULT is failed with "Failed to invoke action...%S ", bstrActionName...
anybody knows what is error in this, please let me know...
#define SF_ACT_BK_POWEROFF _T(L"BacklightPowerOff")
void CSmartFrameDeviceDlg::OnBnClickedBtnPwrOff()
{
BSTR bstrActionName;
bstrActionName = SysAllocString(SF_ACT_BK_POWEROFF);
InvokeActionOnOff(m_pAppService, bstrActionName);
}
void CSmartFrameDeviceDlg::InvokeActionOnOff(IUPnPService *pService, BSTR bstrActionName)
{
HRESULT hr;
if (bstrActionName)
{
SAFEARRAYBOUND rgsaBound[1];
SAFEARRAY *psa = NULL;
rgsaBound[0].lLbound = 0;
rgsaBound[0].cElements = 0;
psa = SafeArrayCreate(VT_VARIANT, 1, rgsaBound);
if (psa != NULL)
{
// LONG lStatus;
VARIANT varInArgs;
VariantInit(&varInArgs);
varInArgs.vt = VT_VARIANT | VT_ARRAY;
V_ARRAY(&varInArgs) = psa;
hr = pService->InvokeAction(bstrActionName, varInArgs, NULL, NULL);
if (SUCCEEDED(hr))
TRACE("\nInvokeAction \"%S\" success...", bstrActionName);
else if (hr == UPNP_E_ACTION_REQUEST_FAILED)
TRACE("\nThe device had an internal error; the request could not be executed.");
else if (hr == UPNP_E_DEVICE_ERROR)
TRACE("\nAn unknown error occurred.");
else if (hr == UPNP_E_DEVICE_TIMEOUT)
TRACE("\nThe device has not responded within the 30 second time-out period.");
else if (hr == UPNP_E_ERROR_PROCESSING_RESPONSE)
TRACE("\nThe device has sent a response that cannot be processed; for example, the response was corrupted.");
else if (hr == UPNP_E_INVALID_ACTION)
TRACE("\nThe action is not supported by the device.");
else if (hr == UPNP_E_INVALID_ARGUMENTS)
TRACE("\nOne or more of the arguments passed in vInActionArgs is invalid.");
else if (hr == UPNP_E_PROTOCOL_ERROR)
TRACE("\nAn error occurred at the UPnP control-protocol level.");
else if (hr == UPNP_E_TRANSPORT_ERROR)
TRACE("\nAn HTTP error occurred. Use the IUPnPService::LastTransportStatus property to obtain the actual HTTP status code.");
else
TRACE("\nFailed to invoke action...%S ", bstrActionName);
SafeArrayDestroy(psa);
}
else
TRACE("\nFailed to create safe array ");
}
else
TRACE("\nFailed to allocate action name string");
}