Dinesh Bali - 2009-06-09

Hi,
I have created a java application using Netbeans.

My java application reads outlook mails using 3rd party application
http://www.moyosoft.com/joc/

My application works great with MyApp.bat file

Now, I have created windows service of my application using
http://wrapper.tanukisoftware.org/doc/english/download.jsp
abd running batch file (InstallMyApp-NT.bat) after all configurations

Now when I run my program as windows service then I get an error
saying
com.moyosoft.connector.com.ComponentObjectModelException: Unable to create an instance for the specified program ID (80080005)
      at com.moyosoft.connector.com.c.a(Unknown Source)
      at com.moyosoft.connector.com.c.a(Unknown Source)
      at com.moyosoft.connector.com.c.a(Unknown Source)
      at com.moyosoft.connector.com.c.a(Unknown Source)
      at com.moyosoft.connector.com.DispatchProxy.<init>(Unknown Source)
      at com.moyosoft.connector.com.c.a(Unknown Source)
      at com.moyosoft.connector.com.ComUtil.createDispatch(Unknown Source)
      at com.moyosoft.connector.ms.outlook.Outlook.a(Unknown Source)
      at com.moyosoft.connector.ms.outlook.Outlook.<init>(Unknown Source)
      at smecoutlook.FindNewMail$1.run(FindNewMail.java:66)
      at java.util.TimerThread.mainLoop(Unknown Source)
      at java.util.TimerThread.run(Unknown Source)
COM error has occured:

I have already provided all jar files and dll in the wrapper.conf file

************************************

wrapper.java.classpath.1=C:/Me/Pers/Java/Service/wrapper-delta-pack-3.3.3/wrapper-delta-pack-3.3.3/lib/wrapper.jar
wrapper.java.classpath.2=C:/Me/PitneyOff/java/schedular/SMECOutlookApp/app/SMECOutlookApp.jar
wrapper.java.classpath.3=C:/Me/Pers/Java/Service/wrapper-delta-pack-3.3.3/wrapper-delta-pack-3.3.3/bin
wrapper.java.classpath.4=C:/Me/PitneyOff/java/schedular/SMECOutlookApp/app/lib/moyocore.jar
wrapper.java.classpath.5=C:/Me/PitneyOff/java/schedular/SMECOutlookApp/app/lib/joc-v2.1.3-pro.jar
wrapper.java.classpath.6=C:/Me/PitneyOff/java/schedular/SMECOutlookApp/app/lib/joc-samples.jar
wrapper.java.classpath.7=C:/WINDOWS/moyocore.dll
wrapper.java.classpath.8=C:/Me/Softwares/java/outlookconnectorFullVersion/joc-pro-2_1_3/Java Outlook Connector/.install4j/i4jruntime.jar

# Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=C:/Me/Pers/Java/Service/wrapper-delta-pack-3.3.3/wrapper-delta-pack-3.3.3/lib
wrapper.java.library.path.2=C:/WINDOWS/moyocore.dll

wrapper.java.library.path.3=C:/Me/Softwares/java/outlookconnectorFullVersion/joc-pro-2_1_3/Java Outlook Connector/.install4j/_shfoldr.dll
wrapper.java.library.path.4=C:/Me/Softwares/java/outlookconnectorFullVersion/joc-pro-2_1_3/Java Outlook Connector/.install4j/i4jinst.dll
wrapper.java.library.path.5=C:/Me/Softwares/java/outlookconnectorFullVersion/joc-pro-2_1_3/Java Outlook Connector/.install4j/unicows.dll

************************************

How do I fix that. My code is given below

************************************

try
    {
        int initialDelay = 5000;
        int interval = 1000;       

        Timer timer = new Timer();
        timer.schedule(new TimerTask()
        {
            Date receivedTime = new Date();
            ArrayList receivedIds = new ArrayList();
           
            public void run()
            {               
                try
                {
                   // System.out.println("I am running.");
                    Outlook outlookApplication = new Outlook();
                    OutlookFolder inbox = outlookApplication
                        .getDefaultFolder(FolderType.INBOX);
                    String filter = "[CreationTime] >= '" + formatDateToString(receivedTime) + "'";

                    ItemsIterator iterator = inbox.getItems().findItems(filter);
                    ArrayList foundIds = new ArrayList();

                    while(iterator.hasNext())
                    {
                        OutlookItem item = iterator.nextItem();

                        if(item != null && item.getType().isMail())
                        {
                            OutlookMail mail = (OutlookMail) item;

                            OutlookItemID id = mail.getItemId();

                            if(!receivedIds.contains(id))
                            {
                                try
                                {
                                    handleNewMail(mail);
                                }catch(Exception ex)
                                {
                                    System.out.println("Error comes "+ex.toString());
                                    mL.error("Error comes", ex);
                                }
                            }

                            foundIds.add(id);
                        }
                    }
                   
                    receivedIds = foundIds;
                    outlookApplication.dispose();
                    System.out.println("Waiting for new mail");
                    mL.info("Waiting for new mail");
                   
                    Thread.sleep(10000);
                }catch (ComponentObjectModelException ex)
                {
                    mL.error("COM error has occured", ex);
                    System.out.println("COM error has occured: ");
                    ex.printStackTrace();
                }
                catch (LibraryNotFoundException ex)
                {
                     mL.error("The Java Outlook Library hasn't been found", ex);
                    // If this error occurs, verify the file 'moyocore.dll' is present
                    // in java.library.path
                    System.out.println("The Java Outlook Library hasn't been found.");
                    ex.printStackTrace();
                }catch(Exception ex)
                {
                    mL.error("Error in Java Outlook Connector", ex);
                    System.out.println("Error in Java Outlook Connector: "+ex.toString());
                    ex.printStackTrace();
                }
            }
        }, initialDelay, interval);
    }catch(Exception ex2)
    {
        System.out.println("Exception occurs2: "+ex2.toString());
    }

************************************

Please guide
Many Thanks