0
我正在創建一個用於Chrome擴展的小型NPAPI插件。 擴展的主要目標是能夠從網頁打開PuTTY(帶參數)。NPAPI Chrome擴展:如何執行包含的可執行文件?
我讓它工作......除了通往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;
}
任何幫助,將不勝感激!