需要 Firefox ctypes 输出字符串参数的工作示例
您好,我有一个 XPCOM 组件,我现在正在将其转换为使用 ctypes。
我能够创建采用 wchar_t* 的函数,并使用 ctypes.jschar.ptr 定义函数。 这一切都很好,但是当我需要创建 wchar_t 指针和指针数组时,如何使用输出参数?
我读了很多书,但我很困惑。
- 我应该如何分配内存 在我的 C dll 中?我应该使用 分配?如果是的话那会怎样 释放了?
- 您将如何分配和处理 wchar_t * 的输出参数?我会吗 从 javascript 将其作为 我之前声明过CData吗?
- 我应该如何处理 wchar_t 字符串 大批?
谁能给我一些代码示例来说明如何处理这样的函数? (在C方面,使用malloc?或者我应该使用什么来分配内存,而在javascript方面,应该如何处理)?
int MyFunc(wchar_t** outString, wchar_t*** outStringArray)
谢谢!
Hi I have an XPCOM component which I'm now converting to use ctypes.
I was able to create functions that take a wchar_t* and I define the functions using ctypes.jschar.ptr.
This all works great, but how do I use output parameters when I need to create wchar_t pointers and array of pointers?
I have done a lot of reading and I'm confused.
- How should I allocate the memory
inside my C dll? should I use
malloc? if so how would that get
freed up? - How would you allocate and handle an
out parameter of wchar_t * ? would I
pass it in from javascript as a
CData I declate before? - How should I handle a wchar_t string
array?
Can anyone give me some code examples of say how to handle a function like this?
(both on the C side of things, using malloc? or what should I use to allcoate the memory and on the javascript side, how this should be handled)?
int MyFunc(wchar_t** outString, wchar_t*** outStringArray)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

我想我可以帮助回答你的第二个问题。
在 C 端,接受输出参数的方法如下所示:
在 JavaScript 端:
此论坛帖子提供了帮助: http://old.nabble.com/-js-ctypes--How-to-handle-pointers-and-get-multiple-values-td27959903.html
I think I can help with your second question.
On the C side, your method which accepts an output parameter looks like:
And on the JavaScript side:
This forum post helped: http://old.nabble.com/-js-ctypes--How-to-handle-pointers-and-get-multiple-values-td27959903.html