Не надо unsafe...
[DllImport(@"C:\data\TEST\Win32Project2\Debug\Win32Project2.dll")]
public static extern int MyFunc(out int sz, out IntPtr p);
..........
int sz;
IntPtr p;
MyFunc(out sz, out p);
var a = new double[sz];
Marshal.Copy(p, a, 0, sz);
Marshal.FreeCoTaskMem(p);