简体   繁体   English

如何将字符串值从 C++ 返回到 javascript (windows/Visual Studio 2008)?

[英]How do I return a string value from C++ to javascript (windows/Visual studio 2008)?

I have the following IDL which works fine for passing a string value from JS to C++.我有以下 IDL,它可以很好地将字符串值从 JS 传递到 C++。 The JS code passes a string value to the c++/COM object. JS 代码将字符串值传递给 c++/COM 对象。

[id(1), helpstring("method DoSomething")] HRESULT DoSomething([in] BSTR otlToken);

I now need to add another method to return a string to a javascript caller.我现在需要添加另一个方法来将字符串返回给 javascript 调用者。 I added the following to the IDL:我在 IDL 中添加了以下内容:

[id(3), helpstring("method GetValue")]  HRESULT GetValue([out] BSTR *nicknames);

The developer who is working on the JS side says he gets a message about wrong number of arguments and other things depending on if he tries to call the method or access it as a property.在 JS 方面工作的开发人员说,他收到一条关于错误数量的参数和其他事情的消息,这取决于他是尝试调用该方法还是将其作为属性访问。

Does JS require a call by reference to get this or do I have to pass the one BSTR* param as [in,out]? JS 是否需要通过引用调用来获取它,还是我必须将一个 BSTR* 参数作为 [in,out] 传递?

How can I get this to work?我怎样才能让它发挥作用? (getting a string value from C++/IDL to a JS caller? (从 C++/IDL 获取字符串值到 JS 调用者?

What does the IDL have to look like and what should the JS code look like? IDL 必须是什么样子,JS 代码应该是什么样子?

Javascript itself does not know how to handle values returned through parameters. Javascript 本身不知道如何处理通过参数返回的值。 You have to explicitly declare which parameter is the return value otherwise COM will simply return the HRESULT.您必须明确声明哪个参数是返回值,否则 COM 将简单地返回 HRESULT。 You can do this with the following.您可以使用以下方法执行此操作。

[id(3), helpstring("method GetValue")]  HRESULT GetValue([out, retval] BSTR *nicknames);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NAPI 插件:如何从 C++ CALLBACK 将值返回给 javascript? - NAPI Addon : how to return value to javascript from c++ CALLBACK? 如何使用N-API将BigInt类型从C ++返回到javascript? - How do I return a BigInt type from C++ to javascript using N-API? 如何在Visual Studio 2008或Visual Studio 2010中设置JavaScript断点 - How to set JavaScript breakpoints in Visual Studio 2008 or Visual Studio 2010 如何从 Javascript 中的 function 的工作人员返回值 - how do I return a value from a worker for a function in Javascript 如何从 JavaScript 中的 Handler 函数获取返回值? - How do I get a return value from a Handler function in JavaScript? 如何从javascript函数和值返回true? - How do I return true from a javascript function along with a value? 如何将值从 JavaScript 中的函数返回到 HTML 中的文本框 - How do I return a value from a function in JavaScript to a textbox in HTML 如何在 javascript 中返回 promise 的值? - How do I return value from promise in javascript? 如何在Visual Studio 2008中使用JavaScript / jQuery Intellisense? - How do you get JavaScript/jQuery Intellisense Working in Visual Studio 2008? 如何将二进制数据从C ++发送到Javascript - How do i send binary data from C++ to Javascript
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM