HTML與C++交互源碼工程(NPAPI)
1.本demo的使用前提:html與dll放在一起。接入lomox中則無需。2.在html中寫入:- <embedtype="application/npcodeproject"width=800height=200id="plugin">
復制代碼 3.javascript 訪問plugin:- PLUGIN = document.getElementById('plugin');
復制代碼 4.在C++中使用Netscape Plug-in API 的指針啟動插件就是代碼中的:- NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
復制代碼 函數:pFuncs為其的指針5.檢查是否有返回信息:- if( !strcmp( "Name", pProp ) )
- {
- //allocating Memory
- for the string with invocation of Browser-API
- char *p =
- (char*) NPN_MemAlloc( m_pszName );
- STRINGZ_TO_NPVARIANT(
- p, *result);
- return true;
- }
復制代碼 6.調用接口
- <p>bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
- uint32_t argCount, NPVariant *result)
- {
- char *pFunc =
- NPN_UTF8FromIdentifier(name);</p>
- <p> if( !strcmp( "Add", pFunc ) )
-
- {
- int sum = 0;</p>
- <p> for( unsigned int i = 0; i <
- argCount; i++ )
-
- {
- if(
- args[i].type == NPVariantType_Int32
- )
-
- {
-
- sum +=
- args[i].value.intValue;
-
- }
- else if(
- args[i].type == NPVariantType_String
- )
-
- {
-
- CNPString
- s(args[i].value.stringValue);
-
- sum += atoi( s
- );
-
- }
- else
- return false;//an error happenend</p>
- <p>
- }
- ..
- }</p>
復制代碼 7.示例中為編譯后的dll,html,以及一份工程。環境:vs2008與vs2010 下載地址
http://bbs.lomox.hk/forum.php?mod=viewthread&tid=36&fromuid=4
posted on 2012-05-28 13:43
爬 閱讀(4270)
評論(0) 編輯 收藏 引用