Why does it seem that so many people want to avoid C++/CLI? If you have to ask how to use P/Invoke, that might be a hint to use C++/CLI instead.
Something along the lines of the following in JasonRShaver.h
namespace StackOverflow
{
public ref class JasonRShaver abstract sealed // "abstract sealed" -> "static"
{
public:
static int Generalize(array<array<BYTE>^>^ items) {
int count = items->Length;
std::vector<const BYTE*> arrays(count);
for each (array<BYTE>^ a in items)
{
BYTE* bytes = new BYTE[a->Length];
for (int i=0; i<a->Length; i++)
bytes[i] = a[i];
arrays.push_back(bytes);
}
int retval = ::Generalize(count, &(arrays[0]));
typedef std::vector<const BYTE*>::const_iterator it_t;
for (it_t it = arrays.begin(); it != arrays.end(); ++it)
{
const BYTE* bytes = *it;
delete[] bytes;
}
return retval;
}
};
}
This isn't production-quality code (e.g., exception handling), and you might be able to do even a better job with pin_ptr<>
and the like. But you get the general idea.