(a 'IntPtr' instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle(a 'IntPtr' instance) to determine whether it should be replaced with a SafeHandle or CriticalHandle"有许多SafeHandle子类,它们似乎都没有在包装对象的生命周期结束时调用FreeLocal
我正试图找到一种方法,让VirtualAlloc的pinvoke签名返回一个PageAlignedBuffer。我遇到的问题是,我不能有一个默认的构造函数,因为VirtualFree方法需要知道缓冲区大小,所以我必须在构造函数中提供它。出于这个原因,我采用了下面的方法,只需在构造函数中调用VirtualAlloc。[SecurityCritical]
public sealed class PageAlig
SafeHandle sHandle = this.ServiceHandle; // I want to do this but this fails.//some more code ...}
如何将IntPtr (如this.ServiceHandle)转换为"System.Runtime.InteropServices.SafeHandle