コード例 #1
0
ファイル: Program.cs プロジェクト: ARLM-Keller/clr-interop
        private static void GenerateDelegate(Type delegateType)
        {
            Debug.WriteLine(delegateType.FullName);

            NativeSignature native_sig = NativeSignature.FromDelegateType(
                delegateType,
                options.TargetPlatformAnsi,
                options.TargetPlatform64Bit);

            PrintNativeSignature(native_sig);
        }
コード例 #2
0
ファイル: Reflector.cs プロジェクト: dbremner/clrinterop
 public NativeSignature GetNativeSignature(bool ansiPlatform, bool platform64bit)
 {
     if (signature == null ||
         signatureAnsi != ansiPlatform ||
         signature64bit != platform64bit)
     {
         // cache the signature
         signature = reflector.GetNativeSignature(id, ansiPlatform, platform64bit);
         signatureAnsi = ansiPlatform;
         signature64bit = platform64bit;
     }
     return signature;
 }
コード例 #3
0
ファイル: Reflector.cs プロジェクト: toiiggww/clrinterop
 public NativeSignature GetNativeSignature(bool ansiPlatform, bool platform64bit)
 {
     if (signature == null ||
         signatureAnsi != ansiPlatform ||
         signature64bit != platform64bit)
     {
         // cache the signature
         signature      = reflector.GetNativeSignature(id, ansiPlatform, platform64bit);
         signatureAnsi  = ansiPlatform;
         signature64bit = platform64bit;
     }
     return(signature);
 }
コード例 #4
0
        protected override void Initialize(TypeDefKey key)
        {
            Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type));

            base.Initialize(key);

            // create the native signature of the delegate
            signature = NativeSignature.FromDelegateType(
                key.Type,
                (key.Flags & MarshalFlags.AnsiPlatform) == MarshalFlags.AnsiPlatform,
                platform64bit);

            name = signature.Name;
        }
コード例 #5
0
ファイル: Reflector.cs プロジェクト: toiiggww/clrinterop
        /// <summary>
        /// Returns a list of interop (P/Invoke & RCW) method descriptors and list of delegates.
        /// </summary>
        public void GetInteropTypesAndMethods(out List <TypeDescriptor> typeDescs, out List <MethodDescriptor> methodDescs)
        {
            methodDescs = new List <MethodDescriptor>();
            typeDescs   = new List <TypeDescriptor>();

            // let's keep track of the types for which we have descriptors
            Dictionary <Type, TypeDescriptor> map = new Dictionary <Type, TypeDescriptor>();

            Type[] types;
            try
            {
                types = assembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                // ReflectionTypeLoadException changes to FileNotFoundException when crossing the appdomain boundary
                // because it contain Type references to the target assembly -> convert to pure strings now
                throw new UnableToGetTypesException(e);
            }

            foreach (Type type in types)
            {
                TypeDescriptor type_desc = null;

                if (typeof(Delegate).IsAssignableFrom(type))
                {
                    type_desc = GetDescriptorForType(map, type);
                    typeDescs.Add(type_desc);
                }
                else
                {
                    foreach (MethodInfo info in type.GetMethods(bindingFlags))
                    {
                        if (NativeSignature.IsPInvoke(info) || NativeSignature.IsRCWMethod(info))
                        {
                            if (type_desc == null)
                            {
                                type_desc = GetDescriptorForType(map, type);
                            }

                            Guid             id          = Guid.NewGuid();
                            MethodDescriptor method_desc = new MethodDescriptor(this, info, type_desc, id);

                            methodDescs.Add(method_desc);
                            methodMap.Add(id, info);
                        }
                    }
                }
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: ARLM-Keller/clr-interop
 private static void GenerateType(Type type)
 {
     if (typeof(Delegate).IsAssignableFrom(type))
     {
         GenerateDelegate(type);
     }
     else
     {
         foreach (MethodInfo mi in type.GetMethods(methodBindingFlags))
         {
             if (NativeSignature.IsPInvoke(mi) || NativeSignature.IsRCWMethod(mi))
             {
                 GenerateMethod(mi);
             }
         }
     }
 }
コード例 #7
0
        private NativeSignature ImportSignature()
        {
            var sig = new NativeSignature();

            sig.ReturnTypeSalAttribute = ImportSalAttribute();
            sig.ReturnType             = ImportTypeReference();

            var count = _reader.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var name = _reader.ReadString();
                var type = ImportTypeReference();
                sig.Parameters.Add(new NativeParameter(name, type));
            }

            return(sig);
        }
コード例 #8
0
        /// <summary>
        /// Generate a procedure from the specified proc
        /// </summary>
        /// <param name="ntProc"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public CodeMemberMethod GenerateProcedure(NativeProcedure ntProc)
        {
            if (ntProc == null)
            {
                throw new ArgumentNullException("ntProc");
            }

            // Create the proc
            NativeSignature  ntSig       = ntProc.Signature;
            string           procComment = "Return Type: ";
            CodeMemberMethod proc        = new CodeMemberMethod();

            proc.Name       = ntProc.Name;
            proc.ReturnType = GenerateTypeReferenceImpl(ntSig.ReturnType, ref procComment);
            proc.UserData[TransformConstants.ReturnType] = ntSig.ReturnType;
            if (ntSig.ReturnTypeSalAttribute != null)
            {
                proc.UserData[TransformConstants.ReturnTypeSal] = ntSig.ReturnTypeSalAttribute;
            }
            else
            {
                proc.UserData[TransformConstants.ReturnTypeSal] = new NativeSalAttribute();
            }
            proc.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            proc.UserData[TransformConstants.Procedure]     = ntProc;
            proc.UserData[TransformConstants.ReturnType]    = ntSig.ReturnType;
            proc.UserData[TransformConstants.ReturnTypeSal] = ntSig.ReturnTypeSalAttribute;

            // Add the DLL import attribute
            string dllName = ntProc.DllName;

            if (string.IsNullOrEmpty(dllName))
            {
                dllName = "<Unknown>";
            }
            proc.CustomAttributes.Add(MarshalAttributeFactory.CreateDllImportAttribute(dllName, ntProc.Name, ntProc.CallingConvention));

            // Generate the parameters
            proc.Parameters.AddRange(GenerateParameters(ntProc.Signature, ref procComment));
            proc.Comments.Add(new CodeCommentStatement(procComment, true));
            return(proc);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: ARLM-Keller/clr-interop
        private static void PrintNativeSignature(NativeSignature nativeSig)
        {
            PrintFlags p_flags = PrintFlags.None;

            if (options.UsePlainCDataTypes)
            {
                p_flags |= PrintFlags.UsePlainC;
            }
            if (options.PrintMarshalDirection)
            {
                p_flags |= PrintFlags.PrintMarshalDirection;
            }

            LogMemoryPrinter log_mem_printer = new LogMemoryPrinter();

            // print definitions first
            if (!options.SuppressTypeDefinitions)
            {
                foreach (NativeTypeDefinition def in nativeSig.GetDefinitions())
                {
                    def.PrintTo(codePrinter, log_mem_printer, p_flags);
                    codePrinter.PrintLn();
                    codePrinter.PrintLn();
                }
            }

            // and then the method signature
            nativeSig.PrintTo(codePrinter, log_mem_printer, p_flags);
            codePrinter.PrintLn();
            codePrinter.PrintLn();

            // flush the log_mem_printer to the real log printer
            if (!options.SuppressMessages)
            {
                log_mem_printer.ReplayTo(logPrinter);
                logPrinter.Separate();
            }
        }
コード例 #10
0
ファイル: Callbacks.cs プロジェクト: dbremner/clrinterop
        protected override void Initialize(TypeDefKey key)
        {
            if (key == null) throw new ArgumentNullException(nameof(key));
            Debug.Assert(typeof(Delegate).IsAssignableFrom(key.Type));

            base.Initialize(key);

            // create the native signature of the delegate
            signature = NativeSignature.FromDelegateType(
                key.Type,
                (key.Flags & MarshalFlags.AnsiPlatform) == MarshalFlags.AnsiPlatform,
                platform64bit);

            name = signature.Name;
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: dbremner/clrinterop
        private static void PrintNativeSignature(NativeSignature nativeSig)
        {
            PrintFlags p_flags = PrintFlags.None;
            if (options.UsePlainCDataTypes) p_flags |= PrintFlags.UsePlainC;
            if (options.PrintMarshalDirection) p_flags |= PrintFlags.PrintMarshalDirection;

            var log_mem_printer = new LogMemoryPrinter();

            // print definitions first
            if (!options.SuppressTypeDefinitions)
            {
                foreach (NativeTypeDefinition def in nativeSig.GetDefinitions())
                {
                    def.PrintTo(codePrinter, log_mem_printer, p_flags);
                    codePrinter.PrintLn();
                    codePrinter.PrintLn();
                }
            }

            // and then the method signature
            nativeSig.PrintTo(codePrinter, log_mem_printer, p_flags);
            codePrinter.PrintLn();
            codePrinter.PrintLn();

            // flush the log_mem_printer to the real log printer
            if (!options.SuppressMessages)
            {
                log_mem_printer.ReplayTo(logPrinter);
                logPrinter.Separate();
            }
        }