本文整理汇总了C#中Interop类的典型用法代码示例。如果您正苦于以下问题:C# Interop类的具体用法?C# Interop怎么用?C# Interop使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Interop类属于命名空间,在下文中一共展示了Interop类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Open
/// <summary>Opens the specified file with the requested flags and mode.</summary>
/// <param name="path">The path to the file.</param>
/// <param name="flags">The flags with which to open the file.</param>
/// <param name="mode">The mode for opening the file.</param>
/// <returns>A SafeFileHandle for the opened file.</returns>
internal static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int mode)
{
Debug.Assert(path != null);
// If we fail to open the file due to a path not existing, we need to know whether to blame
// the file itself or its directory. If we're creating the file, then we blame the directory,
// otherwise we blame the file.
bool enoentDueToDirectory = (flags & Interop.Sys.OpenFlags.O_CREAT) != 0;
// Open the file.
SafeFileHandle handle = Interop.CheckIo(
Interop.Sys.Open(path, flags, mode),
path,
isDirectory: enoentDueToDirectory,
errorRewriter: e => (e.Error == Interop.Error.EISDIR) ? Interop.Error.EACCES.Info() : e);
// Make sure it's not a directory; we do this after opening it once we have a file descriptor
// to avoid race conditions.
Interop.Sys.FileStatus status;
if (Interop.Sys.FStat(handle, out status) != 0)
{
handle.Dispose();
throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), path);
}
if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
{
handle.Dispose();
throw Interop.GetExceptionForIoErrno(Interop.Error.EACCES.Info(), path, isDirectory: true);
}
return handle;
}
示例2: Parse
public TypeSymbol Parse(Interop.IMetadataImport mdImport, IntPtr signatureBytes, int signatureLength, out bool isIndexer) {
_mdImport = mdImport;
_signatureBytes = signatureBytes;
_signatureLength = signatureLength;
_signatureIndex = 0;
isIndexer = false;
byte signatureMarker = Read();
byte typeMarker = (byte)(signatureMarker & 0xF);
switch (typeMarker) {
case Interop.SIG_FIELD:
return ParseField();
case Interop.SIG_PROPERTY:
return ParseProperty(out isIndexer);
case Interop.SIG_METHOD_DEFAULT:
case Interop.SIG_METHOD_C:
case Interop.SIG_METHOD_THISCALL:
case Interop.SIG_METHOD_VARARG:
case Interop.SIG_METHOD_STDCALL:
case Interop.SIG_METHOD_FASTCALL:
bool isGeneric = ((signatureMarker & Interop.SIG_GENERIC) != 0);
return ParseMethod(isGeneric);
default:
// TODO: Error
Debug.Fail("Unexpected signature type");
return null;
}
}
示例3: ProcessIpv6Address
protected unsafe void ProcessIpv6Address(Interop.Sys.IpAddressInfo* addressInfo, uint scopeId)
{
IPAddress address = IPAddressUtil.GetIPAddressFromNativeInfo(addressInfo);
address.ScopeId = scopeId;
AddAddress(address);
_ipv6ScopeId = scopeId;
}
示例4: ModuleDescriptionItem
public ModuleDescriptionItem(Interop.Core.ModuleDescription @struct)
{
Name = @struct.Name;
ShortName = @struct.ShortName;
LongName = @struct.LongName;
Description = @struct.Help;
}
示例5: CreateSharedBackingObject
private static FileStream CreateSharedBackingObject(
Interop.libc.MemoryMappedProtections protections, long capacity,
out string mapName, out SafeMemoryMappedFileHandle.FileStreamSource fileStreamSource)
{
// The POSIX shared memory object name must begin with '/'. After that we just want something short and unique.
mapName = "/" + MemoryMapObjectFilePrefix + Guid.NewGuid().ToString("N");
fileStreamSource = SafeMemoryMappedFileHandle.FileStreamSource.ManufacturedSharedMemory;
// Determine the flags to use when creating the shared memory object
Interop.libc.OpenFlags flags = (protections & Interop.libc.MemoryMappedProtections.PROT_WRITE) != 0 ?
Interop.libc.OpenFlags.O_RDWR :
Interop.libc.OpenFlags.O_RDONLY;
flags |= Interop.libc.OpenFlags.O_CREAT | Interop.libc.OpenFlags.O_EXCL; // CreateNew
// Determine the permissions with which to create the file
Interop.libc.Permissions perms = default(Interop.libc.Permissions);
if ((protections & Interop.libc.MemoryMappedProtections.PROT_READ) != 0)
perms |= Interop.libc.Permissions.S_IRUSR;
if ((protections & Interop.libc.MemoryMappedProtections.PROT_WRITE) != 0)
perms |= Interop.libc.Permissions.S_IWUSR;
if ((protections & Interop.libc.MemoryMappedProtections.PROT_EXEC) != 0)
perms |= Interop.libc.Permissions.S_IXUSR;
// Create the shared memory object. Then enlarge it to the requested capacity.
int fd;
Interop.CheckIo(fd = Interop.libc.shm_open(mapName, flags, (int)perms), mapName);
SafeFileHandle fileHandle = new SafeFileHandle((IntPtr)fd, ownsHandle: true);
// Wrap the handle in a stream and return it.
var fs = new FileStream(fileHandle, TranslateProtectionsToFileAccess(protections));
fs.SetLength(capacity);
return fs;
}
示例6: CreateSharedBackingObject
private static FileStream CreateSharedBackingObject(Interop.libc.MemoryMappedProtections protections, long capacity)
{
Directory.CreateDirectory(s_tempMapsDirectory);
string path = Path.Combine(s_tempMapsDirectory, Guid.NewGuid().ToString("N"));
FileAccess access =
(protections & (Interop.libc.MemoryMappedProtections.PROT_READ | Interop.libc.MemoryMappedProtections.PROT_WRITE)) != 0 ? FileAccess.ReadWrite :
(protections & (Interop.libc.MemoryMappedProtections.PROT_WRITE)) != 0 ? FileAccess.Write :
FileAccess.Read;
// Create the backing file, then immediately unlink it so that it'll be cleaned up when no longer in use.
// Then enlarge it to the requested capacity.
const int DefaultBufferSize = 0x1000;
var fs = new FileStream(path, FileMode.CreateNew, TranslateProtectionsToFileAccess(protections), FileShare.ReadWrite, DefaultBufferSize);
try
{
Interop.CheckIo(Interop.Sys.Unlink(path));
fs.SetLength(capacity);
}
catch
{
fs.Dispose();
throw;
}
return fs;
}
示例7: ProcessIpv4Address
protected unsafe void ProcessIpv4Address(Interop.Sys.IpAddressInfo* addressInfo, Interop.Sys.IpAddressInfo* netMask)
{
IPAddress ipAddress = IPAddressUtil.GetIPAddressFromNativeInfo(addressInfo);
IPAddress netMaskAddress = IPAddressUtil.GetIPAddressFromNativeInfo(netMask);
AddAddress(ipAddress);
_netMasks[ipAddress] = netMaskAddress;
}
示例8: GetIPStatus
// Translates the relevant icmpsendecho codes to a IPStatus code.
private IPStatus GetIPStatus(Interop.IpHlpApi.IcmpV4Type type, Interop.IpHlpApi.IcmpV4Code code)
{
switch (type)
{
case Interop.IpHlpApi.IcmpV4Type.ICMP4_ECHO_REPLY:
return IPStatus.Success;
case Interop.IpHlpApi.IcmpV4Type.ICMP4_SOURCE_QUENCH:
return IPStatus.SourceQuench;
case Interop.IpHlpApi.IcmpV4Type.ICMP4_PARAM_PROB:
return IPStatus.ParameterProblem;
case Interop.IpHlpApi.IcmpV4Type.ICMP4_TIME_EXCEEDED:
return IPStatus.TtlExpired;
case Interop.IpHlpApi.IcmpV4Type.ICMP4_DST_UNREACH:
{
switch (code)
{
case Interop.IpHlpApi.IcmpV4Code.ICMP4_UNREACH_NET:
return IPStatus.DestinationNetworkUnreachable;
case Interop.IpHlpApi.IcmpV4Code.ICMP4_UNREACH_HOST:
return IPStatus.DestinationHostUnreachable;
case Interop.IpHlpApi.IcmpV4Code.ICMP4_UNREACH_PROTOCOL:
return IPStatus.DestinationProtocolUnreachable;
case Interop.IpHlpApi.IcmpV4Code.ICMP4_UNREACH_PORT:
return IPStatus.DestinationPortUnreachable;
case Interop.IpHlpApi.IcmpV4Code.ICMP4_UNREACH_FRAG_NEEDED:
return IPStatus.PacketTooBig;
default:
return IPStatus.DestinationUnreachable;
}
}
}
return IPStatus.Unknown;
}
示例9: Wrap
public static ICorPublishProcess Wrap(Interop.CorPub.ICorPublishProcess objectToWrap)
{
if (objectToWrap != null)
{
return new ICorPublishProcess(objectToWrap);
}
return null;
}
示例10: Open
/// <summary>Opens the specified file with the requested flags and mode.</summary>
/// <param name="path">The path to the file.</param>
/// <param name="flags">The flags with which to open the file.</param>
/// <param name="mode">The mode for opening the file.</param>
/// <returns>A SafeFileHandle for the opened file.</returns>
internal static SafePipeHandle Open(string path, Interop.Sys.OpenFlags flags, int mode)
{
// Ideally this would be a constrained execution region, but we don't have access to PrepareConstrainedRegions.
SafePipeHandle handle = Interop.CheckIo(Interop.Sys.OpenPipe(path, flags, mode));
Debug.Assert(!handle.IsInvalid);
return handle;
}
示例11: TryRegister
public bool TryRegister(int fileDescriptor, SocketAsyncEvents current, SocketAsyncEvents events, GCHandle handle, out Interop.Error error)
{
if (current == events)
{
error = Interop.Error.SUCCESS;
return true;
}
return _backend.TryRegister(fileDescriptor, current, events, handle, out error);
}
示例12: GetIPAddressFromNativeInfo
/// <summary>
/// Copies the address bytes out of the given native info's buffer and constructs a new IPAddress.
/// </summary>
/// <param name="addressInfo">A pointer to a native IpAddressInfo structure.</param>
/// <returns>A new IPAddress created with the information in the native structure.</returns>
public static unsafe IPAddress GetIPAddressFromNativeInfo(Interop.Sys.IpAddressInfo* addressInfo)
{
byte[] ipBytes = new byte[addressInfo->NumAddressBytes];
fixed (byte* ipArrayPtr = ipBytes)
{
Buffer.MemoryCopy(addressInfo->AddressBytes, ipArrayPtr, ipBytes.Length, ipBytes.Length);
}
IPAddress ipAddress = new IPAddress(ipBytes);
return ipAddress;
}
示例13: RegCreateKeyEx
internal static extern int RegCreateKeyEx(
SafeRegistryHandle hKey,
String lpSubKey,
int Reserved,
String lpClass,
int dwOptions,
int samDesired,
ref Interop.Kernel32.SECURITY_ATTRIBUTES secAttrs,
out SafeRegistryHandle hkResult,
out int lpdwDisposition);
示例14: Import
public static void Import(string filename, out string name, out Interop.Grid grid)
{
name = string.Empty;
grid = null;
MyObjectBuilder_Definitions loaded = null;
if (File.Exists(filename))
{
using (FileStream stream = File.Open(filename, FileMode.Open))
{
MyObjectBuilderSerializer.DeserializeXML<MyObjectBuilder_Definitions>(stream, out loaded);
}
}
if (loaded != null)
{
foreach (MyObjectBuilder_ShipBlueprintDefinition blueprints in loaded.ShipBlueprints)
{
name = blueprints.Id.SubtypeId;
grid = new Grid(loaded)
{
Name = name,
Path = filename,
};
foreach (MyObjectBuilder_CubeGrid cubegrid in blueprints.CubeGrids)
{
foreach (MyObjectBuilder_CubeBlock block in cubegrid.CubeBlocks)
{
if (block is MyObjectBuilder_TerminalBlock)
{
MyObjectBuilder_TerminalBlock terminalblock = (MyObjectBuilder_TerminalBlock)block;
long entityid = terminalblock.EntityId;
string type = GetBlockType(terminalblock.TypeId.ToString());
// TODO Use MyTexts.GetString(MyStringId id) to get default blocks names from MyTexts.resx (for localization)
string customname = String.IsNullOrEmpty(terminalblock.CustomName) ? type : terminalblock.CustomName;
if (block is MyObjectBuilder_MyProgrammableBlock)
{
MyObjectBuilder_MyProgrammableBlock prog = (MyObjectBuilder_MyProgrammableBlock)block;
grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = true, Program = prog.Program });
}
else
{
grid.AddBlock(type, new TerminalBlock() { Name = customname, EntityID = entityid, IsProgram = false });
}
}
}
}
}
}
}
示例15: GssInitSecurityContext
private static bool GssInitSecurityContext(
ref SafeGssContextHandle context,
SafeGssCredHandle credential,
bool isNtlm,
SafeGssNameHandle targetName,
Interop.NetSecurityNative.GssFlags inFlags,
byte[] buffer,
out byte[] outputBuffer,
out uint outFlags,
out int isNtlmUsed)
{
outputBuffer = null;
outFlags = 0;
// EstablishSecurityContext is called multiple times in a session.
// In each call, we need to pass the context handle from the previous call.
// For the first call, the context handle will be null.
if (context == null)
{
context = new SafeGssContextHandle();
}
Interop.NetSecurityNative.GssBuffer token = default(Interop.NetSecurityNative.GssBuffer);
Interop.NetSecurityNative.Status status;
try
{
Interop.NetSecurityNative.Status minorStatus;
status = Interop.NetSecurityNative.InitSecContext(out minorStatus,
credential,
ref context,
isNtlm,
targetName,
(uint)inFlags,
buffer,
(buffer == null) ? 0 : buffer.Length,
ref token,
out outFlags,
out isNtlmUsed);
if ((status != Interop.NetSecurityNative.Status.GSS_S_COMPLETE) && (status != Interop.NetSecurityNative.Status.GSS_S_CONTINUE_NEEDED))
{
throw new Interop.NetSecurityNative.GssApiException(status, minorStatus);
}
outputBuffer = token.ToByteArray();
}
finally
{
token.Dispose();
}
return status == Interop.NetSecurityNative.Status.GSS_S_COMPLETE;
}