0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Span を DllImport に渡す

Last updated at Posted at 2019-11-24
// c の定義
SAMPLE_EXPORT void SAMPLE_NumberSequence(unsigned char *bytes, int length);
[DllImport(DllName, EntryPoint = "SAMPLE_NumberSequence")]
public static extern void SAMPLE_NumberSequence_UseRef(ref byte bytes, int length);

と書いておいて

static void StackSample()
{
    Span<byte> span = stackalloc byte[10];
    SampleImport.SAMPLE_NumberSequence_UseRef(ref span[0], span.Length);
    Console.WriteLine(ToString(span));
}

ref span[0] で先頭要素へのリファレンスを渡すことでできた。

実験コード

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?