Type registration required: IPXV_Inst.CreateOp().Params.Root

This Forum is for the use of Software Developers requiring help and assistance for Tracker Software's PDF-Tools SDK of Library DLL functions(only) - Please use the PDF-XChange Drivers API SDK Forum for assistance with all PDF Print Driver related topics or PDF-XChange Viewer SDK if appropriate.

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Sean - Tracker, Chris - Tracker Supp, Tracker Supp-Stefan

Post Reply
scoberry
User
Posts: 3
Joined: Thu Oct 05, 2017 11:56 am

Type registration required: IPXV_Inst.CreateOp().Params.Root

Post by scoberry » Tue Oct 17, 2017 12:17 pm

We have some code that sometimes runs on 32-bit, sometimes on 64-bit, and we'd like to avoid registering DLLs.

http://sdkhelp.tracker-software.com/view/PXV:PXV_Inst says you can use the SDK in most circumstances without registration (but not PXV_Control).

That matches what I wanted to do: I'm trying to extract pages from a PDF file. So I have the code below, but it fails if we get to operation.Params.Root, throwing because a library isn't registered.

It seems like if you can't get to operation.Params.Root, you wouldn't be able to do much with PXV_Inst without requiring registration. Is there something I'm missing?

Thanks.

Code: Select all

using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            string outputPath = @"c:\outputPath\out.pdf";
            //string inputPath = @"c:\inputPath\in.pdf";

            const uint opExecFlagsNoUINoProgress = 3;

            string libraryName = IntPtr.Size == 4 ? "PDFXEditCore.x86.DLL" : "PDFXEditCore.x64.DLL";
            IntPtr module = LoadLibrary(libraryName);
            IntPtr hProc = GetProcAddress(module, "PXV_GetInstance");
            var pxvDelegate = (PXV_GetInstance)(object)Marshal.GetDelegateForFunctionPointer(hProc, typeof(PXV_GetInstance));
            IPXV_Inst typedInstance;
            HRESULT result = pxvDelegate(out typedInstance);
            dynamic instance = typedInstance;
            instance.Init(Missing.Value, "");
            int extractPagesId = instance.Str2ID("op.document.extractPages", false);
            var pxcInst = (dynamic)instance.GetExtension("PXC");

            try
            {
                //var doc = pxcInst.OpenDocumentFromFile(inputPath, Missing.Value); //Side issue: This gives DISP_E_BADVARTYPE

                var operation = instance.CreateOp(extractPagesId);
                var operationParams = operation.Params;
                var root = operationParams.Root; //Trying to get root throws because a type isn't registered

                var options = operation.Params.Root["Options"];
                var pagesRange = options["PagesRange"];
                pagesRange["Type"].v = 6;// PDFXEdit.RangeType.RangeType_Exact;
                pagesRange["Text"].v = string.Join(",", "4");
                options["OpenFolder"].v = false;
                options["ExtractPagesAction"].v = "AllToOneFile";
                options["LocalFolder"].v = Path.GetDirectoryName(outputPath);
                options["FileName"].v = Path.GetFileName(outputPath);

                var input = operation.Params.Root["Input"];
                //input.v = doc;

                instance.AsyncDoAndWaitForFinish(operation, opExecFlagsNoUINoProgress);

                byte[] bytes = File.ReadAllBytes(outputPath);
                Console.WriteLine(bytes.Length);
            }
            catch (COMException ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }

        [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
        public static extern IntPtr LoadLibrary(string dllName);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate HRESULT PXV_GetInstance([MarshalAs(UnmanagedType.Interface)]out IPXV_Inst foo);

        [DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
        public static extern IntPtr GetProcAddress(IntPtr module, [In, MarshalAs(UnmanagedType.LPStr)] string procName);
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct HRESULT
    {
        private readonly int _Value;

        public HRESULT(int value)
        { _Value = value; }
    }

    [Guid("D726366D-34D6-49FC-A341-7B84C54CCA3E")]
    [InterfaceType(ComInterfaceType.InterfaceIsDual)]
    [ComImport]
    interface IPXV_Inst
    {
    }
}

User avatar
Sasha - Tracker Dev Team
User
Posts: 4217
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Type registration required: IPXV_Inst.CreateOp().Params.Root

Post by Sasha - Tracker Dev Team » Wed Oct 18, 2017 8:36 am

Hello scoberry,

Well, you can reference the dll itself as you are developing your project. But it won't be used once compiled.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply