0
votes

I'm creating a small NPAPI Plugin to be used in a Chrome extension. The main goal of the extension is to be able to open PuTTY (with arguments) from a web page.

I have it working...with the exception of the path to PuTTY. I have the path hard coded to a location on my C drive. I'd like to include the executable and have it run from the installation directory. How do I do that? Here is my Invoke Method:

 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;
 }

Any help would be appreciated!

1

1 Answers

1
votes

In your DllMain:

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

strDllPath1 will now contain the path and filename of the plugin DLL; from there you should be able to find the path to whatever else is installed next to it.