argledhel
argledhel

Reputation: 197

Interop: Retrieving the COM class factory

I was developing a 32-bit application in VS2013 using a 32-bit Win 7. I used a registered COM named 'xpdfText.dll', registered in %windir%\system32, as expected. The code was as follows:

    public static string PDF_XPDF(byte[] PDFByte = null, string filename = null, string mode = "layout")
    {

        XpdfText.XpdfText pdf;
        pdf = new XpdfText.XpdfText();


        if (filename == null)
        {
            // Create a UCOMIStream from the allocated memory
            IStream comStream;
            Common.CreateStreamOnHGlobal(IntPtr.Zero, true, out comStream);
            comStream.Write(PDFByte, PDFByte.Length, IntPtr.Zero);
            pdf.loadStream(comStream);
        }
        else
            pdf.loadFile(filename);

        if (mode == "layout")
            pdf.physicalLayoutMode = true;

        pdf.textEncoding = "Latin1";
        int n = pdf.numPages;
        string lines = pdf.convertToTextString(1, n);

        return lines;
    }

Recently, I bought a new computer and moved to a 64 bit Win 7. As my solution is to be deployed in 32 bit systems, I chose the target platform for my C# project to be x86 (instead of "Any CPU", by default) and thus I also chose to register the same 32-bit xpdftext.dll in %windir%\syswow64.

When I debug the program, everything goes well until the line when the class 'pdf' is initiliazed:

pdf = new XpdfText.XpdfText();

It shows up the following error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll

Additional information: Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

Needless to say, CLSID {00000000-0000-0000-0000-000000000000} does not exist, so I don't understand what I've done wrong. I have read a lot of threads and followed the guidelines but, to this time, no idea how to solve the problem.

Upvotes: 1

Views: 10980

Answers (2)

Ahsin Anwar
Ahsin Anwar

Reputation: 83

Make sure you have changed target platform to 32xbit instead of 64xbit or Any CPU

Project>> Properties>>Build>>Target Platform

Upvotes: 0

argledhel
argledhel

Reputation: 197

Finally, I managed to solve the problem. It was as simple as modifying a flag in the properties of the COM.

enter image description here

Upvotes: 2

Related Questions