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.

4

1 回答 1

6

alcOpenDevice 不采用char*[]char**,它采用char*,您应该将其指定为string. 它还返回一个句柄。

    [DllImport("OpenAL32.dll", CharSet = CharSet.Ansi)]
    static extern IntPtr alcOpenDevice(string devicename);
于 2012-12-29T22:46:51.797 回答