__declspec(dllexport) constantly crashes Rhino

I don’t know why this is happening. When i try to use __declspec(dllexport) all functions are crashing rhino but things which are set with extern "C" __declspec(dllexport) in front are working ok.

@dale would you mind give me a hint why this is happening? I made a simple set without and with (extern “C”) i don’t understand why i cannot use ‘normal’ ones.

For being precise i’m calling the library from the code.

The extern is needed to ensure unmangled name export, especially necessary for PInvoke

or

1 Like

@nathanletwory Thanks for the excellent answer on this i tried with mangled names and it seems to work but now i see that pushing whole class in dllexport with mangled names is rather a pain. This time i don’t need it for pinvoke (this side is almost ready) but for c++ example call and hook as a listener…

Related question: I know i’ve asked many times but i’ll try one last time (since CRM won’t work in my case) is there any suitable way to leave in doc data for other plugins? I don’t ask for much - sth like would be nice Dictionary(string, List(double[16]) - simpler case would be array(string,double[16]) ?

I’ve asked @steve but i didn’t get any respond -> How i can reference my plugin?

You probably are best off reading up on creating libraries in C/C++ in general. The MSDN gives quite a bit of info on that, and the internet is also full of good knowledge on the subject :slight_smile:

I think that the best chance at this very moment is with point clouds: the location and normal you can use for location and orientation of your items, the color you could probably use as the part to convey scale. Then you can add a user string with SetUserString on the pointcloud with the point index as key, and any other information serialized into a string as value - that way you can have existing data structures that any plug-in can access without too many hoops.

Note though that we’d like to figure out a better way together with @andy for your case.

Yah, probably not that guy, because this user was active last back in 2013… :slight_smile:

If you need any input from my side I’m open to questions. Have in mind also that my attempt with empty mesh in blocks was just a workaround which produced enormously big files (no control on save not saying that autosave would last forever) and since block with empty mesh was listed in block manager user could mess up things quickly.

We will come with questions at some point, we’d like to have your kind of use case covered as well.

@nathanletwory at your service. As always i have an additional question. How do i convert C# guid to C++ ON_UUID to find instance? I made the bridge already and i have guid as wchar_t on the other side but after an hour of looking around i can’t still find the answer - it could be that i’m blind :face_with_monocle: .

I need to pass ON_UUID here: https://developer.rhino3d.com/api/cpp/class_c_rhino_instance_definition_table.html#a536a2ef2d12bdef0154be8ccc9b8dd77

@dale some advice?

How about this:

publc void GuidTest()
(
  var guid = Guid.NewGuid();
  UnsafeNativeMethods.GuidTest(ref guid);
)

[DllImport("MyLib.dll", CallingConvention=CallingConvention.Cdecl)]
internal static extern void GuidTest(ref Guid guid);

extern "C" __declspec(dllexport) void GuidTest(ON_UUID* guid)
{
  if (nullptr != guid)
  {
  }
}

– Dale

Hi @dale! I really appreciate very quick answer. Hmm this changes my conception a bit since here is indeed passed pointer to c# GUID (?) I believe this is kinda tricky now since my c++ bridge is rhino independent so i don’t have ON_UUID type def? I get -> incomplete type is not allowed.

@dale thanks for effort i digged deep into opennurbs_uuid.h and found that there’s fortunately UuidFromString function!

Replace ON_UUID* with GUID*.

– Dale