• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Interop类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Interop的典型用法代码示例。如果您正苦于以下问题:C# Interop类的具体用法?C# Interop怎么用?C# Interop使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Interop类属于命名空间,在下文中一共展示了Interop类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:37,代码来源:SafeFileHandle.Unix.cs


示例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;
            }
        }
开发者ID:fugaku,项目名称:scriptsharp,代码行数:29,代码来源:SignatureParser.cs


示例3: ProcessIpv6Address

 protected unsafe void ProcessIpv6Address(Interop.Sys.IpAddressInfo* addressInfo, uint scopeId)
 {
     IPAddress address = IPAddressUtil.GetIPAddressFromNativeInfo(addressInfo);
     address.ScopeId = scopeId;
     AddAddress(address);
     _ipv6ScopeId = scopeId;
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:UnixNetworkInterface.cs


示例4: ModuleDescriptionItem

 public ModuleDescriptionItem(Interop.Core.ModuleDescription @struct)
 {
     Name = @struct.Name;
     ShortName = @struct.ShortName;
     LongName = @struct.LongName;
     Description = @struct.Help;
 }
开发者ID:Greaky,项目名称:xZune.Vlc,代码行数:7,代码来源:ModuleDescription.cs


示例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;
        }
开发者ID:jsalvadorp,项目名称:corefx,代码行数:33,代码来源:MemoryMappedFile.Linux.cs


示例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;
        }
开发者ID:nblumhardt,项目名称:corefx,代码行数:26,代码来源:MemoryMappedFile.Unix.BackingObject_File.cs


示例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;
 }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:7,代码来源:UnixNetworkInterface.cs


示例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;
        }
开发者ID:rainersigwald,项目名称:corefx,代码行数:35,代码来源:PingReply.cs


示例9: Wrap

		public static ICorPublishProcess Wrap(Interop.CorPub.ICorPublishProcess objectToWrap)
		{
		    if (objectToWrap != null)
			{
				return new ICorPublishProcess(objectToWrap);
			}

		    return null;
		}
开发者ID:john-peterson,项目名称:processhacker,代码行数:9,代码来源:ICorPublishProcess.cs


示例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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:14,代码来源:SafePipeHandle.Unix.cs


示例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);
 }
开发者ID:nnyamhon,项目名称:corefx,代码行数:9,代码来源:SocketAsyncEngine.Unix.cs


示例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;
 }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:15,代码来源:IPAddressUtil.cs


示例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);
开发者ID:dotnet,项目名称:corefx,代码行数:10,代码来源:Interop.RegCreateKeyEx.cs


示例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 });
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:gilgame,项目名称:SEWorkbench,代码行数:55,代码来源:Blueprint.cs


示例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;
        }
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:54,代码来源:NegotiateStreamPal.Unix.cs


示例16: AddBlock

 public void AddBlock(string type, Interop.TerminalBlock block)
 {
     if (!String.IsNullOrEmpty(type))
     {
         if (!_Blocks.ContainsKey(type))
         {
             _Blocks.Add(type, new List<TerminalBlock>());
         }
         _Blocks[type].Add(block);
     }
 }
开发者ID:gilgame,项目名称:SEWorkbench,代码行数:11,代码来源:Grid.cs


示例17: UnsafeCreateFile

 [System.Security.SecurityCritical]  // auto-generated
 internal static SafeFileHandle UnsafeCreateFile(
     string lpFileName,
     int dwDesiredAccess,
     FileShare dwShareMode,
     ref Interop.mincore.SECURITY_ATTRIBUTES securityAttrs,
     FileMode dwCreationDisposition,
     int dwFlagsAndAttributes,
     IntPtr hTemplateFile)
 {
     return CreateFile(lpFileName, dwDesiredAccess, dwShareMode, ref securityAttrs, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
 }
开发者ID:johnhhm,项目名称:corefx,代码行数:12,代码来源:Helpers.cs


示例18: SystemIPv4InterfaceProperties

        internal SystemIPv4InterfaceProperties(Interop.IpHlpApi.FIXED_INFO fixedInfo, Interop.IpHlpApi.IpAdapterAddresses ipAdapterAddresses)
        {
            _index = ipAdapterAddresses.index;
            _routingEnabled = fixedInfo.enableRouting;
            _dhcpEnabled = ((ipAdapterAddresses.flags & Interop.IpHlpApi.AdapterFlags.DhcpEnabled) != 0);
            _haveWins = (ipAdapterAddresses.firstWinsServerAddress != IntPtr.Zero);

            _mtu = ipAdapterAddresses.mtu;

            GetPerAdapterInfo(ipAdapterAddresses.index);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:11,代码来源:SystemIPv4InterfaceProperties.cs


示例19: GetHashAlgorithmName

        /// <summary>
        /// Get the HashAlgorithmName from the given ALG_ID
        /// </summary>
        internal static HashAlgorithmName? GetHashAlgorithmName(Interop.BCrypt.ECC_CURVE_ALG_ID_ENUM hashId)
        {
            CRYPT_OID_INFO oid = Interop.Crypt32.FindAlgIdOidInfo(hashId);
            if (oid.AlgId == -1)
            {
                // The original hash algorithm may not be found and is optional
                return null;
            }

            return new HashAlgorithmName(oid.Name);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:14,代码来源:ECCng.HashAlgorithm.cs


示例20: CreateProcessWithLogonW

 internal static extern bool CreateProcessWithLogonW(
     string userName,
     string domain,
     IntPtr password,
     LogonFlags logonFlags,
     [MarshalAs(UnmanagedType.LPTStr)] string appName,
     StringBuilder cmdLine,
     int creationFlags,
     IntPtr environmentBlock,
     [MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory,
     Interop.Kernel32.STARTUPINFO lpStartupInfo,
     Interop.Kernel32.PROCESS_INFORMATION lpProcessInformation);
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:Interop.CreateProcessWithLogon.cs



注:本文中的Interop类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# WinHttp.SafeWinHttpHandle类代码示例发布时间:2022-05-24
下一篇:
C# InternetAddressList类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap