2
如果我的.NET 4.5和Windows Store的可移植类可以使用DllImport。但是,当我添加WP8时,即使WP8支持DllImport,它也不再可用。这是怎么回事?使用.NET 4.5/Windows Store/WP8的便携式类库中的DllImport
如果我的.NET 4.5和Windows Store的可移植类可以使用DllImport。但是,当我添加WP8时,即使WP8支持DllImport,它也不再可用。这是怎么回事?使用.NET 4.5/Windows Store/WP8的便携式类库中的DllImport
仅仅因为你可以在你的C#WP8项目添加[DllImport ...]
并不意味着它的支持。
private void Button_Click_1(object sender, RoutedEventArgs e)
{
var v = GetCurrentThread();
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetCurrentThread();
...将在WP8中给出NotSupportedException
。尽管MSDN says that this is a supported Win32 API for WP8.
这也可以解释为什么你失去了使用PCL DllImport
的能力...
感谢保罗。你挽救了我的剩余头发。 – tofutim
如果DllImport被最终的exe支持,你认为可以使用反射来调用PCL中的DllImport吗? – tofutim