首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

指针和固定大小缓冲区只能在不安全的上下文中使用解决办法

2012-04-15 
指针和固定大小缓冲区只能在不安全的上下文中使用[DllImport(Mwic_32.dll, EntryPoint swr_4442, Se

指针和固定大小缓冲区只能在不安全的上下文中使用
[DllImport("Mwic_32.dll", EntryPoint = "swr_4442", SetLastError = true, CharSet = CharSet.Ansi, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]  
  public static extern int swr_4442(int icdev, int offset, int len, char* w_string);  


中出现了 如题中的问题,应该如何解决!~

[解决办法]
属性中勾选允许不安全代码,然后这些放在unsafe段
[解决办法]
char*换成string,不过w_string应该是宽字符吧
这样
[DllImport("Mwic_32.dll")]
public static extern int swr_4442(int icdev, int offset, int len, [MarshalAs(UnmanagedType.BStr)]string w_string);
如果w_string不是宽字符,把[MarshalAs(UnmanagedType.BStr)]去掉

热点排行