C++/CLI 调用不带参数的 Interop 包装器方法
我有一些非托管 DLL 调用的互操作包装器,这些调用通过参数返回详细信息。这些函数如下所示:
_myWrapper->My_Method( ... out UInt32 value ... );
假设该方法是这样声明的:
void My_Method(out UInt32 value);
那么我如何从 C++/CLI 代码中调用此方法?我知道如何调用这样的参考方法很简单:
void Another_Method(ref UInt32 value);
UInt32 _value;
_myWrapper->Another_Method(%_value);
我正在阅读一些内容,并且我正在阅读它无法完成?我不相信......这可能不是不可能克服或解决的方法,但你一定是在开玩笑吧?这是真的吗?
谢谢...
I've got an Interop wrapper to some unmanaged DLL calls that return details through out paremeters. The functions appear like this:
_myWrapper->My_Method( ... out UInt32 value ... );
So assuming the method is declared like this:
void My_Method(out UInt32 value);
How do I then call this method from within my C++/CLI code? I know how to call reference methods such as this easy enough:
void Another_Method(ref UInt32 value);
UInt32 _value;
_myWrapper->Another_Method(%_value);
I'm doing a little reading and I am reading it can't be done? I don't believe it... Likely this isn't impossible to overcome or workaround, but you've got to be kidding me? Is that really true?
Thank you...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 C++ 中,没有特殊的调用语法来调用带有引用参数的函数,您只需像按值传递一样编写调用即可。当然,您需要提供要覆盖的左值,不能使用算术表达式的右值(临时)结果。
顺便说一句,您调用 ref 函数的代码也是错误的,这可能是您麻烦的根源。
示例:
C# 定义:
C++/CLI 定义:
C# 调用:
C++/CLI 调用:
In C++, there's no special call syntax for calling a function with a reference parameter, you just write the call like it was pass-by-value. Of course, you need to supply an lvalue to be overwritten, the rvalue (temporary) result of an arithmetic expression can't be used.
BTW, your code for calling a
ref
function is wrong too, that might be the source of your troubles.Example:
C# definition:
C++/CLI definition:
C# call:
C++/CLI call: