mirror of
https://gitee.com/csharpui/CPF.git
synced 2025-09-19 10:08:26 +08:00
初始化
This commit is contained in:
48
CPF.Mac/Mac/CoreServices/CFHost.cs
Normal file
48
CPF.Mac/Mac/CoreServices/CFHost.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using CPF.Mac.CoreFoundation;
|
||||
using CPF.Mac.ObjCRuntime;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace CPF.Mac.CoreServices
|
||||
{
|
||||
internal class CFHost : INativeObject, IDisposable
|
||||
{
|
||||
internal IntPtr handle;
|
||||
|
||||
public IntPtr Handle => handle;
|
||||
|
||||
private CFHost(IntPtr handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
~CFHost()
|
||||
{
|
||||
Dispose(disposing: false);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (handle != IntPtr.Zero)
|
||||
{
|
||||
CFObject.CFRelease(handle);
|
||||
handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("/System/Library/Frameworks/CoreServices.framework/Frameworks/CFNetwork.framework/CFNetwork")]
|
||||
private static extern IntPtr CFHostCreateWithName(IntPtr allocator, IntPtr name);
|
||||
|
||||
public static CFHost Create(string name)
|
||||
{
|
||||
CFString cFString = new CFString(name);
|
||||
return new CFHost(CFHostCreateWithName(IntPtr.Zero, cFString.Handle));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user