我正在创建一个用于 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;
}
任何帮助,将不胜感激!