Secret
Secret

Reputation: 2647

C# unsafe type -> char*[] , getting a pointer on char array

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:

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.

Upvotes: 1

Views: 6339

Answers (2)

Jens Eckervogt
Jens Eckervogt

Reputation: 1

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...

Upvotes: 0

Aleksandr Dubinsky
Aleksandr Dubinsky

Reputation: 23505

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);

Upvotes: 6

Related Questions