1

Have:

[DllImport("OpenAL32.dll")]
static extern void alcOpenDevice(char*[] devicename);

Wanna send the name to this function like smth that:

char[] data = "Hello!".ToCharArray();
char*[] txt = &data;

But getting the errors:

  • cannot implicitly convert type char[] * to char * []

    (funny error, because C# compiler refuses to define char[] * in /unsafe mode also :) )

  • Cannot take the address of, get the size of, or declare a pointer to a managed type (char[])

PS
When does char become managed? It's a struct, isn't it?

public struct Char : IComparable, IConvertible, IComparable<char>, IEquatable<char>

Although compiler showed info about declaring the pointer to a managed type (char[]). I can only suggest that when the type is an array CLR may present it like a managed type, but it sounds very crazy.

2 Answers 2

6

alcOpenDevice does not take char*[] or char**, it takes char*, which you should specify as a string. It also returns a handle.

    [DllImport("OpenAL32.dll", CharSet = CharSet.Ansi)]
    static extern IntPtr alcOpenDevice(string devicename);
Sign up to request clarification or add additional context in comments.

21 Comments

Ahh, I got confuse for a while. "char*[]" ? is that even valid ?
char* is valid for C/C++; char* in C# is different stuff, it's not a pointer to char-array in C#, it's a pointer to a single char ( main different between C/C++ and C# definition of char* )
@Icarus3 Yes, since the compiler accepts it. It is an array of char*. Use it to pass many char* to a function, by automatically marshalling the managed array to a char**
@OlegOrlov That is not true. It can be a pointer to many chars. An int* can be a pointer to many ints. Just like C/C++. You can use fixed(int* intPointer = intArray)
C# char is not the same as C or C++ char (nevermind pointers or arrays).
|
0

If you use char[] to char*

You missed fixed statement:

char[] data = "Hello!".ToCharArray();
fixed (char* dataPtrs = data)
{
    // Logic here ...
}

I hope that my code helps you.

If you want to use char*[] from char** ( char Double Pointer ) - I will look for resolving...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.