K
KennethK
Guest
I've written an ActiveX control for use in scripting, particularly JavaScript. One of the object's properties is a list device names returned as an array of BSTRs. My problem is that JavaScript does not seem to recognize the array. My current definition in the .idl is SAFEARRAY(BSTR)*. I have also used VARIANT*. When I inspect the object in the I.E. debugger it recognizes the array and displays the strings within. When I try to inspect the property by placing it under the cursor it is undefined as VARIANT and unknown as SAFEARRAY(BSTR). Assigning the contents of the property to a variable produced a variable of type unknown. Interestingly VBA handles the property as an array of strings. In my C++ implementation:
STDMETHODIMP CScanner::GetDevices(SAFEARRAY** pVal)
{
USES_CONVERSION;
try
{
CSimpleMap<CString, TW_IDENTITY>* devices =
_pScanner->GetDeviceList();
INT nCount = devices->GetSize();
CComSafeArray<BSTR> sar;
for (INT i = 0; i < nCount;i++)
{
sar.Add(devices->GetKeyAt(i).AllocSysString());
//sar.Ad(devices->GetKeyAt(i).AllocSysString());
}
delete devices;
*pVal = sar.Detach();
}
catch(CTwainException& ex)
{
return AtlReportError(GetObjectCLSID(), ex.what(), IID_IScanner);
}
return S_OK;
}
Kenney
Continue reading...
STDMETHODIMP CScanner::GetDevices(SAFEARRAY** pVal)
{
USES_CONVERSION;
try
{
CSimpleMap<CString, TW_IDENTITY>* devices =
_pScanner->GetDeviceList();
INT nCount = devices->GetSize();
CComSafeArray<BSTR> sar;
for (INT i = 0; i < nCount;i++)
{
sar.Add(devices->GetKeyAt(i).AllocSysString());
//sar.Ad(devices->GetKeyAt(i).AllocSysString());
}
delete devices;
*pVal = sar.Detach();
}
catch(CTwainException& ex)
{
return AtlReportError(GetObjectCLSID(), ex.what(), IID_IScanner);
}
return S_OK;
}
Kenney
Continue reading...