C++/CLI Problems with GH_Exposure Code Conversion

I am almost there on getting a C++/CLI Component working.
The purpose of this component is to to save myself extra coding down the pipeline. I’m trying to eventually pass calculations to GPU Kernels.

I could set up a three way street where I make the call from C# to a
.dll set up for CUDA operations. But If I could get away from needing
the C# altogether it would be an avenue Id be willing to explore.
I am having issues with an error thrown by the following code:

//C# Original
public override GH_Exposure Exposure
{
get { return GH_Exposure.primary; }
}

This gets Converted to C++/CLI to look like
//.h file code:

 public:
     property GH_Exposure ^Exposure
     {
         virtual GH_Exposure ^get() override;
     }

//.cpp file code:

GH_Exposure ^Exposure::Exposure::get()
{
return GH_Exposure::primary;
}

On build time it returns the error
’Grasshopper::Kernel::GH_Exposure
^MyProject1::MyProject1Component::Exposure::get(void)’: overriding
virtual function return type differs from
’Grasshopper::Kernel::GH_Exposure
Grasshopper::Kernel::GH_DocumentObject::Exposure::get(void)’

If I get rid of the the Exposure lines altogether along with the bitmap call its
using then it compiles, but… then the component cannot be called
from grasshopper.

I would recommend getting away from C++/CLI if possible and just create pInvokes into your C++ DLL that is using CUDA.


Not seeing more code, I can’t exactly tell where your compile error is coming from. I would recommend getting rid of the using statements at the beginning of the file and explicitly call out the return type. That may help pin down the source of the problem.

c .zip (9.7 MB)

Here is the VS2013 Project if it helps. I have been told the PInvoke method as a solution several times now and even on the NVidia forums have read that its probably a better solution. If you come up with anything from this let me know. I’m an architect by trade and wont get to trying the PInvoke method until later in the week.

Sorry, but I also won’t be able to get to debugging something of this scale for a while myself either. I’m pretty loaded with other pressing projects at the moment.

Not a problem. Understandable.

I’m not sure what you mean by “gets converted to C++/CLI” - are you using a translator?

I think that this part should be changed (also in the header).

GH_Exposure ^Exposure::Exposure::get()
{
   return GH_Exposure::primary;
}

to

GH_Exposure Exposure::Exposure::get() // notice the missing caret
{
return GH_Exposure::primary;
}

The caret means that it is a managed reference. Managed references are created by new in C# and gcnew in C++/CLI. As the Exposure is an enum (that is, not a reference type, but a value type) you don’t need to use the caret or gcnew.

But, if you can get away from C++ altogether, please do so. Using P/Invoke is preferred. For CUDA there are also .NET libraries, like CUDAfy, which allow you to write GPU code in .NET (untested by me, only by hearsay).