My C# method needs to be invoked from C++
Originally my C# method takes a parameter of type double[], but when calling from C++ it becomes a SAFEARRAY
In C++
Continuing on @Liton's answer, I want to stress his last sentence, i.e. ATL's CComSafeArray
. It really can save you a lot of typing. CComSafeArray
has C++ constructors, destructors, operator overloads including one for [ ] that gives you an read / write reference to any element in the SAFEARRAY
. In short, you can really focus on your business logic and needn't worry about the SAFEARRAY
plumbing:
#include
#include
// ...
CComSafeArray arr(10);
arr[0] = 2.0;
arr[1] = 3.0;
arr[2] = 5.0;
// ...
At the very least, even if you're not going to use CComSafeArray
it's worthwhile to deconstruct its source code in
giving you better insight on the what, when, why and how on SAFEARRAY
functions.