I am trying to instantiate a JIComServer using JInterop for a custom dll, but I keep on getting the following Exception:

org.jinterop.dcom.common.JIException: Class not registered. If you are using a DLL/OCX , please make sure it has "DllSurrogate" flag set. Faq A(6) in readme.html. [0x80040154]

I went through the JInterop readme to set up my machine properly.

I tried installing the 32 bit JVM (because the dll is 32 bit)

I tried registering a 64 bit dll instead of the 32 bit version.

There is a dllflag in the registry (everything I found online said that its value is supposed to be empty).

The assembly is registered (I can find its CLSID in the registry under the TypeLibrary, AppID and CLSID directories. When I register it (using RegAsm), it is being saved to a .tlb file, does that change anything?)

This is the code:

import org.jinterop.dcom.common.*;  
import org.jinterop.dcom.core.*;

import java.net.UnknownHostException;
import java.util.logging.Level;

public class Test1{

    private static final String DOMAIN = arg;           
    private static final String USERNAME = arg; 
    private static final String PASSWORD = arg;

    private static final String CLSID = "1CCFE037-6C0E-4E33-92DA-4BC3BE772957";

    public static void main(String[] args) {

        JISystem.setAutoRegisteration(true);
        JISystem.getLogger().setLevel(Level.FINEST);

        JISession session = JISession.createSession(DOMAIN, USERNAME, PASSWORD);
        session.useSessionSecurity(true);

        if (session == null) {
            throw new NullPointerException("session is null");
        }

        JIComServer comServer = null;

        try {
            //exception gets thrown here
            comServer = new JIComServer(JIClsid.valueOf(CLSID), session);
        } catch (JIException e) {
            e.printStackTrace();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        if (comServer == null) {
            throw new NullPointerException("COM server is null");
        }

        IJIComObject comObject = null;
        try {
            comObject = comServer.createInstance();
        } catch (JIException e) {
            e.printStackTrace();
        }

    }`

This is the stack trace:

org.jinterop.dcom.common.JIException: Class not registered. If you are using a DLL/OCX , please make sure it has "DllSurrogate" flag set. Faq A(6) in readme.html. [0x80040154] at    
org.jinterop.dcom.core.JIComServer.init(JIComServer.java:669) at  
org.jinterop.dcom.core.JIComServer.initialise(JIComServer.java:575) at org.jinterop.dcom.core.JIComServer.(JIComServer.java:460) at
org.jinterop.dcom.core.JIComServer.(JIComServer.java:391) at
Test1.main(Test1.java:34) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at
com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: org.jinterop.dcom.common.JIRuntimeException: Class not registered. If you are using a DLL/OCX , please make sure it has "DllSurrogate" flag set. Faq A(6) in readme.html. [0x80040154] at
org.jinterop.dcom.core.JIRemoteSCMActivator$RemoteCreateInstance.read(JIRemoteSCMActivator.java:645) at ndr.NdrObject.decode(NdrObject.java:36) at
 rpc.ConnectionOrientedEndpoint.call(ConnectionOrientedEndpoint.java:137) at 
rpc.Stub.call(Stub.java:113) at
org.jinterop.dcom.core.JIComServer.init(JIComServer.java:645) ... 9 more
 

Last edit: Yitzchak Horowitz 2016-07-25