Can I run GDPicture as a Windows Service?

General discussions about GdPicture.NET.
Post Reply
gdpicuser
Posts: 2
Joined: Mon Aug 03, 2009 2:47 am

Can I run GDPicture as a Windows Service?

Post by gdpicuser » Mon Aug 03, 2009 2:57 am

I am scanning from ADF into separate jpeg files. I have created a console app which runs fine. The exact same code does not produce the jpeg files when running as a windows service. It only produces an image for the very last page scanned. It doesn't loop...as if it never returns from the TwainAcquireToGdPictureImage function until all pages have gone through the scanner.

Code: Select all

                GdPictureImaging oGdPictureImaging = new GdPictureImaging();
                oGdPictureImaging = new GdPictureImaging();
                //temp 30 day license
                oGdPictureImaging.SetLicenseNumber("XXX");

                //for (int nCpt = 1; nCpt < 3; nCpt++)
                //{
                //    Console.WriteLine(oGdPictureImaging.TwainGetSourceName((IntPtr)null, nCpt));
                //    Console.ReadLine();
                //}

                oGdPictureImaging.TwainOpenSource((IntPtr)null,"Xerox DocuMate 252");

                // Here we will scan in a 24bpp  & 300 DPI from ADF into separate jpeg files
                int nImageCount = 0;
                int ImageID = 0;


                //Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp6 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
               
                if (oGdPictureImaging.TwainOpenDefaultSource((IntPtr)null))
                {
                    nImageCount = 0;

                    //InitScanConfig();
                    oGdPictureImaging.TwainSetHideUI(true);
                    oGdPictureImaging.TwainSetIndicators(true);
                    //if (System.Convert.ToDouble(chkAutoBrightness.CheckState) == 1)
                    //{
                    //    oGdPictureImaging.TwainSetAutoBrightness(true);
                    //}
                    //else
                    //{
                    //    oGdPictureImaging.TwainSetAutoBrightness(false);
                    //    oGdPictureImaging.TwainSetBrightness(HBrightness.Value);
                    //}
                    //oGdPictureImaging.TwainSetContrast(HContrast.Value);
                    oGdPictureImaging.TwainEnableDuplex(false);
                    //End InitScanConfig();



                    oGdPictureImaging.TwainSetAutoFeed(true); // Set AutoFeed Enabled
                    oGdPictureImaging.TwainSetAutoScan(true); // To  achieve the maximum scanning rate

                    oGdPictureImaging.TwainSetResolution(300);
                    oGdPictureImaging.TwainSetPixelType(TwainPixelType.TWPT_RGB); // RGB
                    oGdPictureImaging.TwainSetBitDepth(8); //  24 bpp

                    //Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp7 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
                    do
                    {
                        ImageID = oGdPictureImaging.TwainAcquireToGdPictureImage((IntPtr)null);
                        //Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp8 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
                        if (ImageID != 0)
                        {
                            //ApplyImageFilters(ref ImageID);
                            //if (System.Convert.ToDouble(chkPreview.CheckState) == 1)
                            //{
                            //    DisplayImage(ImageID);
                            //}
                            nImageCount = nImageCount + 1;
                            string transTemp0 = nImageCount.ToString();
                            //Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase transTemp9 = new Microsoft.VisualBasic.ApplicationServices.ConsoleApplicationBase();
                            oGdPictureImaging.SaveAsJPEG(ImageID, @"C:\temp\image" + transTemp0.Trim() + ".jpg", 75);
                            oGdPictureImaging.ReleaseGdPictureImage(ImageID);
                        }

                    }
                    while (System.Convert.ToInt64(oGdPictureImaging.TwainGetState()) > System.Convert.ToInt64(TwainStatus.TWAIN_SOURCE_ENABLED));

                    oGdPictureImaging.TwainCloseSource();
                    //Interaction.MsgBox("Done !", (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
                }
                else
                {
                    //Interaction.MsgBox("can't open default source, twain state is: " + oGdPictureImaging.TwainGetState().ToString(), (Microsoft.VisualBasic.MsgBoxStyle)(0), null);
                } 

gdpicuser
Posts: 2
Joined: Mon Aug 03, 2009 2:47 am

Re: Can I run GDPicture as a Windows Service?

Post by gdpicuser » Mon Aug 03, 2009 6:28 pm

As a reminder I am trying to create separate jpeg images and running this code as a windows service (the code works fine as a console app).

At first I was getting an invalid handle in the log file because I was sending the handle of the service (just for testing). However, I set the handle to NULL and the invalid handle error went away. Here is the log file:


#GdTwain Log Start. Version: 630

RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
Start: OpenSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
DSM library loaded: C:\WINDOWS\TWAIN_32.DLL
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
Entry point of the DSM found.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 1
-------------------
End: OpenSourceManager.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 3
-------------------
Start: OpenDefaultSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 3
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
Start: SetXferMech.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
End: SetXferMech.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
End: OpenDefaultSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
Start: Set Duplex False.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_FAILURE CC: TWCC_BADCAP
-------------------
End Set Duplex.
RC: TWRC_FAILURE
CC: TWCC_BADCAP
State: 4
-------------------
Start: SetAutoFeed.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
CAP_FEEDERENABLED. Result for Set True.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
CAP_AUTOFEED. Result for Set True.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: NegotiateXferCount.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
End: NegotiateXferCount.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
End: SetAutoFeed.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: SetAutoScan.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: SetAutoFeed.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
CAP_FEEDERENABLED. Result for Set True.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
CAP_AUTOFEED. Result for Set True.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: NegotiateXferCount.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
End: NegotiateXferCount.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
End: SetAutoFeed.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_FAILURE CC: TWCC_BADCAP
-------------------
End: SetAutoScan True.
RC: TWRC_FAILURE
CC: TWCC_BADCAP
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_FAILURE CC: TWCC_BUMMER
-------------------
Start: AcquireNative.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
Source: WIA-Xerox DocuMate 252
Manufacturer: Xerox
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_GETCURRENT ->RC: TWRC_SUCCESS
-------------------
Start: WaitForXfer.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_GETCURRENT ->RC: TWRC_SUCCESS
-------------------
Start: SetXferMech.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_SET ->RC: TWRC_SUCCESS
-------------------
End: SetXferMech.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: EnableSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_USERINTERFACE - MSG: MSG_ENABLEDS ->RC: TWRC_SUCCESS
-------------------
End: EnableSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_EVENT - MSG: MSG_PROCESSEVENT ->RC: TWRC_DSEVENT CC: TWCC_SUCCESS
-------------------
MessageHook: MSG_XFERREADY.
RC: TWRC_DSEVENT
CC: TWCC_SUCCESS
State: 6
-------------------
Start: DoOneTransfer.
RC: TWRC_DSEVENT
CC: TWCC_SUCCESS
State: 6
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_CAPABILITY - MSG: MSG_GETCURRENT ->RC: TWRC_SUCCESS
-------------------
Start: NativeXferHandler.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 6
-------------------
::DS operation. DG: DG_IMAGE - DAT: DAT_IMAGENATIVEXFER - MSG: MSG_GET ->RC: TWRC_XFERDONE CC: TWCC_SUCCESS
-------------------
End: NativeXferHandler.
RC: TWRC_XFERDONE
CC: TWCC_SUCCESS
State: 7
-------------------
Start: EndXfer.
RC: TWRC_XFERDONE
CC: TWCC_SUCCESS
State: 7
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_PENDINGXFERS - MSG: MSG_ENDXFER ->RC: TWRC_SUCCESS
-------------------
End: EndXfer.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
End: DoOneTransfer.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
End: ModalEventLoop.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
End: WaitForXfer.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
AcquireNative: Multi transfer mode -> closing source.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
Start: DisableSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 5
-------------------
::DS operation. DG: DG_CONTROL - DAT: DAT_USERINTERFACE - MSG: MSG_DISABLEDS ->RC: TWRC_SUCCESS
-------------------
End: DisableSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
-------------------
Start: CloseSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 4
Source: WIA-Xerox DocuMate 252
Manufacturer: Xerox
-------------------
End: CloseSource.
RC: TWRC_SUCCESS
CC: TWCC_SUCCESS
State: 3
-------------------
End: AcquireNative.
RC: TWRC_XFERDONE
CC: TWCC_SUCCESS
State: 3
-------------------
#GdTwain Log Stop.

nschafer
Posts: 28
Joined: Tue Oct 30, 2007 10:05 pm
Location: Florida, USA

Re: Can I run GDPicture as a Windows Service?

Post by nschafer » Mon Oct 05, 2009 10:43 pm

Just a quick note. I use GdPicture in a Windows Service without any issues. I am not however attempting to control a scanner. The App I created to run as a service simply watches a folder and coverts any TIFF files it finds into PDF becuase the particular client's multi-function-device will only save scans as TIFF files and they want them stored as PDFs.

My first thought was that the you might be running into a security issue as the service user may not have rights to your scanner, but looking at your log that doesn't seem to be the case.

Sorry I can't be more help, but I thought I'd at least let you know that Yes, GdPicture will run in a service app.

Neal.

RobHamm
Posts: 1
Joined: Tue Mar 17, 2015 9:32 pm

Re: Can I run GDPicture as a Windows Service?

Post by RobHamm » Tue Mar 17, 2015 9:36 pm

nschafer lHow did you add the namesapce to you windows service project. I was able to add the reference, however when I try to add the namespace within code, then build. I am getting a "The type or namespace GdPicture 11 could not be fou nd... Anyy assistance would be helpful

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests