如何将v8::value强制转换为LPCSTR



我正在尝试制作一个节点插件并复制一些C++代码。一行给我一个错误

void Attach(const FunctionCallbackInfo <Value> &args) {
Isolate *isolate = args.GetIsolate();
HWND target = FindWindowA(NULL, args[0]);
...

javascript的用法是

const title = window.getTitle();
const attach = addon.attach(title)

其中"window"是电子中BrowserWindow的一个实例

错误

'HWND FindWindowA(LPCSTR,LPCSTR)': cannot convert argument 2 from 'v8::Local<v8::Value>' to 'LPCSTR'

我确实理解选角,但我对Windows、C++的理解/经验非常有限,这是我第一次尝试插件。

我在这里找到了答案将v8::字符串转换为LPCWSTR?但我无法理解。

我在一个法语论坛上找到了解决方案https://zestedesavoir.com/forums/sujet/13978/c-probleme-de-conversion-de-type-stringchar/.

Isolate *isolate = args.GetIsolate();
Local<Context> context = isolate->GetCurrentContext();
Local<String> appName = args[0].As<String>();
CHAR* charAppName = new CHAR[128];
(*appName)->WriteUtf8(isolate, charAppName);
HWND target = FindWindowA(NULL, charAppName);

这使我能够在没有错误的情况下进行编译,并且插件可以按预期工作。虽然我根本不明白每一行在做什么。

最新更新