呼叫托管 C++ C# 中的函数
我有一个用于非托管 C++ 代码的托管 C++ 包装器,并且有必要在方法中使用一些指针参数!
在 C# 中调用此包装函数的最佳方法是什么(我在托管代码中使用引用参数进行了尝试,并创建了指针,然后调用非托管代码)?
示例:
// c++/managed
Uint32 someMethod(int &value);
Uint32 Wrapper::someMethod(int &value)
{
int *valuePtr = &value;
return unmanagedObj->someMethod(valuePtr);
}
// c++/unmanaged
Uint32 someMethod(int *value);
Uint32 UnmanagedClass::someMethod(int *value)
{
...
}
我在 VS2008 中使用带有“添加引用”的托管 C++ 包装器,但是当我调用 someMethod 时 在C#中只有指针而不是引用?!
// c#
// e.g. value conversion to C++ pointer
...
Wrapper wrapper = new Wrapper();
wrapper.someMethod(ref value); // should work but here we have an C++ pointer
// and not a reference ?!?!
感谢您的任何提示!
问候
I have an managed C++ Wrapper for unmanaged C++ code and it's necessary to use some pointer parameters into the methods!
What's the best way in C# to call this wrapper functions (I tryed it with reference parameter in the managed code and create the pointer and call then the unmanaged code)?
Example:
// c++/managed
Uint32 someMethod(int &value);
Uint32 Wrapper::someMethod(int &value)
{
int *valuePtr = &value;
return unmanagedObj->someMethod(valuePtr);
}
// c++/unmanaged
Uint32 someMethod(int *value);
Uint32 UnmanagedClass::someMethod(int *value)
{
...
}
I use the managed C++ wrapper with "add reference" in VS2008, but when I call someMethod
in C# there are only a pointer instead of reference?!
// c#
// e.g. value conversion to C++ pointer
...
Wrapper wrapper = new Wrapper();
wrapper.someMethod(ref value); // should work but here we have an C++ pointer
// and not a reference ?!?!
Thank you for any tips!
greets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是
int%
,这是 C++CLI 引用的正确语法,称为 跟踪参考:What you are looking for is
int%
, which is the correct syntax for C++CLI references and called a tracking reference: