0

尝试使用 NPAPI 插件通过 Javascript 获取属性值时出现问题;在调试过程中,我看到调用了所有函数链(HasProperty、HasMethod 和 GetProperty)。此外,我看到在调用 GetProperty 期间,我将新值设置为结果参数。但是在离开 GetProperty 之后,我得到了一个异常,无法理解它的原因。

FireFox 可以调用一些我忘记初始化的附加函数吗?

提前致谢

我的代码是:

// static function which calls Get_Property for the instance of CScriptableNPObject
bool CScriptableNPObject::NP_GetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
{
    m_Logs.WriteLogs(10, _T("Enter the CScriptableNPObject::NP_GetProperty()"));

    return ((CScriptableNPObject *)npobj)->GetProperty(name, result);
}

// just converter name from NPIdentifier to char *
bool CScriptableNPObject::GetProperty(NPIdentifier name, NPVariant *result)
{
    NPUTF8 *pszProperty = m_pNPNFuncs->utf8fromidentifier(name);

    return GetProperty(pszProperty, result);
}

// checking the dictionary of properties, if property exists put its value into the result
bool CScriptableNPObject::GetProperty(NPUTF8 *pszProperty, NPVariant *result)
{
    VOID_TO_NPVARIANT(*result);

    JSPropertiesMap::iterator it = m_JSProperties.find(pszProperty);

    if (it == m_JSProperties.end())
        return false;

    NPUTF8 *pszNewPropertyValue = new NPUTF8[it->second->value.stringValue.UTF8Length + 1];
    sprintf(pszNewPropertyValue, it->second->value.stringValue.UTF8Characters);

    STRINGZ_TO_NPVARIANT(pszNewPropertyValue, *result);

    return true;
}
4

1 回答 1

1

您需要使用NPN_MemAlloc()

NPUTF8* newValue = NPN_MemAlloc(length + 1);
于 2012-12-11T04:36:40.837 回答