【问题标题】:NPAPI Chrome Extension: How to execute included executable file?NPAPI Chrome 扩展:如何执行包含的可执行文件?
【发布时间】:2013-09-10 21:13:22
【问题描述】:

我正在创建一个用于 Chrome 扩展的小型 NPAPI 插件。 该扩展的主要目标是能够从网页打开 PuTTY(带参数)。

我可以正常工作...除了 PuTTY 的路径。我将路径硬编码到 C 驱动器上的某个位置。我想包含可执行文件并让它从安装目录运行。我怎么做?这是我的调用方法:

 bool ScriptablePluginObject::Invoke(NPObject* obj, NPIdentifier methodName,
                 const NPVariant* args, uint32_t argCount,
                 NPVariant* result) {
   ScriptablePluginObject *thisObj = (ScriptablePluginObject*)obj;
   char* name = npnfuncs->utf8fromidentifier(methodName);
   bool ret_val = false;
   if (!name) {
      return ret_val;
   }
   if (!strcmp(name, kOpenPutty)) {
     ret_val = true;
     std::string strCMD = std::string("C:\\putty.exe ") +  args[0].value.stringValue.UTF8Characters;
     system(strCMD.c_str());
     const char* outString = "success";
     char* npOutString = (char *)npnfuncs->memalloc(strlen(outString) + 1);
     if (!npOutString)
        return false;
     strcpy(npOutString, outString);
     STRINGZ_TO_NPVARIANT(npOutString, *result);
   } else {
      // Exception handling. 
      npnfuncs->setexception(obj, "Unknown method");
   }
   npnfuncs->memfree(name);
   return ret_val;
 }

任何帮助将不胜感激!

【问题讨论】:

    标签: google-chrome-extension npapi


    【解决方案1】:

    在您的 DllMain 中:

    TCHAR* strDLLPath1(new TCHAR[_MAX_PATH]);
    ::GetModuleFileName(hInstance, strDLLPath1, _MAX_PATH);
    

    strDllPath1 现在将包含插件 DLL 的路径和文件名;从那里你应该能够找到旁边安装的任何其他东西的路径。

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 1970-01-01
      • 2012-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-22
      • 2018-12-28
      • 1970-01-01
      相关资源
      最近更新 更多