public InterfaceVtblDeclaration(TypeDesc type, InterfaceWrapperDeclaration container)
            : base(type, container, AccessModifierType.Private)
        {
            isIUnknown = type.BaseTypes.Any(x => x.Name == "IUnknown");
            isUserImplemented = InterfaceDeclaration.IsUserImplemented(type);
            ignoreIdentifier = InterfaceDeclaration.IsWithoutIdentifier(type);

            var methods = type.AllMethods.OrderBy(x => x.Name).Select(x => new MethodDeclaration(x, this, AccessModifierType.Internal)).ToArray();

            WriteBaseLine(() => "{");
            for(int i = 0; i < methods.Length; i++)
                AddTextBlock(new FieldDeclaration(new TypeDesc("IntPtr"), container.GetMethodName(i), this, AccessModifierType.Internal));
            WriteBaseLine(() => "}");
        }
示例#2
0
        public InterfaceVtblDeclaration(TypeDesc type, InterfaceWrapperDeclaration container)
            : base(type, container, AccessModifierType.Private)
        {
            isIUnknown        = type.BaseTypes.Any(x => x.Name == "IUnknown");
            isUserImplemented = InterfaceDeclaration.IsUserImplemented(type);
            ignoreIdentifier  = InterfaceDeclaration.IsWithoutIdentifier(type);

            var methods = type.AllMethods.OrderBy(x => x.Name).Select(x => new MethodDeclaration(x, this, AccessModifierType.Internal)).ToArray();

            WriteBaseLine(() => "{");
            for (int i = 0; i < methods.Length; i++)
            {
                AddTextBlock(new FieldDeclaration(new TypeDesc("IntPtr"), container.GetMethodName(i), this, AccessModifierType.Internal));
            }
            WriteBaseLine(() => "}");
        }
            public DelegateCaller(int index, MethodDesc method, InterfaceWrapperDeclaration container)
                : base(container, 0)
            {
                string delegateName   = container.GetDelegateName(index);
                string vtblMethodName = container.GetMethodName(index);

                string returnDecl = MethodDeclaration.GetReturnValue(method);
                IEnumerable <string> argumentNames = MethodDeclaration.GetParameterNames(method);

                WriteLine(() => "{");
                WriteLine(() => "    " + container.vtbl.TypeName + "** @this = (" + container.vtbl.TypeName + "**)reference;");
                WriteLine(() => "    " + container.vtbl.TypeName + "* vtbl = *@this;");
                WriteLine(() => "    if (vtbl == null)");
                WriteLine(() => "        throw new InvalidComObjectException();");
                WriteLine(() => "    Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(vtbl->" + vtblMethodName + ", typeof(" + delegateName + "));");
                WriteLine(() => "    " + delegateName + " method = (" + delegateName + ")genericDelegate;");
                WriteLine(() => "    " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", new string[] { "@this" }.Union(argumentNames)) + ");");
                WriteLine(() => "}");
            }
            public DelegateCaller(int index, MethodDesc method, InterfaceWrapperDeclaration container)
                : base(container, 0)
            {
                string delegateName = container.GetDelegateName(index);
                string vtblMethodName = container.GetMethodName(index);

                string returnDecl = MethodDeclaration.GetReturnValue(method);
                IEnumerable<string> argumentNames = MethodDeclaration.GetParameterNames(method);

                WriteLine(() => "{");
                WriteLine(() => "    " + container.vtbl.TypeName + "** @this = (" + container.vtbl.TypeName + "**)reference;");
                WriteLine(() => "    " + container.vtbl.TypeName + "* vtbl = *@this;");
                WriteLine(() => "    if (vtbl == null)");
                WriteLine(() => "        throw new InvalidComObjectException();");
                WriteLine(() => "    Delegate genericDelegate = Marshal.GetDelegateForFunctionPointer(vtbl->" + vtblMethodName + ", typeof(" + delegateName + "));");
                WriteLine(() => "    " + delegateName + " method = (" + delegateName + ")genericDelegate;");
                WriteLine(() => "    " + ((returnDecl == "void") ? "" : "return ") + "method(" + string.Join(", ", new string[] { "@this" }.Union(argumentNames)) + ");");
                WriteLine(() => "}");
            }