我要啦免费统计
HTML与C++交互源码工程(NPAPI)
http://bbs.lomox.hk/forum.php?mod=viewthread&tid=36&fromuid=4

1.本demo的使用前提:html与dll放在一起。接入lomox中则无需。

2.在html中写入:
  1. <embedtype="application/npcodeproject"width=800height=200id="plugin">
复制代码
3.javascript 访问plugin:
  1. PLUGIN = document.getElementById('plugin');
复制代码
4.在C++中使用Netscape Plug-in API 的指针启动插件就是代码中的:
  1. NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs)
复制代码
函数:pFuncs为其的指针

5.检查是否有返回信息:
  1. if( !strcmp( "Name", pProp ) )
  2. {
  3.     //allocating Memory 
  4. for the string with invocation of Browser-API
  5.     char *p = 
  6. (char*) NPN_MemAlloc( m_pszName );
  7.     STRINGZ_TO_NPVARIANT( 
  8. p, *result);
  9.     return true;
  10. }
复制代码
6.调用接口

  1. <p>bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, 
  2. uint32_t argCount, NPVariant *result)
  3. {
  4.     char *pFunc = 
  5. NPN_UTF8FromIdentifier(name);</p>
  6. <p>    if( !strcmp( "Add", pFunc ) )
  7.     
  8. {
  9.         int sum = 0;</p>
  10. <p>        for( unsigned int i = 0; i < 
  11. argCount; i++ )
  12.         
  13. {
  14.             if( 
  15. args[i].type == NPVariantType_Int32 
  16. )
  17.             
  18. {
  19.                 
  20. sum += 
  21. args[i].value.intValue;
  22.             
  23. }
  24.             else if( 
  25. args[i].type == NPVariantType_String 
  26. )
  27.             
  28. {
  29.                 
  30. CNPString 
  31. s(args[i].value.stringValue);
  32.                 
  33. sum += atoi( s 
  34. );
  35.             
  36. }
  37.             else 
  38. return false;//an error happenend</p>
  39. <p>        
  40. }
  41.         ..
  42. }</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 阅读(4229) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理