I have been struggling with this problem for a day and a half, I hope someone can help me. Let's say I have structures like this in C #:
public struct Part { public double? x;
(these structures represent database tables converted from Linq to SQL code created by SQLMetal)
I need to provide these structures containing types with a null value, COM, so that they can be used in another application (C ++). But I canβt understand for me how to do this. I thought I could create classes to encapsulate types with a null value:
public class NullableDouble { private double _Value;
Similar works, but on the C ++ side, I get a pointer to a class, but not a class definition (just an interface):
interface DECLSPEC_UUID("{E8EE4597-825D-3F4C-B20B-FD6E9026A51C}") _NullableDouble; struct Part { MyDll_tlb::_NullableDouble* x; }
Thus, I cannot dereference this pointer without defining a class from which you can access data elements / methods on the C ++ side. This still seems like a good option if I can just figure out how to get the class definition in C ++ (I'm new to COM).
I thought maybe I can use unsafe code, but I canβt figure out how to convert from a double? double * (I am also new to C #!):
unsafe public struct Part { public double* x; } Part part = new Part() { x = AnotherObject.x
I was thinking maybe I can use System.Variant, but C # doesn't like it either (inconsistent availability, whatever that means).
public struct Part { public Variant x;
I have been using C ++ for 20 years, but I'm pretty new to COM and C #, so for me this is a battle.
In the worst case ... I simply create a logic element in the structure for each of the types with a null value and use this to indicate whether the value should be processed as if it were null. But it just seems stupid. Of course, some way to show nullable types through COM. Why has Microsoft created .NET types that cannot be used in COM? These guys in Redmond are not idiots (although sometimes it just looks like that).
So what are my options? What is the best way to do this?
Thanks in advance.