Hi,
I’m using the OpenNURBS library to do some conversions between Rhino objects and OpenCascade geometry. I would like to wrap this functionality so that I can call some C-style functions from a .NET assembly (i.e. declspec’cing into a .gha
).
Is it possible to get a raw pointer to the Rhino types in C#? Looking through the docs, I can’t find anything that might yield an IntPtr
or similar, but perhaps there are other methods for this? If it is possible, are there any obvious ‘gotchas’ that I should look out for, i.e. difference in versions between the OpenNURBS API and the Rhino I’m running?
Thanks in advance for any tips
Found it
For anyone looking for the same:
IntPtr ptr = Rhino.Runtime.Interop.NativeGeometryConstPointer(GeometryBase geo);
from Interop Methods
Seems to work OK!
It is possible to get a raw pointer to Rhino objects in C# using the Rhino.Runtime.HostUtils.GetConstPointer()
and Rhino.Runtime.HostUtils.GetNonConstPointer()
methods. These methods can be used to obtain pointers to Rhino objects, which can then be passed to C-style functions.
However, it’s important to note that the use of pointers can be dangerous and should be used with caution.
Both of these methods are used to obtain pointers to Rhino objects that can be used in C-style functions or passed to external libraries. The difference between them is that GetConstPointer()
returns a pointer to a constant version of the object, while GetNonConstPointer()
returns a pointer to a non-constant version of the object.
The GetConstPointer()
method takes a single argument, which is the Rhino object for which a pointer is required. This method returns a constant pointer to the object, which can be used to access the data associated with the object, but cannot be used to modify the object in any way. This is useful when you want to pass the object to a C-style function that expects a constant pointer.
The GetNonConstPointer()
method also takes a single argument, which is the Rhino object for which a pointer is required. This method returns a non-constant pointer to the object, which can be used to modify the object. This is useful when you want to pass the object to a C-style function that expects a non-constant pointer.
1 Like