I am working with a 3rd party unmanaged dll, and I need to pass an array of
char* as an argument.
I can used fixed to get a single char* as follows:
char[] buf = new char[64];
fixed (char* p = buf) { ... }
But I do not know how many of these to create until runtime. I cannot think
of a way to use fixed in a loop to fix multiple pointers. Is there a way?
Alternately, I could create and fix a single long char[] and treat it as
several shorter char[] as follows:
int count = 3;
char[] buf = new char[64 * count];
fixed (char* b = buf)
{
for (int i = 0; i < count; i++)
{
char* tmp = b + (64 * i); // this is the start of each shorter
char[]
}
}
This would meet my first requirement.
But how do I create an array of char* to hold the values produced by the
above loop? I tried the following, but p is always null. Using the
debugger, it seems that char*[] results in an array of char. Why?
int count = 3;
char[] buf = new char[64 * count];
char*[] ptrs = new char*[count];
fixed (char* b = buf)
{
fixed (char** p = ptrs) // this always leaves p = null
{
for (int i = 0; i < count; i++)
{
p[i] = b + (64 * i);
}
}
}
Thanks in advance,
Wendell