I would like to pass a nativeElementRef from a .NET application to a library function written in MDL/C++. In V8i I declared the C++ function like this:
using SRI=System.Runtime.InteropServices; namespace WhatEver { class MyClass { [SRI.DllImport("mylib.dll", EntryPoint = "lib_MyFunction", CallingConvention = SRI.CallingConvention.StdCall)] static extern void lib_MyFunction(int elementRef);
and called the function like this:
lib_MyFunction(pElement.MdlElementRef());
Snippet from the MDL / CPP source file:
extern "C" lib_myFunction(ElementRef elmRefIn) { MSElement baseElm; elementRef_getElement(elmRefIn, &baseElm, elementRef_getElemSize(elmRefIn));
Now I would like to do the same in Connect.
I've declared the function like this:
[SRI.DllImport("mylib.dll", EntryPoint = "lib_MyFunction", CallingConvention = SRI.CallingConvention.StdCall)] static extern void lib_MyFunction(System.IntPtr elm);
and calls the function like this:
lib_myFunction(elm.GetNativeElementRef());
In MDL / CPP the function looks like this:
extern "C" void lib_myFunction(ElementRefP elmRef) { MSElement elm; elementRef_getElement(elmRef, &elm, elementRef_getElemSize(elmRef));
Both parts C# and C++ compiles fine but when the AddIn application is started, the element is identified and I call the C++ function MicroStation crashes. Please tell me why.
TIA.
Regards Evan
Unknown said:Both parts C# and C++ compiles fine but when the AddIn application is started, the element is identified and I call the C++ function MicroStation crashes
MicroStation CONNECT is 64-bit. Have you rebuilt your DLL as a 64-bit app.?
Regards, Jon Summers LA Solutions
Unknown said:lib_myFunction(elm.GetNativeElementRef());
I notice that there is a similar function public IntPtr GetNativeElementRefFromDescr(). How that differs from GetNativeElementRef() is not clear.
I've found the solution ;-)
I just had to include DLLEXPORT in C++ so that the function header now looks like this:
extern "C" DLLEXPORT void lib_myFunction(ElementRefP elmRefIn)
Regards, Evan
Answer Verified By: EvanH
I'm pleased to read that you have supplied your own solution!
Unknown said:I just had to include DLLEXPORT in C++
DLLEXPORT is a macro. The pre-processor substitutes Microsoft directive __declspec(dllexport). I'm a little puzzled, for without that directive your DLL would not have worked correctly in the 32-bit version either.