The (incomplete) snippet
unsafe class MainWindow
{
...
IntPtr somePtr = IntPtr.Zero;
unsafe private void Click(object sender, RoutedEventArgs e)
{
NamespaceFromReferencedUnsafeDll.SomeFunction(&somePtr)
}
...
}
}
Is supposed to call SomeFunction
from a managed Dll with unsafe code, to set the pointer somePtr
, but results in the compiler error
CS0212: You can only take the address of an unfixed expression inside of a fixed statement initializer
According to this answer, the fixed
keyword has to be used in some way, but
fixed(IntPtr somePtr = IntPtr.Zero);
didn't help.
How can I fix this (no pun intended) ?